点赞++2
This commit is contained in:
parent
c1ae7cb7bc
commit
1399bfd1e5
@ -1,23 +1,26 @@
|
|||||||
package com.lovenav.controller;
|
package com.lovenav.controller;
|
||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
|
import com.lovenav.service.CommentService;
|
||||||
import com.lovenav.service.serviceImpl.CommentServiceImpl;
|
import com.lovenav.service.serviceImpl.CommentServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/comment")
|
@RequestMapping("/comment")
|
||||||
public class CommentController {
|
public class CommentController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommentServiceImpl commentServiceImpl;
|
private CommentService commentService;
|
||||||
@PostMapping(value= "/AddLikeCount",produces="application/json;charset=UTF-8")
|
|
||||||
public String AddLikeCount(@RequestBody Comment comment) {
|
|
||||||
return commentServiceImpl.AddLikeCount(comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/hello")
|
// @GetMapping(value= "/AddLikeCount")
|
||||||
public String he(){
|
// public String AddLikeCount_Controller(HttpSession session){
|
||||||
System.out.println("hello world");
|
// int id = (int) session.getAttribute("id");
|
||||||
return "Hello world!";
|
// return commentService.AddLikeCount(id);
|
||||||
|
// }
|
||||||
|
@GetMapping(value= "/AddLikeCount")
|
||||||
|
public String AddLikeCount(int id){
|
||||||
|
return commentService.AddLikeCount(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@Mapper
|
||||||
public interface CommentDao {
|
public interface CommentDao {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package com.lovenav.service;
|
package com.lovenav.service;
|
||||||
|
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
public interface CommentService {
|
public interface CommentService {
|
||||||
// 点赞
|
// 点赞
|
||||||
public String AddLikeCount(Comment comment);
|
public String AddLikeCount(int id);
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,21 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.lovenav.dao.CommentDao;
|
import com.lovenav.dao.CommentDao;
|
||||||
import com.lovenav.entity.Comment;
|
import com.lovenav.entity.Comment;
|
||||||
import com.lovenav.service.CommentService;
|
import com.lovenav.service.CommentService;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service("commentService")
|
||||||
public class CommentServiceImpl implements CommentService {
|
public class CommentServiceImpl implements CommentService {
|
||||||
|
@Autowired
|
||||||
private CommentDao commentDao;
|
private CommentDao commentDao;
|
||||||
|
|
||||||
// 点赞++
|
// 点赞++
|
||||||
public String AddLikeCount(Comment comment){
|
@Override
|
||||||
|
public String AddLikeCount(int id){
|
||||||
|
Comment comment = commentDao.selectByPrimaryKey(id);
|
||||||
comment.setLikeCount(comment.getLikeCount()+1);
|
comment.setLikeCount(comment.getLikeCount()+1);
|
||||||
commentDao.updateByPrimaryKeySelective(comment);
|
commentDao.updateByPrimaryKey(comment);
|
||||||
return JSONObject.toJSONString(comment);
|
return JSONObject.toJSONString(comment.getLikeCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user