Spring Boot 3---Controller使用案例
来源:互联网 发布:mysql 特殊字符入库 编辑:程序博客网 时间:2024/06/05 18:22
1、Spring Boot的Controller使用
(1)@Controller ---处理http请求
(2)@RestController---Spring4之后新加的注解,原来返回json需要 @ResponseBody配合@Controller
(3)RequestMapping配置url映射
(4)PathVariable获取url中的数据
(5)RequestParam获取请求参数的值
(6)GetMapping 组合注解
2、案例GirlProperties.java(在src/main/java/com.example包中)
package com.example;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;@Component@ConfigurationProperties(prefix="girl")public class GirlProperties { private String cupSize; private Integer age; public String getCupSize() { return cupSize; } public GirlProperties setCupSize(String cupSize) { this.cupSize = cupSize; return this; }}
application.yml(在src/main/resources包下)
server: port: 8081girl: cupSize: B age: 18
GirlController.java
package com.example;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controller@ResponseBodypublic class GirlController { @Autowired private GirlProperties girlProperties; @RequestMapping(value="/hello") public String say() { return girlProperties.getCupSize(); }}
GirlApplication.java
package com.example;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication//开启自动配置public class GirlApplication { //main方法作用:作为项目启动的入口 public static void main(String[] args) { SpringApplication.run(GirlApplication.class, args); }}
运行GirlApplication.java结果:
0 0
- Spring Boot 3---Controller使用案例
- Spring Boot-Controller控制器的使用
- Spring Boot Controller
- spring boot 之 controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot 学习——Controller的使用
- Spring Boot学习(一)之Controller的使用
- Spring Boot 在Controller使用@Transactional注解导致@RequestMapping失效
- spring boot 学习之controller
- Spring Boot 的控制器--Controller
- Spring Boot Junit 测试Controller
- spring boot中controller注意事项
- maven打包案例-spring boot
- Spring boot项目搭建案例
- Oracle遇到的知识点
- Android Accessibility功能
- spring+redis ip不能为127.0.0.1
- JAVA执行bat文件和shell脚本文件
- 创建型模式--工厂模式(Factory Pattern)
- Spring Boot 3---Controller使用案例
- VS[Web应用程序项目***已配置为使用IIS。无法访问IIS元数据库]
- Numpy-day01
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- 使用Apache Flume抓取数据(1)
- Java设计原则1—城堡游戏之消除代码复制
- zoj1029
- springmvc自定义参数绑定用户信息
- SpringBoot Web/API的通用异常处理[嗡汤圆的小笔记]