1、数据库中表的设计
2、实体类
public class Goods {
private int id;
private String dsp;
private double cp;
private double op;
3、mapper映射文件
<select id="selectGoods" resultType="cn.ll.entity.Goods">
select * from theme where id = #{id}
</select>
4、解决数据库字段名和实体类属性名不一致的问题
- 为字段名指定别名,别名与实体类属性名一致
<select id="selectGoods" resultType="cn.ll.entity.Goods">
select id id,description dsp,current_price cp,original_price op from theme where id = #{id}
</select>
- 设置结果映射类型
<select id="selectGoods" resultMap="GoodsMap">
select * from theme where id = #{id}
</select>
<resultMap id="GoodsMap" type="Goods">
<id column="id" property="id"/>
<result column="description" property="dsp"/>
<result column="current_price" property="cp"/>
<result column="original_price" property="op"/>
</resultMap>
column为数据库中字段名,property为实体类属性名,两者形成映射关系,一一对应