zoukankan      html  css  js  c++  java
  • SpringMvc GET请求传递对象

    在controller层接收Get请求参数,最好还是用基本类型接收会比较好,即使是date类型的,也可以使用date类型去数据库查找。

    date类型不用去考虑用什么类型,如果数据库类型为datetime或date。用String类型就可以查询了。如下(注意符号)

     SELECT * FROM teacher WHERE create_time >= '2020/06/08 00:00:00'
        
    

    比如一个下载Excel的功能:

    
    				var searchDTO = {
    					Action: 'exportCollectionEx',
    					collectionId:this.searchForm.collectionId,
    					waybillNos:this.searchForm.waybillNos,
    					empNo:this.searchForm.empNo,
    					deptCode:this.searchForm.deptCode,
    					billDateStart:this.searchForm.collecteDate == undefined ? undefined:this.searchForm.collecteDate[0],
    					billDateEnd:this.searchForm.collecteDate == undefined ? undefined:this.searchForm.collecteDate[1]
    				}
    				this.$httpExt().get('/receivable/outstanding', searchDTO, {
    					headers: {
    						'Content-Type': 'application/octet-stream'
    					},
    					responseType: 'arraybuffer'
    				}).then(res => {
    					console.log(res.headers);
    					const [, fileName] = res.headers['content-disposition'].split('=');
    					const blob = new Blob([res.data])
    					const downloadElement = document.createElement('a');
    					const href = window.URL.createObjectURL(blob);
    					downloadElement.href = href;
    					downloadElement.download = fileName;
    					document.body.appendChild(downloadElement);
    					downloadElement.click();
    					document.body.removeChild(downloadElement);
    					window.URL.revokeObjectURL(href);
    				});
    

    controller

     @GetMapping(params = {"Action=exportCollectionEx"})
        public Response exportCollectionEx(CollectionExSearchDTO searchDTO,HttpServletResponse resp) {
    
        }
    

    DTO

    public class CollectionExSearchDTO {
    
        /**收款单号*/
        private String collectionId;
    
        /**
         * 运单号
         */
        private String waybillNo;
    
        /**
         * 员工号
         */
        private String empNo;
    
        /**
         * 网点
         */
        private String deptCode;
    
        /**
         * 收款开始日期
         */
        private String billDateStart;
    
        /**
         * 收款结束日期
         */
        private String billDateEnd;
    
        //set/get
    
  • 相关阅读:
    2021.2.28
    《构建之法》11~16章读后感
    《构建之法》6~10章读后感
    《构建之法》1~5章读后感
    4.7 wait notify
    4.8 wait,notify 的正确姿势
    4.9 park&unpark
    4.10 重新理解线程的状态转换
    第七章 Redis-6.2.1脚本安装
    第三十九章 Centos 7 系统优化脚本
  • 原文地址:https://www.cnblogs.com/sean-zeng/p/13068815.html
Copyright © 2011-2022 走看看