基于注解的关联查询用到的pojo实体类以及创建表的mysql语句分别在文章Mybatis一对一查询、Mybatis一对多查询、Mybatis多对多查询里有
在项目文件下新建dao包,并新建接口类ByAnnotation用于编写注解代码
package com.hxx.associatedQuery.dao;
import com.hxx.associatedQuery.pojo.orders.Goods;
import com.hxx.associatedQuery.pojo.orders.Orders;
import com.hxx.associatedQuery.pojo.person.Person;
import com.hxx.associatedQuery.pojo.person.PersonInformation;
import com.hxx.associatedQuery.pojo.reader.Lend_Books;
import com.hxx.associatedQuery.pojo.reader.Readers;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface ByAnnotation {
// 一对一注解查询;
@Select("select * from user where uId=#{uId}")
List<Person> oneForOne(Integer id);
@Select("select * from user_information where id=#{id}")
@Results({@Result(column = "user_id",property = "person",
one = @One(select = "com.hxx.associatedQuery.dao.ByAnnotation.oneForOne"))})
List<PersonInformation> selectOneForOne(Integer id);
// 一对多注解查询;
@Select("select * from lend_books where lend_id=#{id}")
@Results({@Result(id