<bean id="userDao" class="com.hw.domain.UserDao">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<bean id="serviceDao" class="com.hw.domain.ServiceDao">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
public class UserDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void save(){
String sql= "insert into pop values(?,?)";
jdbcTemplate.update(sql,2,"ppp");
}
}
public class UserDao extends JdbcTemplate{
public void add(){
String sql = "insert into pop values(?,?)";
update(sql,5,"ss");
}
}
<bean id="userDao" class="com.hw.domain.UserDao">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class UserDao extends JdbcDaoSupport{
public void add(){
String sql = "insert into pop values(?,?)";
this.getJdbcTemplate().update(sql,6,"ss");
}
}
<bean id="userDao" class="com.hw.domain.UserDao">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
网友评论