标签:pack seda sql get import extend actor port ace
package cn.my.dao; import java.util.List; /** * 将公用方法提取出来 * @author Administrator * * @param <T> */ public interface BaseDao<T> { public List<T> findAll(); public T findById(int id); public void insert(T entity); public void update(T entity); public void delete(int id); }
package cn.my.dao; import java.util.List; import cn.my.mybatis.entity.User; import cn.my.mybatis.entity.UserQueryVo; public interface UserDaoMapper extends BaseDao<User> { public List<User> findByNameAndSex(UserQueryVo userVo); public List<User> findByIds(UserQueryVo userVo); /** * 直接注释父接口中已有的方法 */ // public User findById(int id); // public void insert(User entity); // public void update(User entity); // public void delete(int id); }
package cn.my.dao; import java.util.List; import cn.my.mybatis.entity.Orders; public interface OrdersDaoMapper extends BaseDao<Orders> { // public List<Orders> findAll(); public List<Orders> findDetialAll(); }
@Test public void testfindDetialAll(){ SqlSession session = factory.openSession(); OrdersDaoMapper dao = session.getMapper(OrdersDaoMapper.class);//获取mybatis的动态代码实现接口对象 List<Orders> list = dao.findDetialAll(); session.close(); for (Orders orders : list) { System.out.println(orders); } }
Orders [id=3, user_id=1, number=1000010, createtime=Wed Feb 04 13:22:35 CST 2015, note=null, user=User [id=1, username=王五, sex=2, birthday=null, address=null], detailList=[Ordersdetail [id=1, items_id=1, items_num=1, orders_id=0], Ordersdetail [id=2, items_id=2, items_num=3, orders_id=0]]]
Orders [id=4, user_id=1, number=1000011, createtime=Tue Feb 03 13:22:41 CST 2015, note=null, user=User [id=1, username=王五, sex=2, birthday=null, address=null], detailList=[Ordersdetail [id=3, items_id=3, items_num=4, orders_id=0], Ordersdetail [id=4, items_id=2, items_num=3, orders_id=0]]]
好了写完了以上就是封装的一个最简单的BaseDao.java,有时间我会继续往下写的,如果需要加群一起研究的可以q我,939705214,也可以添加群号581591235
标签:pack seda sql get import extend actor port ace
原文地址:http://www.cnblogs.com/duchaochen/p/7599335.html