在实际业务场景中,当前台通过 url 向后台传送多个参数时,可以将参数封装成一个bean类,在bean类中对各个参数进行非空,默认值等的设置。
前台 url ,想后台传送两个参数,username 和 password:
1 http://localhost:8082/web/baseaction.do?pathvar=app/task/fetchitemdetail.do?username=123&password=123
将参数封装成bean 类,并在bean类中对参数进行控制:
1 2 3 import org.hibernate.validator.constraints.notempty; 4 5 /** 6 * created by thinkpad on 2017/10/23. 7 */ 8 public class querycondition { 9 10 @notempty(message = "validator.username") 11 private string username ; 12 private string password; 13 14 public string getusername() { 15 return username; 16 } 17 18 public void setusername(string username) { 19 this.username = username; 20 } 21 22 public string getpassword() { 23 if (null == password || password.length() == 0){ 24 password = "123456"; 25 } 26 return password; 27 } 28 29 public void setpassword(string password) { 30 this.password = password; 31 } 32 }
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(); }
如对本文有疑问, 点击进行留言回复!!
unity的错误解决办法:NullReferenceException: Object reference not set to an instance of an object;tiny proje
Hadoop 之 HDFS (HDFS 数据流的 读写 流程)
听说你一读Spring源码就懵逼?我帮你把架子搭好了,你填就行!
首席架构师推荐:金融保险领域数字化转型实践--如何优雅地修改业务中台中分层应用Maven多模块的版本号?(命令导入式)
[JVM学习之路]一、初识JVM,了解其结构、模型及生命周期
网友评论