修正comment,banner接口
This commit is contained in:
14
src/main/java/com/lovenav/service/BannersService.java
Normal file
14
src/main/java/com/lovenav/service/BannersService.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.lovenav.service;
|
||||
|
||||
import com.lovenav.entity.Banners;
|
||||
|
||||
public interface BannersService {
|
||||
// 跳转链接
|
||||
String Jump_url(int id);
|
||||
// 添加banner
|
||||
String Add_banner(Banners banners);
|
||||
// 删除banner
|
||||
String Delete_banner(int id);
|
||||
// 展示banner
|
||||
String View_banner();
|
||||
}
|
@@ -10,7 +10,9 @@ public interface CommentService {
|
||||
// 评论
|
||||
String Reply1(Comment comment);
|
||||
// 回复
|
||||
String Reply2(Comment comment);
|
||||
String Reply2(Comment comment,int id);
|
||||
// 删除
|
||||
String Delete(int id);
|
||||
// 显示评论
|
||||
String View_comment();
|
||||
}
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package com.lovenav.service.serviceImpl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.lovenav.dao.BannersDao;
|
||||
import com.lovenav.entity.Banners;
|
||||
import com.lovenav.service.BannersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class BannersServiceImpl implements BannersService {
|
||||
@Autowired
|
||||
private BannersDao bannersDao;
|
||||
|
||||
// 跳转链接
|
||||
@Override
|
||||
public String Jump_url(int id){
|
||||
Banners banners = bannersDao.selectByPrimaryKey(id);
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
if(banners != null){
|
||||
hashMap.put("url",banners.getUrl());
|
||||
}else{
|
||||
hashMap.put("code",500);
|
||||
hashMap.put("msg","找不到指定链接");
|
||||
}
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
|
||||
// 添加banner
|
||||
@Override
|
||||
public String Add_banner(Banners banners) {
|
||||
int result = bannersDao.insert(banners);
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
if(result>0){
|
||||
return JSON.toJSONString(banners);
|
||||
}else{
|
||||
hashMap.put("code",500);
|
||||
hashMap.put("msg","添加banner失败");
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除banner
|
||||
@Override
|
||||
public String Delete_banner(int id){
|
||||
int result = bannersDao.deleteByPrimaryKey(id);
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
if(result>0){
|
||||
hashMap.put("code",200);
|
||||
hashMap.put("msg","删除成功");
|
||||
return JSON.toJSONString(hashMap);
|
||||
}else{
|
||||
hashMap.put("code",500);
|
||||
hashMap.put("msg","删除失败");
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
}
|
||||
|
||||
// 展示banner
|
||||
@Override
|
||||
public String View_banner(){
|
||||
List<Banners> list = bannersDao.selectByAllBanners();
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package com.lovenav.service.serviceImpl;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.lovenav.dao.CommentDao;
|
||||
import com.lovenav.dao.UserDao;
|
||||
import com.lovenav.entity.Comment;
|
||||
import com.lovenav.service.CommentService;
|
||||
import org.apache.ibatis.jdbc.Null;
|
||||
@@ -13,10 +14,12 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Service("commentService")
|
||||
@Service
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
@Autowired
|
||||
private CommentDao commentDao;
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
// 评论功能
|
||||
@Override
|
||||
public String Reply1(Comment comment){
|
||||
@@ -32,18 +35,11 @@ public class CommentServiceImpl implements CommentService {
|
||||
}
|
||||
// 回复功能
|
||||
@Override
|
||||
public String Reply2(Comment comment){
|
||||
List<Integer> list = commentDao.selectByRootId(comment.getRootCommentId());
|
||||
if(list.size()<5){
|
||||
commentDao.insert(comment);
|
||||
return JSON.toJSONString(comment);
|
||||
}else{
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
result.put("code", 500);
|
||||
result.put("msg", "回复超过上限");
|
||||
String jsonString = JSONObject.toJSONString(result);
|
||||
return JSON.toJSONString(result);
|
||||
}
|
||||
public String Reply2(Comment comment,int id){
|
||||
String name = (userDao.selectByPrimaryKey(id)).getNickname();
|
||||
HashMap<Comment,String> hashMap = new HashMap<>();
|
||||
hashMap.put(comment, name);
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
// 删除
|
||||
@Override
|
||||
@@ -67,7 +63,13 @@ public class CommentServiceImpl implements CommentService {
|
||||
comment.setLikeCount(comment.getLikeCount()+1);
|
||||
commentDao.updateByPrimaryKeySelective(comment);
|
||||
HashMap<String, Long> hashMap = new HashMap<>();
|
||||
hashMap.put("点赞成功:",comment.getLikeCount());
|
||||
hashMap.put("点赞成功",comment.getLikeCount());
|
||||
return JSON.toJSONString(hashMap);
|
||||
}
|
||||
|
||||
// 显示评论
|
||||
public String View_comment(){
|
||||
List<Comment> list = commentDao.selectByAllComment();
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user