字段与属性不匹配的解决方法

way1:sql语句中为字段起别名,别名与实体类名一致

1 <select id="getOrder2" parameterType="int" resultType="com.zhiyou.clg.bean.Order">
2           select order_id id,order_no no,order_price price from Orders where order_id=#{id}   
3 select>

way2:使用resultMap标签(属性:type、id)来定义实体类与字段之间的对应关系,其标签内包含标签id(主键)、标签result(普通字段,属性:column、property)

1 <select id="getOrder" resultMap="myMap">
2            select * from Orders where Order_id=#{id}   
3      select>
4      <resultMap type="com.zhiyou.clg.bean.Order" id="myMap">
5          <id column="order_id" property="id"/>
6          <result column="order_no" property="no"/>
7          <result column="order_price" property="price"/>
8      resultMap>    

 

转载于:https://www.cnblogs.com/lwgok1003/p/11442680.html

你可能感兴趣的:(字段与属性不匹配的解决方法)