SpringMVC使用@PathVariable,@RequestBody,@ResponseBody,@RequestParam,@InitBinder
- @Pathvariable
public ResponseEntity<String> ordersBack(
@PathVariable String reqKey,
@RequestParam(value="intVal") Integer intVal,
@RequestParam(value="strVal") String strVal) throws Exception{
return new ResponseEntity("ok", HttpStatus.OK);
}
- @RequestParam
@Controller
@RequestMapping("/pets")
@SessionAttributes("pet")
publicclass EditPetForm {
@RequestMapping(method = RequestMethod.GET)
public String setupForm(@RequestParam("petId") int petId, ModelMap model) {
Pet pet = this.clinic.loadPet(petId);
model.addAttribute("pet", pet);
return"petForm";
}
}
- @RequestBody
- @ResponseBody
@Controller
public class PersonController {
/**
* 查询个人信息
*
* @param id
* @return
*/
@RequestMapping(value = "/person/profile/{id}/{name}/{status}", method = RequestMethod.GET)
public @ResponseBody
Person porfile(@PathVariable int id, @PathVariable String name,
@PathVariable boolean status) {
return new Person(id, name, status);
}
/**
* 登录
*
* @param person
* @return
*/
@RequestMapping(value = "/person/login", method = RequestMethod.POST)
public @ResponseBody
Person login(@RequestBody Person person) {
return person;
}
}
@InitBinder
表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 该标签是进行数据类型转换的,将string类型转为自定义的类型。
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
SpringMVC使用@PathVariable,@RequestBody,@ResponseBody,@RequestParam,@InitBinder的更多相关文章
- [@Controller]3 详解@CookieValue,@PathVariable,@RequestBody,@RequestHeader,@RequestParam
[@Controller]3 详解@CookieValue,@PathVariable,@RequestBody,@RequestHeader,@RequestParam 转载:http://blog ...
- springMVC(二): @RequestBody @ResponseBody 注解实现分析
一.继承结构 @RequestBody.@ResponseBody的处理器:RequestResponseBodyMethodProcessor @ModelAttribute处理器: ModelAt ...
- @RequestBody和@RequestParam区别
@RequestParam 用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容.(Http协议中,默认传递的参数就是applicati ...
- @RequestBody, @ResponseBody 注解详解(转)
原文地址: https://www.cnblogs.com/qq78292959/p/3760651.html @RequestBody, @ResponseBody 注解详解(转) 引言: 接上一篇 ...
- @requestbody @responsebody详解
@requestbody @responsebody详解 会唤起spring mvc的httpmessageconveter转换类进行数据转换 简介: @RequestBody 作用: i) 该注解用 ...
- @RequestBody, @ResponseBody 注解理解
@RequestBody, @ResponseBody 注解理解 自己以前没怎么留意过,来实习后公司采用前后端分离的开发方式,前后端拿到的注释都是 json 格式的,这时候 @RequestBody, ...
- @RequestBody 和 @RequestParam(“test”) 的区别与联系
@RequestBody @RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的):GET方式无请求体,所以使用@RequestBody接收数据时,前端不能使用 ...
- 【SpringBoot—注解】@requestBody 与@requestparam;@requestBody的加与不加的区别
一)首先说明xia @requestBody与@requestParam的区别 spring的RequestParam注解接收的参数是来自于requestHeader中,即请求头.都是用来获取请求路径 ...
- @requestBody 与@requestparam详解
@RequestParam注解接收的参数是来自于requestHeader中,即请求头.都是用来获取请求路径url 中的动态参数,格式为xxx?username=123&password=45 ...
随机推荐
- Hyper-V架构与VMware ESXi的差异
微软的Hyper-V与VMware的ESXi在架构上有众多不同,然而很多虚拟化管理员并未意识到这些差异.而且很多管理员同样对Hyper-V是在主机操作系统上运行感到困惑. 有关微软Hyper-V的一个 ...
- FTP上传与下载
1.连接 先假设一个ftp地址 用户名 密码 FTP Server: 192.168.1.125 User: administrator Password: abc123 2. 打开win ...
- 单元测试实战 - 如何使用Eclipse
一.Eclipse工具的使用 1. 进入官网: http://www.eclipse.org ,点击download,根据系统版本选择自己需要的版本,下载之后,会得到一个zip文件,将这个文件解压到 ...
- sturct2类型转化
第三种struts2类型转换方式实例 1.convert.jsp <%@ page language="java" import="java.util.*" ...
- jsonobject 遍历 org.json.JSONObject
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public static ...
- PAT 1008. 数组元素循环右移问题 (20)
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 ...
- some basic graph theoretical measures
· mean characteristic path length calculated as the average length of the shortest path between two ...
- win10显示此电脑
http://jingyan.baidu.com/article/3aed632e00dfe17011809169.html
- 未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage
本文出处:http://blog.sina.com.cn/s/blog_6fe3efa301016i64.html vs 2005 ,vs 2008, vs 2010,安装后有时出现这个错误(我的机器 ...
- 4817 江哥的dp题d
4817 江哥的dp题d 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 已知1-N的排列P的LIS(最长上 ...