美文网首页
Dao使用JDBCTemplate

Dao使用JDBCTemplate

作者: 打死你的小白兔 | 来源:发表于2018-03-30 03:29 被阅读0次
    
        <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>
    

    相关文章

      网友评论

          本文标题:Dao使用JDBCTemplate

          本文链接:https://www.haomeiwen.com/subject/tshvcftx.html