Caching mybatis一对一关系,发送多个参数
我正在使用mybatis,我有一对一的关系,但我想发送多个参数,以下是我的代码:Caching mybatis一对一关系,发送多个参数,caching,mybatis,one-to-one,Caching,Mybatis,One To One,我正在使用mybatis,我有一对一的关系,但我想发送多个参数,以下是我的代码: @Mapper public interface ParentMapper { @Select("select o.id, o.name, o.key from parent o where o.key=#{key}") @Result({ @Result(column = "id", property = "id") @Result(column = "name",
@Mapper
public interface ParentMapper {
@Select("select o.id, o.name, o.key from parent o where o.key=#{key}")
@Result({
@Result(column = "id", property = "id")
@Result(column = "name", property = "name")
@Result(column = "id", property = "child", one=@One(select = "getChild"))
})
List<Parent> getParents(@Param("key") String key, @Param("childKey") String childKey);
@Select("select id, childName, childKey from child where parentId=#{parentId} and childKey = #{childKey}")
Child getChild(@Param("parentId")String parentId, @Param("childKey") String childKey);
}
如您所见,从逻辑上讲,我获取一个父级列表,然后发送两个参数:父级id childKey以获取子级。
但是如何使用@One注释实现这一点呢?。
必须在映射结果中同时指定这两列。
尽管它们使用XML,但在基于注释的映射中它可能是可转置的。虽然到目前为止我还没有做到。
无论如何,我不知道第二栏会是什么
此外,如果不使用延迟加载:@OnefetchType=FetchType.lazy,select=getChild,那么我看不到N+1选择的意义。
您最好使用SQL连接,并使用单个查询构建整个结构。。
必须在映射结果中同时指定这两列。
尽管它们使用XML,但在基于注释的映射中它可能是可转置的。虽然到目前为止我还没有做到。
无论如何,我不知道第二栏会是什么
此外,如果不使用延迟加载:@OnefetchType=FetchType.lazy,select=getChild,那么我看不到N+1选择的意义。
您最好使用SQL连接,并使用单个查询构建整个结构。代码段为false:embedded annotation为@Results,在@Result的每一行之间缺少逗号。代码段为false:embedded annotation为@Results,在@Result的每一行之间缺少逗号。