发表于: 2019-11-12 23:14:38
1 1093
今天完成的事情:
今天把前台的自动获取ID加上。加的过程中发现了一个其他地方的BUG。BUG解决了,我也不想复现。
说下大概吧。
留言的查询接口,要查出这个留言对应的用户信息,所以是一对一查询,这个时候我们要加入用户类。查询完返回参数时,会带上各自的id,如果这个时候,在sql语句中没有做区分,这两个id的值会相等,比如用户1留言了,这个留言记录id是3,但是查询时没做区分,这两个id展示的数值是3.因为是根据留言查用户 。
所以要们在返回数据的时候,要把相同的字段名分开来
<resultMap id="BaseResultMap" type="com.happynewyear.admin.pojo.Comment">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="content" jdbcType="VARCHAR" property="content"/>
<result column="study_object_id" jdbcType="BIGINT" property="studyObjectId"/>
<result column="star" jdbcType="INTEGER" property="star"/>
<result column="like_count" jdbcType="INTEGER" property="likeCount"/>
<result column="create_at" jdbcType="BIGINT" property="createAt"/>
<result column="update_at" jdbcType="BIGINT" property="updateAt"/>
<result column="create_by" jdbcType="BIGINT" property="createBy"/>
<result column="update_by" jdbcType="BIGINT" property="updateBy"/>
<association property="user" column="userId" javaType="com.happynewyear.admin.pojo.User">
<id property="userId" column="user_id"/>
<result property="userName" column="user_name"/>
<result property="userImg" column="user_img"/>
<result property="userClass" column="user_class"/>
<result property="userTel" column="user_tel"/>
<result property="userMail" column="user_mail"/>
</association>
<association property="studyObject" column="id" javaType="com.happynewyear.admin.pojo.StudyObject">
<id property="id" column="oid"/>
<result property="type" column="type"/>
<result property="course" column="course"/>
</association>
</resultMap>
<!--列表查询留言表的留言与对应的用户信息-->
<select id="selectSelective" parameterType="com.happynewyear.admin.pojo.Comment" resultMap="BaseResultMap">
SELECT c.id,u.user_id,u.user_name,u.user_img,c.content,c.star,c.create_at,c.like_count,c.create_by,o.id as oid,o.type,o.course
FROM
`comment` as c ,`user` as u ,study_object as o
<trim prefix="WHERE" prefixOverrides="AND|OR ">
c.create_by = u.user_id
and c.study_object_id=o.id
<if test="id!=null">and c.id=#{id}</if>
<if test="user != null ">
<if test="user.userName != null and user.userName !=''">and u.user_name LIKE CONCAT('%',#{user.userName},'%')</if>
<if test="user.userClass != null and user.userClass !=0">and u.user_class= #{user.userClass}</if>
<if test="startTime != null and endTime != null ">and c.create_at between #{startTime} and #{endTime}</if>
</if>
</trim>
</select>
今天因为统计问题和pm师兄讨论了下,查看了一次学习对象,我们就增加一次浏览量,但是这个时候,我们把这个浏览记录删了,我们要不要把这个统计减去一个1,讨论结果是不要。浏览记录删除是用户的事,和学习对象无关,你看过一次,我浏览量加1,是没错的,不可能你删掉了记录就可以表示没看过。
所以不需要对统计减1.
现在又想了下,好像收藏和点赞是要进行增减的,我收藏了,又取消收藏了,这个收藏人数是确定的。比如第一个人点赞了,然后他又取消了,那点赞人数就是0。我晕,前面我把这代码删了,现在又要加回来了。
明天计划的事情:
遇到的问题:
mybatis一对一查询配置问题,统计方案没做好。不过做过一次就知道怎么做了。经验的重要性
收获:
评论