0%

mybatis | xml 的属性讲解

我们在定义 xml 的时候,经常这样定义。

column 和 property

1
2
3
4
5
6
7
8
9
10
<resultMap type="com.fate.backstage.entity.user.UserInfo" id="UserInfo">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="password" column="password"/>
<result property="nickName" column="nickName"/>
<result property="email" column="email"/>
<result property="token" column="token"/>
<result property="erc20_address" column="erc20_address"/>
<result property="create_time" column="create_time"/>
</resultMap>
  • column
    • 对应我们数据库表中的字段名称
  • property
    • 对应我们的实体类的属性,比如:User中的属性userName,要和数据库表m_user中的name对应

include 片段

1
2
3
<select id="selectAll" resultType="User">
select id,name as nickName,score,password from user;
</select>

可以改成

1
2
3
4
5
6
7
8
<sql id = "sql1">
id,name as nickName,score,password
</sql>
<select id="selectAll" resultType="User">
select
<include refid = "sql1"/>
from user;
</select>
请我喝杯咖啡吧~