发表于: 2019-11-09 21:41:21

1 1042


今天完成的事情:

把前台的留言接口写了,要用到另一个组员的用户表信息。

xml映射文件和前面一样,把用户表的映射加进来。

 <resultMap id="BaseResultMap" type="com.happynewyear.user.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.user.pojo.User">
         <id property="userId" column="user_id"/>
         <result property="userName" column="user_name"/>
         <result property="userImg" column="user_img"/>
     </association>
 </resultMap>
 <!--查询留言关联对应用户信息-->
 <select id="selectSelective" parameterType="com.happynewyear.user.pojo.Comment" resultMap="BaseResultMap">
     SELECT c.id,u.user_name,u.user_img,c.content,c.star,c.create_at,c.like_count,u.create_by
FROM
`comment` as c ,`user` as u
WHERE
c.study_object_id=u.user_id=#{studyObjectId}
 </select>



private final Logger log = LogManager.getLogger(this.getClass());

@Autowired
CommentServer commentServer;
@Autowired
StudyObjectServer studyObjectServer;
/**
* 学习对象内的留言列表查看
*/
@GetMapping("/a/u/list/comment")
public Map<String, Object> commentListSelect(Long id,
                                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "size", defaultValue = "10") Integer size) {
   HashMap<String, Object> result = new HashMap<>(16);
   log.info("获取第{}页共{}行学习对象{}信息的评论列表", page, size, id);
   try {
       Comment comment = new Comment();
       comment.setStudyObjectId(id);
       PageHelper.startPage(page, size, "c.create_at desc");
       List commentList = commentServer.selectSelective(comment);
       PageInfo<Comment> pageInfo = new PageInfo<>(commentList);
       /*获取总数据量*/
       Long total = pageInfo.getTotal();
       result.put("code", SUCCESS.getCode());
       result.put("msg", SUCCESS.getMsg());
       result.put("total", total);
       result.put("data", commentList);
       return result;
   } catch (Exception e) {
       e.printStackTrace();
       result.put("code", REQUEST_FAILED.getCode());
       result.put("msg", REQUEST_FAILED.getMsg());
       return result;
   }
}

/**
* 留言新增
*/
@PostMapping("/a/u/comment")
public Map<String, Object> commentInsert(Long id,String content,int star) {
   HashMap<String, Object> result = new HashMap<>(16);
   try {
       Comment comment=new Comment();
       comment.setStudyObjectId(id);
       comment.setContent(content);
       comment.setStar(star);
       comment.setLikeCount(0);
       comment.setCreateBy(1L);
       comment.setUpdateBy(1L);
       int commentInsertSuccess=commentServer.insertSelective(comment);
       /*新增留言成功,对应学习对象留言统计加1*/
       if (commentInsertSuccess==1) {
           StudyObject studyObject=new StudyObject();
           studyObject.setId(id);
           studyObject.setCommentCount(1);
           studyObjectServer.updateCount(studyObject);
           result.put("code", SUCCESS.getCode());
           result.put("msg", SUCCESS.getMsg());
           result.put("id", comment.getId());
       }
       return result;
   }catch (Exception e) {
       e.printStackTrace();
       result.put("code", REQUEST_FAILED.getCode());
       result.put("msg", REQUEST_FAILED.getMsg());
       return result;
   }
}

/**
* 留言删除
*/
@DeleteMapping("/a/u/comment")
public Map<String, Object> commentDelete(Long id) {
   HashMap<String, Object> result = new HashMap<>(16);
   try {
       log.info("删除的留言id为:{}", id);
       commentServer.deleteByPrimaryKey(id);
       result.put("code", SUCCESS.getCode());
       result.put("msg", SUCCESS.getMsg());
       log.info("成功删除学习对象的对应id:{}", id);
       return result;
   } catch (Exception e) {
       e.printStackTrace();
       result.put("code", REQUEST_FAILED.getCode());
       result.put("msg", REQUEST_FAILED.getMsg());
       return result;
   }
}


明天计划的事情:

后台留言接口,,后台留言接口……如果根据用户名来查的话,要改用户表的映射了


遇到的问题:

玄学BUG,用到user表时,在映射文件里一直报红,,怎么也解决不了,后面又从SVN上拉了一次就行了??明明什么都没更新!


收获:



返回列表 返回列表
评论

    分享到