修正comment,banner接口
This commit is contained in:
parent
39048bbcfc
commit
7d3f10a7dc
40
src/main/java/com/lovenav/controller/BannersController.java
Normal file
40
src/main/java/com/lovenav/controller/BannersController.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.lovenav.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.lovenav.entity.Banners;
|
||||
import com.lovenav.service.BannersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/banners")
|
||||
public class BannersController {
|
||||
@Autowired
|
||||
private BannersService bannersService;
|
||||
// 跳转链接
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/jump_url")
|
||||
public String jump(int id){
|
||||
return bannersService.Jump_url(id);
|
||||
}
|
||||
|
||||
// 添加banner
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/add_banner")
|
||||
public String add(@RequestBody Banners banners){
|
||||
return bannersService.Add_banner(banners);
|
||||
}
|
||||
|
||||
// 删除banner
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/delete_url")
|
||||
public String delete(int id){
|
||||
return bannersService.Delete_banner(id);
|
||||
}
|
||||
|
||||
// 首页显示banner
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/view_banner")
|
||||
public String view(){
|
||||
return bannersService.View_banner();
|
||||
}
|
||||
}
|
@ -21,15 +21,15 @@ public class CommentController {
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
// 评论功能
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/reply_comment")
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/comment")
|
||||
public String Reply1(@RequestBody Comment comment){
|
||||
return commentService.Reply1(comment);
|
||||
}
|
||||
|
||||
// 回复功能
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/comment")
|
||||
public String Reply2(@RequestBody Comment comment){
|
||||
return commentService.Reply2(comment);
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/reply_comment")
|
||||
public String Reply2(@RequestBody Comment comment,int id){
|
||||
return commentService.Reply2(comment,id);
|
||||
}
|
||||
// 删除功能
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/delete_comment")
|
||||
@ -40,4 +40,10 @@ public class CommentController {
|
||||
public String addLikeCount(int id){
|
||||
return commentService.AddLikeCount(id);
|
||||
}
|
||||
|
||||
// 显示评论
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/view_comment")
|
||||
public String View_comment(){
|
||||
return commentService.View_comment();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.lovenav.dao;
|
||||
|
||||
import com.lovenav.entity.Banners;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface BannersDao {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
@ -16,4 +20,6 @@ public interface BannersDao {
|
||||
int updateByPrimaryKeySelective(Banners record);
|
||||
|
||||
int updateByPrimaryKey(Banners record);
|
||||
|
||||
List<Banners> selectByAllBanners();
|
||||
}
|
@ -22,5 +22,5 @@ public interface CommentDao {
|
||||
|
||||
int updateByPrimaryKey(Comment record);
|
||||
|
||||
List<Integer> selectByRootId(Integer rootid);
|
||||
List<Comment> selectByAllComment();
|
||||
}
|
@ -2,6 +2,9 @@ package com.lovenav.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -9,6 +12,57 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class Banners implements Serializable {
|
||||
public Banners(){
|
||||
this.bannerStatus = 0;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getImgUrl() {
|
||||
return imgUrl;
|
||||
}
|
||||
|
||||
public void setImgUrl(String imgUrl) {
|
||||
this.imgUrl = imgUrl;
|
||||
}
|
||||
|
||||
public Integer getWeigh() {
|
||||
return weigh;
|
||||
}
|
||||
|
||||
public void setWeigh(Integer weigh) {
|
||||
this.weigh = weigh;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Byte getBannerStatus() {
|
||||
return bannerStatus;
|
||||
}
|
||||
|
||||
public void setBannerStatus(Byte bannerStatus) {
|
||||
this.bannerStatus = bannerStatus;
|
||||
}
|
||||
|
||||
public Date getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(Date createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
|
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);
|
||||
}
|
||||
}
|
||||
|
@ -95,4 +95,12 @@
|
||||
createtime = #{createtime,jdbcType=TIMESTAMP}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ln_banners
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -145,11 +145,13 @@
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<select id="selectByRootId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
|
||||
<select id="selectByAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
id
|
||||
*
|
||||
from ln_comment
|
||||
where root_comment_id = #{rootCommentId,jdbcType=INTEGER}
|
||||
where root_comment_id = 0 and comment_status = 0
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user