BrandMapper.xml中使用resultMap得到返回结果,解决数据库中的字段与pojo中的字段不匹配进行映射问题

发布时间 2023-09-02 12:19:08作者: 努力是一种常态
2023-09-02
<?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" >
<mapper namespace="com.hh.mapper.BrandMapper">

    <!--    得到返回结果,数据库中的字段与pojo中的字段不匹配进行映射-->
    <resultMap id="brandResult" type="brand">
        <result column="brand_name" property="brandName"/>
        <result column="company_name" property="companyName"/>
    </resultMap>

    <select id="selectAll" resultMap="brandResult">
        select * from tb_brand;
    </select>
</mapper>