在实际业务场景中,当前台通过 url 向后台传送多个参数时,可以将参数封装成一个bean类,在bean类中对各个参数进行非空,默认值等的设置。

前台 url ,想后台传送两个参数,userName 和 password:

http://localhost:8082/web/baseAction.do?pathVar=app/task/fetchItemDetail.do?userName=123&password=123

将参数封装成bean 类,并在bean类中对参数进行控制:


 import org.hibernate.validator.constraints.NotEmpty;

 /**
* Created by thinkpad on 2017/10/23.
*/
public class QueryCondition { @NotEmpty(message = "validator.userName")
private String userName ;
private String password; public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getPassword() {
if (null == password || password.length() == 0){
password = "123456";
}
return password;
} public void setPassword(String password) {
this.password = password;
}
}

    controller 中的接收、打印及去除当前传入的参数:

    @RequestMapping("/fetchItemDetail.do")
@ResponseBody
public String fetchItemDetail(QueryCondition condition) {
JSONObject json = new JSONObject();
System.out.println(ReflectionToStringBuilder.toString(condition, ToStringStyle.MULTI_LINE_STYLE));
System.out.println("conditionUserName = [" + condition.getUserName() + "], " +
"conditionPassword = [" + condition.getPassword() + "]");
return json.toJSONString();
}

SpringMVC 中,当前台传入多个参数时,可将参数封装成一个bean类的更多相关文章

  1. ybatis中查询出多个以key,value的属性记录,封装成一个map返回的方法

    可以采用值做映射,也可以不采用映射方式 <resultMap id="configMap" type="java.util.Map" > <r ...

  2. SpringMVC中,前台jsp封装参数,绑定参数,传递参数到后台controller的过程详解

    前台到后台的流程:前台jsp->后台:controller控制器层->service业务层->DAO数据访问层->数据库model模型层. 从上面流程可知,前台jsp的数据,想 ...

  3. python中操作excel数据 封装成一个类

    本文用python中openpyxl库,封装成excel数据的读写方法 from openpyxl import load_workbook from openpyxl.worksheet.works ...

  4. SpringMVC中如何在网站启动、结束时执行代码(详细,确保可用)

        在一个网站启动.结束时,我们经常有些操作是需要执行的. 熟悉Asp.net的朋友,使用Global.asax很容易就搞定,在其中有Application_Start和Application_E ...

  5. block做方法参数时--block的参数传值过程 例1

    说明:此例子中方法的调用在此文中是从下到上调用的.(即:     方法五调用方法四:      方法四调用方法三) 方法一:- (void)setCompletionBlockWithSuccess: ...

  6. ros中同时订阅两个topic(2张图像)合并成一个topic(1张图像)

    2019-12-06 15:42:39 先暂时做个资料保存 要同时用两个红外相机,但是没有做硬件上的 时间戳同步,就是笔记本上同时插着两个相机. 两个topic发布各自相机的图像,然后要有个节点同时订 ...

  7. 纯生js实现Element中input组件的部分功能(慢慢完善)并封装成组件

    现在实现的有基础用法.可清空.密码框,参考链接:https://element.eleme.cn/#/zh-CN/component/input HTML代码:想要测试哪个组件,直接将对应组件解开注释 ...

  8. 将CRUD封装到一个工具类中

    package org.zln.hibernate.utils; import org.hibernate.Session; import org.hibernate.SessionFactory; ...

  9. 【Spring】SpringMVC中浅析Date类型数据的传递

    在控制器中加入如下代码: @InitBinder public void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf ...

随机推荐

  1. OpenCV&&python_图像平滑(Smoothing Images)

    Goals 学习用不同低通滤波方法模糊图像(Blur imagess with various low pass filter) 用用定制的滤波器处理图像(Apply custom-made filt ...

  2. Mac sshw 使用

    sshw ssh client wrapper for automatic login. install use go get go get -u github.com/yinheli/sshw/cm ...

  3. 14. Android框架和工具之 ImageLoader(图片加载)

    1. 这个图片加载框架网友很多都已经使用过,而且分析也很到位,这里我就不写了,直接引用别人,尊重别人的劳动成果. 2. 参考如下: (1)Android 开源框架Universal-Image-Loa ...

  4. SOJ 1017 Power of Cryptography 库函数精度

    Background Current work in cryptography involves (among other things) large prime numbers and comput ...

  5. myeclipse解决JSP文件里script背景颜色的调整

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/UP19910522/article/details/27971401 1导入MyEclipse的主题 ...

  6. apache2 重启、停止、优雅重启、优雅停止

    停止或者重新启动Apache有两种发送信号的方法 第一种方法: 直接使用linux的kill命令向运行中的进程发送信号.你也许你会注意到你的系统里运行着很多httpd进程.但你不应该直接对它们中的任何 ...

  7. @property 装饰器

    property() 函数作用于新式类,返回属性值. class C(object): def __init__(self): self._x = None def getx(self): print ...

  8. 8、RabbitMQ-消息的确认机制(生产者)

    RabbitMQ 之消息确认机制(事务+Confirm) https://blog.csdn.net/u013256816/article/details/55515234 概述: 在 Rabbitm ...

  9. linux命令使用总结

    ## linux 查看系统全部信息 uname -a ## linux 查看系统内核信息 uname -r ## linux 查看系统版本号信息 cat /etc/redhat-release ## ...

  10. 崩溃!UIAlertController 引起的崩溃

    UIAlertController 使用方法很简单,下面贴简单的使用方法: UIAlertController *alert = [UIAlertController alertControllerW ...