SpringBoot Controller
2017-10-16 20:38
344 查看
@Controller处理HTTP请求@RestController = @Controller + @ResponseBody 处理Rest请求@RequestMapping 配置URL映射1、获取请求参数的两种方式@RestControllerpublic class HelloController {@Value("${cupSize}")private String cupSize;@Value("${age}")private Integer age;@Autowiredprivate GirlProperties girlProperties;//请求形式1// localhost:8082/hello/12@RequestMapping(value = "/hello/{id}",method = RequestMethod.GET)public String say(@PathVariable("id") Integer id){return "id:" + id;}//请求形式2//localhost:8082/hello?hi=12//@RequestMapping(value = "/hi",method = RequestMethod.GET) @GetMapping(value = {"/hi","hello"})public String hi(@RequestParam(value = "id",required = false,defaultValue = "0") Integer id){return "id:" + id;}}required = false,defaultValue = "0"表示不必须,缺省值为0
相关文章推荐
- spring boot aop拦截Controller失败
- Spring Boot @ControllerAdvice 处理全局异常,返回固定格式Json
- spring-mvc springboot 使用MockMvc对controller进行测试
- Spring-boot application controller 方法自动解析Locale参数原理
- Spring Boot的Controller控制层和页面
- 打印spring boot的controller里定义的路由
- Spring Boot Controller
- SpringBoot实践之---Controller
- 使用MockMvc编写spring boot的controller的测试用例
- springboot集中处理controller层的异常(有关@ControllerAdvice的用法)
- Spring Boot Controller
- Spring Boot 学习——Controller的使用
- SpringBoot配置非含main类的Controller的注解
- springboot使用addViewController减少控制器代码的编写
- 【spring Boot】Spring中@Controller和@RestController之间的区别
- Spring-boot 配置Aop获取controller里的request中的参数以及其返回值
- SpringBoot第2小节:Controller(控制器)的使用
- SpringBoot 中常用注解@Controller/@RestController/@RequestMapping介绍(转)
- Spring Boot @ControllerAdvice 处理全局异常,返回固定格式Json
- SpringBoot的Controller使用