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 ...
随机推荐
- 免费股票数据API接口
免费股票数据API接口提供沪深.香港.美国股市信息. 1.沪深股市 2.香港股市 3.美国股市 4.香港股市列表 5.美国股市列表 6.深圳股市列表 7.沪股列表 API文档:https://www. ...
- C++浅析——虚表和虚表Hook
为了探究虚表的今生前世,先来一段测试代码 虚函数类: class CTest { public: int m_nData; virtual void PrintData() { printf(&quo ...
- 《Remus: High Availability via Asychronous Virtual Machine Replication》翻译
Abstract 想要让应用能够躲过硬件故障是一项非常昂贵的任务,因为这通常意味着对软件进行重构,使它包含复杂的恢复逻辑的同时需要部署专用的硬件,而这些对于提升大型的或者遗留的应用的可靠性是巨大的障碍 ...
- STL vector
STL vector vector是线性容器,它的元素严格的按照线性序列排序,和动态数组很相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅可以使用迭代器(iterator)访问 ...
- POJ1065Wooden Sticks[DP LIS]
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21902 Accepted: 9353 De ...
- AC日记——求10000以内n的阶乘 openjudge 1.6 14
14:求10000以内n的阶乘 总时间限制: 5000ms 内存限制: 655360kB 描述 求10000以内n的阶乘. 输入 只有一行输入,整数n(0<=n<=10000). 输出 ...
- KEngine策划指南:配置表格的编辑与编译
策划与程序的桥梁 执行策划在游戏开发的过程中的主要工作是什么?当然就是和Excel打交道了.大量的Excel数据表,最终会被演变成游戏的配置数据.日常游戏开发中,策划编辑配置表一般有两种方式: 编译式 ...
- [No000016]为什么假期计划总是做不到?
- ubuntu12.04安装搜狗输入法和配置
1.安装 参考http://hi.baidu.com/lowkey2046/item/7ff8b33abe492bd06d15e9b6 2.配置 当前系统语言默认为英语 1)点击右上角的键盘按钮-&g ...
- docker中如何制作自己的基础镜像
一.本地镜像 举个例子:现在把自己的开发环境打包,取名为centos6-base.tar,然后在docker中,以centos6-base.tar作为基准镜像. 1.创建自己的镜像,放置于/root目 ...