properties配置文件中写入链接数据库
xml配置文件代码
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
使用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));
}
}