Spring MVC常用注解详解编程语言
2023-06-13 09:11:43 时间
请求路径映射,可以标注类,也可以是方法,可以指定请求类型,默认不指定为全部接收。
放在参数前,表示只能接收参数a=b格式的数据,即 Content-Type为 application/x-www-form-urlencoded类型的内容。
放在参数前,表示参数从request body中获取,而不是从地址栏获取,所以这肯定是接收一个POST请求的非a=b格式的数据,即 Content-Type不为 application/x-www-form-urlencoded类型的内容。
放在方法上或者返回类型前,表示此方法返回的数据放在response body里面,而不是跳转页面。一般用于ajax请求,返回json数据。
GetMapping PostMapping PutMapping.. *Mapping的是Spring4.3加入的新注解,表示特定的请求类型路径映射,而不需要写RequestMethod来指定请求类型。
import org.dom4j.util.UserDataElement; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/test") public class TestController { @RequestMapping(value = "/get/{no}", method = RequestMethod.GET) @ResponseBody public Object get(@PathVariable("no") String no) { return new UserDataElement(""); @RequestMapping(value = "/save", method = RequestMethod.POST) public void save(@RequestBody UserDataElement user) { }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/16525.html
cjava相关文章
- Spring MVC 框架学习(三)---- 我的第一个 Spring MVC 程序
- SpringBoot集成Spring Security(1)——入门程序
- spring注解有哪些_Spring 注解
- Spring MVC框架:第七章:REST架构风格
- 【愚公系列】2023年04月 Java教学课程 135-Spring MVC框架的概念和基本使用
- 【愚公系列】2023年04月 Java教学课程 139-Spring MVC框架的前后端数据交互
- Spring学习笔记四 整合SSH详解编程语言
- 基于注解的spring MVC程序详解编程语言
- Spring错误:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.B详解编程语言
- spring mvc入门详解编程语言
- Spring MVC 框架搭建及详解编程语言
- spring mvc(注解)上传文件的简单例子详解编程语言
- spring mvc 服务器端输出一条可执行js详解编程语言
- spring mvc返回json字符串的方式详解编程语言
- Maven+Spring+Spring MVC+MyBatis+MySQL整合SSM框架详解编程语言
- spring Boot(十九):使用Spring Boot Actuator监控应用详解编程语言
- Spring Boot(十四):spring boot整合shiro-登录认证和权限管理详解编程语言
- spring以及spring MVC详解编程语言
- Spring MVC应用@Autowired和@Service进行依赖注入
- Spring框架下整合Redis的实现(spring整合redis)