<resultMap type="com.tvjoy.btop.webapp.entity.User" id="queryUserList">
<!-- id:主键 column:表字段的名称或者别名 property:实体bean类里面对应的变量名称 (注:id这个标签一定需要有,其次才能写result标签)-->
<id column="id" property="id"/>
<!-- result:返回结果 column:表字段的名称或者别名 property:实体bean类里面对应的变量名称 jdbcType:数据库对应的字段类型 -->
<result column="userName" property="userName" jdbcType="VARCHAR"/>
<result column="age" property="age" jdbcType="VARCHAR"/>
<!--collection:多表查询时使用 property:实体bean类里面对应的变量名称 javaType:定义变量的类型 -->
<collection property="role" javaType="com.tvjoy.btop.webapp.entity.Role">
<id column="roleId" property="id"/>
<result column="roleName" property="roleName" jdbcType="VARCHAR"/>
<result column="userId" property="userId" jdbcType="VARCHAR"/>
</collection>
</resultMap>
<!-- select :查询语句 id:对应的maper接口的方法名称 parameterType:入参的类型 resultMap:返回的resultMap的ID-->
<select id="findUserRoleById" parameterType="int" resultMap="queryUserList">
select
u.user_id id,u.user_name userName,u.user_age age ,
r.id roleId,r.role_name roleName,r.user_Id userId
from
t_user u
left join
t_role r
on
u.user_id=r.id
</select>
<resultMap id="BaseResultMap" type="com.sica.domain.User">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="username" property="username" jdbcType="VARCHAR"/>
<result column="password" property="password" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, username, password
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
select
<include refid="Base_Column_List"/>
from user
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from user
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sica.domain.User">
insert into user (id, username, password
)
values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.sica.domain.User">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="username != null">
username,
</if>
<if test="password != null">
password,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="username != null">
#{username,jdbcType=VARCHAR},
</if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sica.domain.User">
update user
<set>
<if test="username != null">
username = #{username,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sica.domain.User">
update user
set username = #{username,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>