对象:User
属性:userId
userName
password
name
age
mobile
表user_account
表user_info
一个User对象对应一条user_account中的userId,userName,password数据,对应三条user_info中的数据,分别是age,name,mobile根据userId关联。
此时是User获取到所有属性信息:
SELECT
userId,
userName,
password
,
(SELECT infoValue FROM user_info WHERE infoName = ‘age’ AND userId = 101) age,
(SELECT infoValue FROM user_info WHERE infoName = ‘name’ AND userId = 101) name,
(SELECT infoValue FROM user_info WHERE infoName = ‘mobile’ AND userId = 101) mobile
FROM
user_account
WHERE
userId = 101
在mybatis中101可以进行传参#{userId},即可达到效果,注意点:user_account中对应userId的信息是否存在决定了结果是否为null,user_info的数据存在与否不影响结果是否为null。