前言
上面表,下面实体类
数据库字段: | id | name_a | name_b | cid |
---|---|---|---|---|
实体类字段: | id | name1 | name2 | cid |
AS映射
AS可:小写&大写
sql标签
sql标签起个名字叫:test1
通过 <include refid="test1"></include>
引入
<sql id="test1">
id,name_a as name1,name_b AS name2,cid
</sql>
<select id="no1" resultType="com.zb.entity.No1">
select <include refid="test1"></include> from no1;
</select>
Map标签(常用)
将查询语句的返回类型改成:resultMap类型,值是起的id名字
resultMap参数讲解:
id | type | column | property |
---|---|---|---|
随便起的名字 | 返回数据类型 | 数据库字段 | 实体类字段 |
<resultMap id="test1" type="com.zb.entity.No1">
<result column="name_a" property="name1"></result>
<result column="name_b" property="name2"></result>
</resultMap>
<select id="no1" resultMap="test1">
select * from no1;
</select>
多表
请前往:https://www.0po.cn/archives/1