- 配置文件注入
<bean id="jdbcTemplateIeCenter" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="XXDataSource"></property>
</bean> - 获取bean对象 ApplicationContext att = SpringBeansUtil.getContext();context.getBean(name)
- 使用bean
JdbcTemplate xxTemplate = (JdbcTemplate) SpringBeansUtil.getBean("name");
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String insertSql ="INSERT into table VALUES(?,?,?,?,now(),'1')";
int count = ouTemplate.update(insertSql,new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1, xx); // xx
ps.setLong(2, xx);//xx
ps.setString(3, xx);//xx
ps.setString(4, xx);//xx
}
});
标签:ps,SpringBeansUtil,setString,getBean,xx,JdbcTemplate,使用 From: https://www.cnblogs.com/shuqing0803/p/17070062.html