mybatis4

批量删除

<deleteid="delMore">

  deletefrom t_user where u_id in(

  <foreachcollection="ids" item="id" separator=",">

  #{id}

  </foreach>

  )

  </delete>

collection为用于遍历的元素(必选),支持数组、List、Set
item表示集合中每一个元素进行迭代时的别名.
index指 定一个名字,用于表示在迭代过程中,每次迭代到的位置.
open表示该语句以什么开始,
separator表示在每次进行迭代之间以什么符号作为分隔符.
close表示以什么结束.

类定义

一方:

public class UserObj {

   privateint id;

   privateString name;

  privateint age;

 

  privateList<ResultObj> resultList = new ArrayList();

}

多方:

public class ResultObj {

   privateint id;

   privateint point;

    private UserObj user;

}



操作多对多关系中,中间表需要手动维护

类定义
老师表

public class TeacherBean {

  privateint id;

  privateString teacherName;

  privateList studentList;

}

学生表

publicclass StudentBean {

  private int id;

  private String studentName;

   privateList teacherList;

}


定义别名
<typeAliasalias="teacher" type="com.lovo.bean.TeacherBean"/>
  <typeAliasalias="student" type="com.lovo.bean.StudentBean"/>
根据id查询老师,返回一个查询结果
<selectid="findTeacher" resultMap=" tm">
  select* from t_teacher where id=#{id};
<resultMapclass="teacher" id=" tm">
  <associationproperty="studentList" column="id" select=" findStudentByTeacher"/>
  </resultMap>
联接中间表按老师查询学生集合
<select id=" findStudentByTeacher"resultType="student">
  SELECTs.* FROM t_student s JOIN t_teacher_student ts ON s.id=ts.studentId WHERE ts.teacherId=#{id};
  </select>
  </select>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值