1,
package com.songyan.jdbc2;public class User {private int id;private String name;public int getId() { return id;}public void setId(int id) { this.id = id;}public String getName() { return name;}public void setName(String name) { this.name = name;}}
2,
package com.songyan.jdbc2;import java.util.List;public interface UserDao { //增 void save(User u); //删 void delete(); //改 void update(); //查 User findUserById(int id); //查 int findUserCount(); //查 ListfindAllUser();}
3,
package com.songyan.jdbc2;import java.util.List;import org.springframework.jdbc.core.JdbcTemplate;public class UserDaoImpl implements UserDao{ private JdbcTemplate jt; public void setJt(JdbcTemplate jt) { this.jt = jt; } public void save(User u) { String sql="insert into users values ('1',?)" ; jt.update(sql,u.getName()); } public void delete(int id) { String sql="delete from users where id=?" ; jt.update(sql,id); } public void update(User u) { String sql="update users set name=? where id=?" ; jt.update(sql,u.getId()); } public User findUserById(int id) { String sql="select * from users where id=?" ; return null; } public int findUserCount() { String sql="select * from users where id=?" ; return 0; } public ListfindAllUser() { return null; } }