mybatis使用注解进行关联查询时,需要使用@results手动配置结果映射
一对一关联查询:使用@one(一对多关联查询:使用@many)
- package com.zwk.dao;
-
- import com.zwk.domain.User;
- import com.zwk.domain.UserInfo;
- import org.apache.ibatis.annotations.*;
-
- import java.util.List;
-
-
-
-
- public interface UserInfoDAO {
-
- @Select("select * from test_userinfo where id =#{id}")
- public UserInfo getUserInfoById(@Param("id") String id);
-
-
- @Select("select * from test_user u where u.id = #{id}")
- @Results({
- @Result(id = true,property = "id" ,column = "id"),
- @Result(property ="password",column = "password"),
- @Result(property ="userInfo",column="info_id"
- ,one =@One(select ="com.zwk.dao.UserInfoDAO.getUserInfoById"))}
- )
- public User getById(@Param("id") String id);
- }