我的实现类:
public class UserDaoImpl implements UserDao {
private JdbcTemplate template;
public boolean addUser(UserBean ub) {
String sql ="insert into tbl_user(loginName,loginPwd,age) values(?,?,?)";
Integer count = template.update(sql, new Object[]{ub.getLoginName(),ub.getLoginPwd(),ub.getAge()});
return count!=0?true:false;
}
public boolean delUser(Integer id) {
String sql ="delete from tbl_user where id =?";
Integer count = template.update(sql, new int[]{id});
return count!=0?true:false;
}
public boolean updateUser(UserBean ub) {
String sql ="update tbl_user set loginName =?,loginPwd =?,age=? where id =?";
Integer count = template.update(sql, new Object[]{ub.getLoginName(),ub.getLoginPwd(),ub.getAge(),ub.getId()});
return count!=0?true:false;
}
public List<UserBean> allUser(){
String sql ="select * from tbl_user ";
return template.queryForList(sql, UserBean.class);
}
public JdbcTemplate getTemplate() {
return template;
}
public void setTemplate(JdbcTemplate template) {
this.template = template;
}
}