Mybatis——动态SQL

Posted Gendan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis——动态SQL相关的知识,希望对你有一定的参考价值。

package cn.yyj1.entity;
public class StudentInfo {

private String studentid;
private String studentName;
private String studentSex;
private String studentPhone;
private String studentAddress;
private int  studentAge;
private int  stuclassid;
//私有的  类型  名字
//只有空的构造方法  才能查到className 的信息
private ClassInfo classInfo;
public String getStudentid() {
    return studentid;
}
public void setStudentid(String studentid) {
    this.studentid = studentid;
}
public String getStudentName() {
    return studentName;
}
public void setStudentName(String studentName) {
    this.studentName = studentName;
}
public String getStudentSex() {
    return studentSex;
}
public void setStudentSex(String studentSex) {
    this.studentSex = studentSex;
}
public String getStudentPhone() {
    return studentPhone;
}
public void setStudentPhone(String studentPhone) {
    this.studentPhone = studentPhone;
}
public String getStudentAddress() {
    return studentAddress;
}
public void setStudentAddress(String studentAddress) {
    this.studentAddress = studentAddress;
}
public int getStudentAge() {
    return studentAge;
}
public void setStudentAge(int studentAge) {
    this.studentAge = studentAge;
}
public int getStuclassid() {
    return stuclassid;
}
public void setStuclassid(int stuclassid) {
    this.stuclassid = stuclassid;
}
public ClassInfo getClassInfo() {
    return classInfo;
}
public void setClassInfo(ClassInfo classInfo) {
    this.classInfo = classInfo;
}
public StudentInfo(String studentid, String studentName, String studentSex, String studentPhone, String studentAddress, int studentAge, int stuclassid, ClassInfo classInfo) {
    this.studentid = studentid;
    this.studentName = studentName;
    this.studentSex = studentSex;
    this.studentPhone = studentPhone;
    this.studentAddress = studentAddress;
    this.studentAge = studentAge;
    this.stuclassid = stuclassid;
    this.classInfo = classInfo;
}
public StudentInfo(String studentName, String studentSex, String studentPhone, String studentAddress, int studentAge, int stuclassid, ClassInfo classInfo) {
    this.studentName = studentName;
    this.studentSex = studentSex;
    this.studentPhone = studentPhone;
    this.studentAddress = studentAddress;
    this.studentAge = studentAge;
    this.stuclassid = stuclassid;
    this.classInfo = classInfo;
}
public StudentInfo() {
}

}
package cn.yyj1.mapper;
import cn.yyj1.entity.ClassInfo;
import cn.yyj1.entity.StudentInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface StudentInfoMapper {

//根据班级编号查询所属班级的所有学生信息  id 班级编号   所属这个班级的学生
public List<StudentInfo> findStuByClassId(int id);
//根据班级编号查询班级信息 id [货币代码](https://www.gendan5.com/currencycode.html)班级信息 班级信息
public ClassInfo findClassByClassId(int id);
//根据班级编号查询所属姓名的学生
public  List<StudentInfo> findStudNameByClassId(@Param("stuclassid") int stuclassid, @Param("studentName") String studentName);
//根据ID修改学生信息
public  int update (StudentInfo si);
public StudentInfo findStudentById(String id);
//根据数组查询所有学生信息 定义数组 int [] array
public  List<StudentInfo> findStudentByArray(int [] array);
//根据集合查学生信息
public  List<StudentInfo> findStudentByList(List<StudentInfo> list);
//根据Map查询
public  List<StudentInfo> findStudentByMap(Map<String,Object> map);
//Choose
public  List<StudentInfo> findStudentByChoose(@Param("studentName")String studentName,@Param("studentAge")int studentAge,@Param("stuclassid")int stuclassid);
//分页
public  List<StudentInfo> findStudentByPage(@Param("pageSize")int pageSize,@Param("pageCode")int pageCode);

}

以上是关于Mybatis——动态SQL的主要内容,如果未能解决你的问题,请参考以下文章

mybatis动态sql片段与分页,排序,传参的使用

Mybatis -- 动态Sql概述动态Sql之<if>(包含<where>)动态Sql之<foreach>sql片段抽取

mybatis动态sql之利用sql标签抽取可重用的sql片段

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段

[mybatis]动态sql_sql_抽取可重用的sql片段

Mybatis动态sql