链接数据库配置properties apicationcontext.xml配置文件

properties配置文件中写入链接数据库
链接数据库配置properties apicationcontext.xml配置文件_第1张图片

xml配置文件代码



    
    
                  
    
        
        
        
        
    
    
    
    
    
    
        
    
 

使用jdbcTemplate 模板操作dao层代码

package com.itheima.e_properties;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.itheima.a_domain.User;

public class UserDao extends JdbcDaoSupport{
    
    
    
    public void update(User user) {
        String sql="update t_user set username=?,password=? where id=?";
        Object[] args= {user.getUsername(),user.getPassword(),user.getId()};
        this.getJdbcTemplate().update(sql, args);
    
    }
    public List findAll() {
        // TODO 自动生成的方法存根
        
        return this.getJdbcTemplate().query("select * from t_user", new BeanPropertyRowMapper(User.class));
    }
}

你可能感兴趣的:(链接数据库配置properties apicationcontext.xml配置文件)