MyBatis基于注解开发(联合查询)

MyBatis基于注解开发(联合查询)

2023年6月27日发(作者:)

MyBatis基于注解开发(联合查询) @Insert @Delete @Update @Param @ResultMap @Results(id="规则名",value={ @Result(property="",column="",id=true), @Result(property="",column=""), @Result(property="",column=""), @Result(property="",javaType=,column="",one=@One(select="⽅法名",fetchType=)), }) @Select("select * from xxx where xxx = #{key}") public Person selectOne(String key); @Select("") public IDCard selectIDCard();package dao;import ;import ;import tions.*;import ype;import ;public interface DeptDao { //设计⼀个⽅法

根据部门编号deptno

查询部门的信息+所属于当前部门的所有员⼯信息 @Results( id="selectDept", value={ @Result(property="deptno",column="deptno",id=true), @Result(property="dname",column="dname"), @Result(property="loc",column="loc"), @Result(property="empList",javaType=,column="deptno",many=@Many(select="selectEmp",fetchType=)), } ) @Select("select * from dept where deptno = #{deptno}") public Dept selectOne(Integer deptno); //辅助⽅法 @Select("select * from emp where deptno = #{deptno}") public Emp selectEmp(Integer deptno); //========================================================== @Select("select * from dept") @ResultMap("selectDept") public List selectAll();}package dao;import ;import ;import tions.*;import ype;import ;public interface EmpDao { //设计⼀个⽅法

根据员⼯empno编号

查询员⼯信息+所属部门信息 @Results( id="selectEmp", value={ @Result(property="empno",column="empno",id=true), @Result(property="ename",column="ename"), @Result(property="job",column="job"), @Result(property="mgr",column="mgr"), @Result(property="hiredate",column="hiredate"), @Result(property="sal",column="sal"), @Result(property="comm",column="comm"), @Result(property="dept",javaType=,column="deptno",one=@One(select="selectDept",fetchType=)) }) @Select("select * from emp where empno = #{empno}") public Emp selectOne(Integer empno); //辅助⽅法 @Select("select * from dept where deptno = #{deptno}") public Dept selectDept(Integer deptno); //==================================================== //查询所有的emp信息+每个emp对应的dept对象 @Select("select * from emp") @ResultMap("selectEmp") public List selectAll();}package dao;import ;import ;import tions.*;import ype;import ;public interface PersonDao { //设计⼀个⽅法

根据⼈的id

查询⼈的信息+连同对应的⾝份证信息 @Select("select * from person where pid = #{pid}") @Results( id="selectOne", value={ @Result(property="pid",column="pid",id=true), @Result(property="pname",column="pname"), @Result(property="idCard",javaType=,column="cardid",one=@One(select="selectOneIDCard",fetchType=)) } ) public Person selectOne(Integer pid);//⽅法返回值对应的是xml resultMap标签中的type属性 //辅助⽅法 @Select("select * from idcard where cardid = #{cardid}") public IDCard selectOneIDCard(String cardid); //利⽤原来的xml形式 //

⽂件中有好多 // ace----类名 // -----------⽅法名 // 3.

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信