1.起别名
sql语句中加入as
id, brand_name as brandName, company_name as companyName, ordered, description, status
缺点:每次查询都要定义一次别名
可以通过sql片段解决
<sql id="brand_column">
id, brand_name as brandName, company_name as companyName, ordered, description, status
</sql>
<select id="selectAll" resultType="com.Arbiter.pojo.Brand">
select <include refid="brand_column"/>
from tb_brand;
</select>-->
2.使用<resultmap>
定义<resultMap>标签
<resultMap id="brandResultMap" type="com.Arbiter.pojo.Brand">
<!--
id:完成主键字段的映射
column:表的列名
property:实体类的属性名
result:完成一般字段的映射
column:表的列名
property:实体类的属性名
-->
<result column="brand_name" property="brandName" />
<result column="company_name" property="companyName" />
</resultMap>
在<select>标签中使用 result属性
<select id="selectAll" resultMap="brandResultMap">
select *
from tb_brand;
</select>