参数配置
1、application.properties
jdbc.config.url=jdbc:mysql://127.0.0.1:3306/dbwback?useUnicode=true&characterEncoding=UTF-8
jdbc.config.driver=com.mysql.jdbc.Driver
jdbc.config.username=root
jdbc.config.password=pass01!
2、
@Configuration
@ConfigurationProperties(prefix = "jdbc.config")
public
class JdbcConfig {
private String url;
private String driver;
private String username;
private String password;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String toString() {
return "url="+url+",driver="+driver+",username="+username+",password="+password;
}
}
3.在
controller中直接使用
@Controller("user_controller")
@RequestMapping("/user")
public class UserController{
@Autowired
JdbcConfig jdbcConfig;
}