配置属性文件:application.properties中写下列属性:
server.port=8080
server.servlet.context-path=/website
helloWorld=Hello SpringBoot!
mysql.jdbcName=com.mysql.jdbc.Driver
mysql.dbUrl=jdbc:mysql://localhost:3306/xzs
mysql.userName=root
mysql.password=825864
Controller中调用application.properties属性文件中的属性:
//把application.properties属性文件中的helloWorld的值赋给 hello
@Value("${helloWorld}")
private String hello;
@Value("${mysql.jdbcName}")
private String jdbcName;
@Value("${mysql.dbUrl}")
private String dbUrl;
@Value("${mysql.userName}")
private String userName;
@Value("${mysql.password}")
private String password;
@RequestMapping("/hello") //这个注解返回的是字符串
public String hello(){
return hello;
}