什么是Mybatis动态SQL
Mybatis动态SQL,就是通过if、choose、when、otherwise、trim、where、foreach等标签组合成灵活的SQL语句,从而在提高SQL语句的准确性的同时,大大提高开发人员的效率
下面以stu表为例
package com.pojo;
import lombok.Data;
import java.io.Serializable;
/**
* @Description:
* @Author: Administrator
* @Create: 2022/07/26 17:08
* @Version:
*/
@Data
public class Student implements Serializable {
private String sid;
private String sname;
private Integer sage;
private String sgender;
public Student() {
}
public Student(String sid, String sname, Integer sage, String sgender) {
this.sid = sid;
this.sname = sname;
this.sage = sage;
this.sgender = sgender;
}
}
if语句
当我们要通过姓名和性别查询学生信息时,
public Student findStudentByNameAndSex(Student s);
我们可以直接写入sql语句:
<select id="findStudentByNameAndSex" resultType="Student" parameterType="Student"