当SpringBoot以war包运行时,获取applicationContext的方法
最近接手别人的一个Spring Boot后台接口的项目的时候,发现其业务逻辑层,也就是与数据库连接的那一块代码没用使用现在主流的MyBatis等,用的还是较为原始的JdbcTemplate,其中某接口的业务逻辑层如下。
public boolean update_addbind(BindBean bb){
boolean flag = true;
String sqlTxt =
"INSERT INTO dbind (dev,dphone,dname) VALUE ('"
+bb.getDev()+"' , '"
+bb.getDphone()+"' , '"
+bb.getDname()+"' ) ";
JdbcTemplate jdbcTemplate =
(JdbcTemplate) SpringUtil.applicationContext.getBean("jdbcTemplate");
int i = 0;
i = jdbcTemplate.update(sqlTxt)