Mybatis关联
Posted hoje
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis关联相关的知识,希望对你有一定的参考价值。
mybatis关联
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.o2o.dao.LocalAuthDao"> <resultMap id="localAuthResultMap" type="com.imooc.o2o.entity.LocalAuth"> <id column="local_auth_id" property="localAuthId" /> <result column="username" property="username" /> <result column="password" property="password" /> <result column="create_time" property="createTime" /> <result column="last_edit_time" property="lastEditTime" /> <association property="personInfo" column="user_id" javaType="com.imooc.o2o.entity.PersonInfo"> <id column="user_id" property="userId" /> <result column="name" property="name" /> <result column="gender" property="gender" /> <result column="email" property="email" /> <result column="profile_img" property="profileImg" /> <result column="user_type" property="userType" /> <result column="create_time" property="createTime" /> <result column="last_edit_time" property="lastEditTime" /> <result column="enable_status" property="enableStatus" /> </association> </resultMap> <select id="queryLocalByUserNameAndPwd" resultMap="localAuthResultMap" parameterType="String"> SELECT l.local_auth_id, l.username, l.password, l.create_time, l.last_edit_time, p.user_id, p.name, p.gender, p.email, p.profile_img, p.user_type, p.create_time, p.last_edit_time, p.enable_status FROM tb_local_auth l LEFT JOIN tb_person_info p ON l.user_id = p.user_id WHERE l.username = #{username} AND l.password = #{password} </select> </mapper>
以上是关于Mybatis关联的主要内容,如果未能解决你的问题,请参考以下文章
MyBatis关联查询,表字段相同,resultMap映射问题的解决办法