mybatis中映射配置文件mapper
1.导入约束
<?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">
2.namespace
<mapper namespace="com.demo.learnbatis.mapper.TeamMapper">
这里的namespace属性的值必须是mapper的全限定类名
3.写上自己要用的sql语句
<select id="findTeamByUserId" resultType="com.demo.learnbatis.entity.Team">
SELECT * FROM user_team
where
user_id=#{userId}
</select>
要注意的是这里面的id属性的取值必须是mapper接口中的方法名
4.设置封装
<resultMap id="BaseResultMap" type="com.demo.learnbatis.entity.Team">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<constructor>
<arg column="id" javaType="java.lang.String" jdbcType="CHAR" />
<arg column="user_id" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="team_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="avatar" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="compress_avatar" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="introduction" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>