当数据库查询的字段和POJO中的属性名不一致时,可以自定义结果集。使用resultMap

 <!--type 指定返回的指定类型的全类名,id是该resultMap的唯一标识-->
<resultMap type="com.neuedu.bean.tbl_employee" >
<!-- id 标签 用于指定该类中主键属性,
    resultMap用于类的普通属性
    column用于指定数据库中获取的字段,如果字段是有别名,就写别名
    property用于指定POJO中属性。
--> <id column="id" property="id" /> <result column="email" property="email" /> <result column="gender" property="gender" /> <result column="user_name" property="userName" /> <result column="d_id" property="dId"/> </resultMap>
<!-- 这里不再使用resultType,而是使用resultMap,resultMap指定我们上面创建的resultMap的id-->
<
select id="selectDepartment" resultType="findTblEmployeeByIdMap">
    select * from tbl_dept where id=#{id}
 
</select>

 

相关文章:

  • 2022-12-23
  • 2021-04-06
  • 2022-12-23
  • 2021-12-02
  • 2021-10-29
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案