这个项目 Dao 是单独一个项目,然后打成 jar 包添加到 maven。在后台项目里从 maven 引入的。
我想在 Dao 里加一个操作,但是就很简单的查询也会失败。
模仿的样例:
AppUserMapper.java
public interface AppUserMapper {
//......
AppUser selectByPrimaryKey(String id);
//......
}
AppUserMapper.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="XXX.dao.AppUserMapper">
<resultMap id="BaseResultMap" type="XXX.entity.AppUser">
<!--实体类映射-->
</resultMap>
<sql id="Base_Column_List">
<!--查询的值-->
</sql>
<!--省略-->
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from app_user
where id = #{id,jdbcType=VARCHAR}
</select>
<!--省略-->
</mapper>
自己写的:
GoodsOff.java
package XXX.entity;
import java.io.Serializable;
public class GoodsOff implements Serializable {
private int id;
private String goodsId;
private float off;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsId() {
return goodsId;
}
public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
}
public float getOff() {
return off;
}
public void setOff(float off) {
this.off = off;
}
}
GoodsOffMapper.java
package XXX.dao;
import XXX.entity.GoodsOff;
public interface GoodsOffMapper {
GoodsOff selectByPrimaryKey(String goodsId);
}
GoodsOffMapper.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="XXX.dao.GoodsOffMapper">
<resultMap id="BaseResultMap" type="XXX.entity.GoodsOff">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="goods_id" jdbcType="VARCHAR" property="goodsId" />
<result column="off" jdbcType="FLOAT" property="off" />
</resultMap>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
*
from hbmm_goodsoff
where goods_id = #{goodsId,jdbcType=VARCHAR}
</select>
</mapper>
我数据库里的表:
REATE TABLE `hbmm_goodsoff` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`goods_id` varchar(64) CHARACTER SET utf8mb4 DEFAULT NULL,
`off` float DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.