问题描述
mapper.xml出现错误:Type handler was null on parameter mapping for property 'category'. It was either not specified and/or could not be found for the javaType (com.yykh.onemall.pojo.Category) : jdbcType (null) combination.
相关代码
mapper.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.yykh.onemall.mapper.ProductMapper">
<resultMap id="Product" type="com.yykh.onemall.pojo.Product">
<id column="id" property="id"/>
<result property="name" column="name"/>
<result property="subTitle" column="subTitle"/>
<result property="originalPrice" column="originalPrice"/>
<result property="promotePrice" column="promotePrice"/>
<result property="stock" column="stock"/>
<result property="createDate" column="createDate"/>
<association property="category" javaType="com.yykh.onemall.pojo.Category">
<id column="cid" property="id"/>
</association>
</resultMap>
<select id="findOne" resultMap="Product">
SELECT * from product where id =#{id}
</select>
<select id="findAll" resultMap="Product">
select * from product where cid =#{id}
</select>
</mapper>
pojo:
@Data
public class Product {
int id;
private Category category;
private String name;
private String subTitle;
private float originalPrice;
private float promotePrice;
private int stock;
private Date createDate;
}
mapper.interface:
public interface ProductMapper {
@Insert("insert into product(name,subTitle,originalPrice,promotePrice,stock,createDate,category) values(#{name},#{subTitle},#{originalPrice},#{promotePrice},#{stock},#{createDate},#{category}) ")
void save(Product bean);
@Delete("delete from product where id =#{id}")
void delete(int id);
Product findOne(int id);
Page<Product> findAll(Category category);
}
问题解决了。
出在了mapper.interface中。之前一直以为在mapper.xml中。
注意注解的SQL中,数据库的字段输入错误了,导致该错报。