您好,欢迎来到飒榕旅游知识分享网。
搜索
您的当前位置:首页05 - mybatis - 注解crud

05 - mybatis - 注解crud

来源:飒榕旅游知识分享网

注解方式crud

注解一对一

 @Select("select * from student s  where s.id = #{id}")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "name",column = "name"),
            @Result(property = "tid",column = "tid"),
            @Result(property = "teacher" ,javaType = cn.laixueit.pojo.Teacher.class, column = "tid", one = @One(select = "cn.laixueit.mapper.StudentMapper.t"))
    })
    Student onetoone(Integer id);

    @Select("select name tname from teacher where id = #{id}")
    Teacher t(Integer id);

一对多

@Select("select * from student")
@Results(
   id = "studentMap2",
   value = {
       @Result(property = "id",column = "id",id = true),
       @Result(property = "name",column = "name"),
       @Result(property = "address",column = "address"),
       @Result(property = "teachers" ,column = "id",many = @Many(select = "cn.laixueit.mapper.TeacherMapper.findBySid"))
   }
)
public List<Student> findStudentOneToManyTeacher2();

@Select("select * from teacher where sid = #{id}")
public Teacher findBySid(Integer id);

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务