keypropert是查询的属性的名称 resulttype是XM代理申请www.fx61.com/brokerlist/xm.html返回值类型,是查询结果的返回值类型 order是执行顺序 keycolum:数据库中对应的属性 多种查询方法的使用 1.模糊查询 select from table where name=#{name} [1]在查询的时候改正 SelectAll("%ko%"); [2]在sql语句中改正 使用concat函数 select from table where id=concat('%',#{id},'%')
多表联合查询 (1) mapper文件的配置类
//封装连接类的属性,主要是主类属性 //用association封装子类所有的属性
(2) test测试类@org.junit.Test br/>@org.junit.Test SqlSession session=Util.getSession(); PeopleMapperDao peopleMapperDao=session.getMapper(PeopleMapperDao.class); peopleMapperDao.SelectTogether(); List list=null; list=peopleMapperDao.SelectTogether(); System.out.println(list); } 3.一对一联合查询 配置类文件 package com.pojo; public class Student { private String name; private Integer id; private Integer tid;//和老师中的id对因 private String address; private String city; //一个学生对应一个老师 private Teacher teacher;//在学生中查询老师 public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getTid() { return tid; } public void setTid(Integer tid) { this.tid = tid; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public Teacher getTeacher() { return teacher; } public void setTeacher(Teacher teacher) { this.teacher = teacher; } public Student(String name, Integer id, Integer tid, String address, String city, Teacher teacher) { this.name = name; this.id = id; this.tid = tid; this.address = address; this.city = city; this.teacher = teacher; } public Student() { }@Override br/>@Override return "Student{" + "name='" + name + '\'' + ", id=" + id + ", tid=" + tid + ", address='" + address + '\'' + ", city='" + city + '\'' + ", teacher=" + teacher + '}'; } } 接口配置 package com.service; import com.pojo.Student; import java.util.List; public interface StudentDao { public List Selectall(); public List SelectByid(Integer id); //查询所有学生 public List SelectAllStudent(); public List selct01(); } mapper文件配置
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4.多对一联合查询
多对多的联合查询 实体类的配置 package com.pojo; import java.util.Date; import java.util.List; public class Writer { private String name; private Integer id; private Integer age; private String sex; private String book; private Date birthday; //查询作者里面包含作品 private List works; public List getWorks() { return works; } public void setWorks(List works) { this.works = works; } public Writer(List works) { this.works = works;} @Override br/>} @Override return "Writer{" + "name='" + name + '\'' + ", id=" + id + ", age=" + age + ", sex='" + sex + '\'' + ", book='" + book + '\'' + ", birthday=" + birthday + ", works=" + works + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBook() { return book; } public void setBook(String book) { this.book = book; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public Writer(String name, Integer id, Integer age, String sex, String book, Date birthday) { this.name = name; this.id = id; this.age = age; this.sex = sex; this.book = book; this.birthday = birthday; } public Writer() { } } mapper文件配置
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">