1、ibatis.binding.BindingException: Parameter 'userNo' not found
解决办法:加 @Param("userNo")
List<TimeSpread> selectToday(@Param("userNo")String userNo,@Param("today")String today);
2、jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.beauty.time.dto
在类上加这个注释
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
3、一个mapper.xml文件有两个resultMap的使用方法
<?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.beauty.time.dao.TimeManageMapper">
<resultMap id="BaseResultMap" type="com.beauty.time.entity.TimeManage">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="item_id" jdbcType="BIGINT" property="itemId" />
<result column="user_no" jdbcType="VARCHAR" property="userNo" />
<result column="start_time" jdbcType="VARCHAR" property="startTime" />
<result column="end_time" jdbcType="VARCHAR" property="endTime" />
<result column="duration" jdbcType="VARCHAR" property="duration" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, item_id, user_no, start_time, end_time, duration, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from timemanage
where id = #{id,jdbcType=BIGINT}
</select>
<resultMap id="TiemSpreadResultMap" type="com.beauty.time.dto.TimeSpread">
<result column="duration" jdbcType="BIGINT" property="duration" />
<result column="item_name" jdbcType="VARCHAR" property="actionType" />
</resultMap>
<select id="selectToday" resultMap="TiemSpreadResultMap">
select sum(a.duration) as duration,b.item_name from timemanage a,item b where a.user_no ='${userNo}' and a.create_time like '${today}%' and a.item_id =b.id group by a.item_id;
</select>
</mapper>
4、接口返回的data是对象数组,例如返回2个对象,但一直都是空值
{
"data": [
{},
{}
],
"status": "0",
"message": null,
"time": 1611023850825
}
两个空值,表示对象两个已经拿到,但为什么没有输出来,可能是数据库字段和对象字段没有对齐,我debug了一下,对象都有的,但没有显示值,那判断可能是对象类没有get方法,给对象类加上@Data(import lombok.Data;)注释就拿到具体值了
{
"data": [
{
"actionType": "娱乐",
"duration": 167
},
{
"actionType": "健身",
"duration": 62
}
],
"status": "0",
"message": null,
"time": 1611023850825
}