基本类型、包装类型的数据绑定以及坑
来源:互联网 发布:2016淘宝销量排行榜 编辑:程序博客网 时间:2024/06/05 18:19
基本类型、包装类型的数据绑定以及坑
例如,age
可以是基本类型:int、也可以是包装类型:Integer
情景一:age为int类型时
错误:参数不是int类型时,springmvc报错400
错误:不传参数,springmvc报错500
情景二:age为包装类型。例如Integer
当然我们实际开发过程中,也可以通过
@RequestParam()
@RequestParam()注解对是否进行配置下面给出我的实例代码:
package com.wsq.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;/** * Created by wsq on 2017/12/17下午9:31. * 本章主要介绍基本类型、包装类型的数据绑定以及坑 */@Controllerpublic class TestController { //TODO http://localhost:8080/baseType.do?xage=10 @RequestMapping(value = "baseType.do", method = RequestMethod.GET) @ResponseBody public String baseType(@RequestParam("xage") int age){ return "age: " + age; } //TODO http://localhost:8080/baseType2.do?age=10 @RequestMapping(value = "baseType2.do", method = RequestMethod.GET) @ResponseBody public String baseType2(Integer age){ return "age: " + age; } //TODO http://localhost:8080/array.do?name=Tom&name=Lucy&name=Jim @RequestMapping(value = "array.do", method = RequestMethod.GET) @ResponseBody public String baseType2(String[] name){ StringBuilder sbf = new StringBuilder(); for (String item : name) { sbf.append(item).append(" "); } return sbf.toString(); }}
阅读全文
0 0
- 基本类型、包装类型的数据绑定以及坑
- SpringMVC数据绑定一(基本数据类型及包装类型)
- 基本类型的包装类型
- 基本类型的包装类
- java基本类型的包装
- 基本类型对应的包装类类型
- Java的基本类型和包装类型
- 优先选择基本类型而不是基本类型的包装类型
- 包装类型的数据比较
- Java 基本类型优先于包装类型,以及二者之间的选择
- 基本类型与包装类型
- 引用类型---基本包装类型
- js基本包装类型
- 06 基本包装类型
- JavaScript基本包装类型
- JS 基本包装类型
- javascript基本包装类型
- [JavaScript]基本包装类型
- Hdoj 2003 求绝对值
- sql模糊查询
- SSH配置整合
- 百度网盘不限速工具
- XGBoost 中特征重要性和特征选择原理解析与实战
- 基本类型、包装类型的数据绑定以及坑
- Week17 总结
- 二分图匹配
- Hdoj 2004 成绩转换
- leetcode 516. Longest Palindromic Subsequence
- Python数据处理的瑞士军刀:pandas
- Python 实现简单的网络抓取图片
- [BZOJ] 2141
- MySQL Workbench不能向表中添加数据,右键select rows 看不到可编辑的数据表,怎么办?