diff --git a/src/main/java/com/lovenav/controller/CommentController.java b/src/main/java/com/lovenav/controller/CommentController.java index 261363b..c034345 100644 --- a/src/main/java/com/lovenav/controller/CommentController.java +++ b/src/main/java/com/lovenav/controller/CommentController.java @@ -1,23 +1,26 @@ package com.lovenav.controller; import com.lovenav.entity.Comment; +import com.lovenav.service.CommentService; import com.lovenav.service.serviceImpl.CommentServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpSession; + @RestController @RequestMapping("/comment") public class CommentController { @Autowired - private CommentServiceImpl commentServiceImpl; - @PostMapping(value= "/AddLikeCount",produces="application/json;charset=UTF-8") - public String AddLikeCount(@RequestBody Comment comment) { - return commentServiceImpl.AddLikeCount(comment); - } + private CommentService commentService; - @GetMapping("/hello") - public String he(){ - System.out.println("hello world"); - return "Hello world!"; +// @GetMapping(value= "/AddLikeCount") +// public String AddLikeCount_Controller(HttpSession session){ +// int id = (int) session.getAttribute("id"); +// return commentService.AddLikeCount(id); +// } + @GetMapping(value= "/AddLikeCount") + public String AddLikeCount(int id){ + return commentService.AddLikeCount(id); } } diff --git a/src/main/java/com/lovenav/dao/CommentDao.java b/src/main/java/com/lovenav/dao/CommentDao.java index 3fa5b00..911061b 100644 --- a/src/main/java/com/lovenav/dao/CommentDao.java +++ b/src/main/java/com/lovenav/dao/CommentDao.java @@ -1,11 +1,12 @@ package com.lovenav.dao; import com.lovenav.entity.Comment; +import org.apache.ibatis.annotations.Mapper; import org.mybatis.spring.annotation.MapperScan; import org.springframework.stereotype.Repository; @Repository - +@Mapper public interface CommentDao { int deleteByPrimaryKey(Integer id); diff --git a/src/main/java/com/lovenav/service/CommentService.java b/src/main/java/com/lovenav/service/CommentService.java index 22f9c12..e6d5912 100644 --- a/src/main/java/com/lovenav/service/CommentService.java +++ b/src/main/java/com/lovenav/service/CommentService.java @@ -1,8 +1,10 @@ package com.lovenav.service; import com.lovenav.entity.Comment; +import org.springframework.stereotype.Service; + public interface CommentService { // 点赞 - public String AddLikeCount(Comment comment); + public String AddLikeCount(int id); } diff --git a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java index 794ceb6..1eb272a 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java @@ -4,18 +4,21 @@ import com.alibaba.fastjson2.JSONObject; import com.lovenav.dao.CommentDao; import com.lovenav.entity.Comment; import com.lovenav.service.CommentService; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -@Service +@Service("commentService") public class CommentServiceImpl implements CommentService { - + @Autowired private CommentDao commentDao; // 点赞++ - public String AddLikeCount(Comment comment){ + @Override + public String AddLikeCount(int id){ + Comment comment = commentDao.selectByPrimaryKey(id); comment.setLikeCount(comment.getLikeCount()+1); - commentDao.updateByPrimaryKeySelective(comment); - return JSONObject.toJSONString(comment); + commentDao.updateByPrimaryKey(comment); + return JSONObject.toJSONString(comment.getLikeCount()); } }