1, 在 application.properties 中自定义参数
- spring.datasource.driverClassName=com.MySQL.jdbc.Driver
- spring.datasource.url=jdbc:MySQL://localhost:3306/test?characterEncoding=UTF-8
- spring.datasource.username=root
- spring.datasource.password=root
- spring.thymeleaf.mode=html5
- spring.thymeleaf.encoding=UTF-8
- spring.thymeleaf.content-type=text/HTML
- # 开发时关闭缓存, 不然没法看到实时页面
- spring.thymeleaf.cache=false
- name=cppdy
2, 在 UserController 中获取自定义参数, 并创建测试方法
- // 获取自定义参数的值
- @Value("${name}")
- private String name;
- // 测试获取自定义参数值的方法
- @RequestMapping("getName")
- public String getName() {
- return name;
- }
来源: http://www.bubuko.com/infodetail-2869350.html