赞
踩
这几年来注解开发越来越流行,Mybatis也可以使用注解开发方式,这样我们就可以减少编写Mapper
映射文件了。我们先围绕一些基本的CRUD来学习,再学习复杂映射多表操作。
一对多案例:
public interface OrderMapper { @Select("select * from orders") @Results({ @Result(id=true,property = "id",column = "id"), @Result(property = "ordertime",column = "ordertime"), @Result(property = "total",column = "total"), @Result(property = "user",column = "uid", javaType = User.class, one = @One(select = "com.lagou.mapper.UserMapper.findById") ) }) List<Order> findAll(); } public interface UserMapper { @Select("select * from user where id=#{id}") User findById(int id); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。