案例代码:本地下载
数据库脚本:本地下载
1.创建实体类
Goods.java
package com.bean;
public class Goods {
private Integer goodsId;
private String goodsName;
private Double goodsPrice;
private Integer goodsNum;
private Integer goodsType;
public Goods() {
}
public Goods(Integer goodsId, String goodsName, Double goodsPrice,
Integer goodsNum, Integer goodsType) {
super();
this.goodsId = goodsId;
this.goodsName = goodsName;
this.goodsPrice = goodsPrice;
this.goodsNum = goodsNum;
this.goodsType = goodsType;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public Double getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(Double goodsPrice) {
this.goodsPrice = goodsPrice;
}
public Integer getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(Integer goodsNum) {
this.goodsNum = goodsNum;
}
public Integer getGoodsType() {
return goodsType;
}
public void setGoodsType(Integer goodsType) {
this.goodsType = goodsType;
}
@Override
public String toString() {
return "Goods [goodsId=" + goodsId + ", goodsName=" + goodsName
+ ", goodsPrice=" + goodsPrice + ", goodsNum=" + goodsNum
+ ", goodsType=" + goodsType + "]";
}
}
2.对应的xml文件
重点修改处
Goods.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bean.Goods">
<select id="findAll" resultMap="resultGoods">
select * from goods
</select>
<resultMap type="com.bean.Goods" id="resultGoods">
<id property="goodsId" column="goods_id" javaType="int" />
<result property="goodsName" column="goods_name" javaType="java.lang.String" />
<result property="goodsPrice" column="goods_price" javaType="java.lang.Double" />
<result property="goodsNum" column="goods_num" javaType="int" />
<result property="goodsType" column="goods_type" javaType="int" />
</resultMap>
</mapper>
3.在mybatis.xml注册Goods.xml
mybatis.xml
<mapper resource="com/bean/Goods.xml" />
评论