Merge remote-tracking branch 'origin/master'

This commit is contained in:
2023-12-20 22:07:09 +08:00
7 changed files with 91 additions and 28 deletions

View File

@@ -1,22 +0,0 @@
package com.lovenav.controller;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import com.lovenav.service.serviceImpl.CommentServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CommentComtroller {
private CommentServiceImpl commentServiceImpl;
@PostMapping(value= "/AddLikeCount",produces="application/json;charset=UTF-8")
public int AddLikeCount(@RequestBody Comment comment) {
return commentServiceImpl.AddLikeCount(comment);
}
}

View File

@@ -0,0 +1,23 @@
package com.lovenav.controller;
import com.lovenav.entity.Comment;
import com.lovenav.service.serviceImpl.CommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@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);
}
@GetMapping("/hello")
public String he(){
System.out.println("hello world");
return "Hello world!";
}
}

View File

@@ -1,9 +1,11 @@
package com.lovenav.dao;
import com.lovenav.entity.Comment;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Repository;
@Repository
public interface CommentDao {
int deleteByPrimaryKey(Integer id);

View File

@@ -4,5 +4,5 @@ import com.lovenav.entity.Comment;
public interface CommentService {
// 点赞
public int AddLikeCount(Comment comment);
public String AddLikeCount(Comment comment);
}

View File

@@ -1,17 +1,21 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.CommentDao;
import com.lovenav.entity.Comment;
import com.lovenav.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CommentServiceImpl implements CommentService {
private CommentDao commentDao;
// 点赞++
public int AddLikeCount(Comment comment){
public String AddLikeCount(Comment comment){
comment.setLikeCount(comment.getLikeCount()+1);
return commentDao.updateByPrimaryKeySelective(comment);
commentDao.updateByPrimaryKeySelective(comment);
return JSONObject.toJSONString(comment);
}
}