What should I do if the attribute name in the entity class is different from the field name in the table?

What should I do if the attribute name in the entity class is different from the field name in the table?

Type 1: By defining the alias of the field name in the query SQL statement, the alias of the field name is consistent with the attribute name of the entity class . Here are some inline code pieces.

<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>

Type 2: Through to map the one-to-one correspondence between field names and entity class attribute names

<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>

Guess you like

Origin blog.csdn.net/m0_51684972/article/details/110820808