zoukankan      html  css  js  c++  java
  • 当实体类中的属性名和表中的字段名不一样 ,怎么办 ?

    1 种: 通过在查询的 sql 语句中定义字段名的别名,让字段名的别名和实体类

    的属性名一致。

    35 页 共 485 页<select id=”selectorder” parametertype=”int” resultetype=”

    me.gacl.domain.order”>

    select order_id id, order_no orderno ,order_price price form

    orders where order_id=#{id};

    </select>

    2 种: 通过<resultMap>来映射字段名和实体类属性名的一一对应的关系。

    <select id="getOrder" parameterType="int"

    resultMap="orderresultmap">

    select * from orders where order_id=#{id}

    </select>

    <resultMap type=”me.gacl.domain.order” id=”orderresultmap”>

    <!–用 id 属性来映射主键字段–>

    <id property=”id” column=”order_id”>

    <!–用 result 属性来映射非主键字段,property 为实体类属性名,column

    为数据表中的属性–>

    <result property = “orderno” column =”order_no”/>

    <result property=”price” column=”order_price” />

    </reslutMap>

  • 相关阅读:
    chapter4.6生成器
    chapter4.4、递归
    chapter4.3、函数执行流程
    chapter4.2、函数返回值
    直接插入排序
    打印三角型的练习
    杂记
    linux top命令
    makefile 中的 := , += ,?=
    makefile中的shell语法 || Makefile中的@
  • 原文地址:https://www.cnblogs.com/programb/p/12686982.html
Copyright © 2011-2022 走看看