这个项目 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;
1
xiaoxinshiwo 2018-10-30 14:10:18 +08:00
报错信息贴一下啊大胸弟
|
2
Starry 2018-10-30 14:10:38 +08:00
是不是包名路径不一样,自动扫描扫不到你的 DAO 和 XML 文件
|
3
ukipoi OP @xiaoxinshiwo
不好意思,错误信息是下面这样的</br> ```error 十月 30, 2018 2:22:44 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [mvc] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bar.hbmm_goodsoff' doesn't exist ### The error may exist in class path resource [com/youzhuo/bar/mapping/mybatis/GoodsOffMapper.xml] ### The error may involve com.youzhuo.bar.dao.mybatis.GoodsOffMapper.selectByPrimaryKey-Inline ### The error occurred while setting parameters ### SQL: select * from hbmm_goodsoff where goods_id = ? ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bar.hbmm_goodsoff' doesn't exist ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bar.hbmm_goodsoff' doesn't exist] with root cause com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bar.hbmm_goodsoff' doesn't exist ``` |
4
gejun123456 2018-10-30 14:32:08 +08:00
不是表不存在么,数据库连接问题? 连到你设置的数据库去看看吧
|
5
ukipoi OP |
6
519718366 2018-10-30 14:44:02 +08:00
bar 库下面有这个 hbmm_goodsoff 表?要么你连到其他库去了,要么就是名字打错了什么的?
|
7
xiaoxinshiwo 2018-10-30 15:13:49 +08:00
@ukipoi #5 所以发贴记得贴异常啊
|