public interface TestDao { List query(String sql,Object[] params); int update(String sql,Object[] params);}
public class TestDaoImpl implements TestDao { @Override public List query(String sql,Object[] params) { DBHelper db = new DBHelper(); return db.query(sql, params); } @Override public int update(String sql,Object[] params) { DBHelper db = new DBHelper(); return db.update(sql, params); }}
public interface TestService { List getTestList();//获取列表 int insertTest(Object[] params);//插入一条 int modifyTest(Object[] params);//修改 int deleteTest(Object[] params);//删除}
public class TestServiceImpl implements TestService { TestDao testDao = new TestDaoImpl(); @Override public List getTestList() { String sql = "select * from test"; return testDao.query(sql, null); } @Override public int insertTest(Object[] params) { String sql ="insert into test(name) values(?)"; return testDao.update(sql, params); } @Override public int modifyTest(Object[] params) { String sql ="update test set name = ? where id = ?"; return testDao.update(sql, params); } @Override public int deleteTest(Object[] params) { String sql ="delete from test where id = ?"; return testDao.update(sql, params); }}