Compare commits
1 Commits
7331553528
...
fearure-No
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
205f347d08 |
11
pom.xml
11
pom.xml
@@ -19,13 +19,6 @@
|
|||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis</groupId>
|
|
||||||
<artifactId>mybatis</artifactId>
|
|
||||||
<version>3.5.10</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@@ -130,8 +123,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>9</source>
|
<source>1.8</source>
|
||||||
<target>9</target>
|
<target>1.8</target>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.bao.dating.common;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 评论表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Comments {
|
|
||||||
private Long comment_id; // 评论ID
|
|
||||||
private String content; // 评论内容
|
|
||||||
private Long user_id; // 评论人ID
|
|
||||||
private Long post_id; // 关联动态ID
|
|
||||||
private LocalDateTime created_at; // 评论时间
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.bao.dating.common;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
/**
|
|
||||||
* 动态表
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Post {
|
|
||||||
private Long post_id; // 动态ID
|
|
||||||
private String content; // 动态内容
|
|
||||||
private Long user_id; // 发布人ID
|
|
||||||
private LocalDateTime created_at; // 创建时间
|
|
||||||
}
|
|
||||||
@@ -8,8 +8,7 @@ public enum ResultCode {
|
|||||||
UNAUTHORIZED(401, "未登录或 Token 失效"),
|
UNAUTHORIZED(401, "未登录或 Token 失效"),
|
||||||
FORBIDDEN(403, "无权限"),
|
FORBIDDEN(403, "无权限"),
|
||||||
NOT_FOUND(404, "数据不存在"),
|
NOT_FOUND(404, "数据不存在"),
|
||||||
SYSTEM_ERROR(500, "系统异常"),
|
SYSTEM_ERROR(500, "系统异常");
|
||||||
FAIL(500, "操作失败");
|
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
private final String msg;
|
private final String msg;
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
import com.bao.dating.common.Comments;
|
|
||||||
import com.bao.dating.common.Result;
|
|
||||||
import com.bao.dating.common.ResultCode;
|
|
||||||
import com.bao.dating.service.CommentsService;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/comments")
|
|
||||||
@CrossOrigin
|
|
||||||
public class CommentController {
|
|
||||||
@Resource
|
|
||||||
private CommentsService commentsService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加评论
|
|
||||||
* @param comment 评论对象(含content、userId、dynamicId)
|
|
||||||
*/
|
|
||||||
@PostMapping("/add")
|
|
||||||
public Result<String> addComment(@RequestBody Comments comment) {
|
|
||||||
boolean success = commentsService.addComment(comment);
|
|
||||||
return success ?
|
|
||||||
Result.success(ResultCode.SUCCESS, "评论成功") :
|
|
||||||
Result.error(ResultCode.FAIL, "评论失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除评论
|
|
||||||
* @param user_id 评论ID
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/delete/{user_id}")
|
|
||||||
public Result<String> deleteComment(@PathVariable Long user_id) {
|
|
||||||
boolean success = commentsService.deleteComment(user_id);
|
|
||||||
return success ?
|
|
||||||
Result.success(ResultCode.SUCCESS, "删除成功") :
|
|
||||||
Result.error(ResultCode.FAIL, "删除失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据动态ID查询评论列表
|
|
||||||
* @param post_id 动态ID
|
|
||||||
*/
|
|
||||||
@GetMapping("/list/{post_id}")
|
|
||||||
public Result<List<Comments>> getCommentList(@PathVariable Long post_id) {
|
|
||||||
List<Comments> commentList = commentsService.getCommentByPostId(post_id);
|
|
||||||
return Result.success(ResultCode.SUCCESS, commentList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.bao.dating.controller;
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.entity.Notice;
|
||||||
|
import com.bao.dating.service.NoticeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/notice")
|
||||||
|
public class NoticeController {
|
||||||
|
@Autowired
|
||||||
|
private NoticeService noticeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有公告数据
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public List<Notice> getNoticeList() {
|
||||||
|
return noticeService.getNoticeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有公告数据
|
||||||
|
* @return true=有数据 false=无数据
|
||||||
|
*/
|
||||||
|
@GetMapping("/hasData")
|
||||||
|
public boolean hasNoticeData() {
|
||||||
|
List<Notice> noticeList = noticeService.getNoticeList();
|
||||||
|
return !noticeList.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/main/java/com/bao/dating/controller/text.java
Normal file
4
src/main/java/com/bao/dating/controller/text.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package com.bao.dating.controller;
|
||||||
|
|
||||||
|
public class text {
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.bao.dating.mapper;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.common.Comments;
|
|
||||||
import com.bao.dating.common.Post;
|
|
||||||
import org.apache.ibatis.annotations.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface CommentsMapper {
|
|
||||||
// 添加评论
|
|
||||||
@Insert("INSERT INTO comments(content, user_id, post_id, created_at) VALUES(#{content}, #{user_id}, #{post_id}, #{created_at})")
|
|
||||||
int addComment(Comments comments);
|
|
||||||
|
|
||||||
// 删除评论
|
|
||||||
@Delete("DELETE FROM comments WHERE user_id = #{user_id}")
|
|
||||||
int deleteComments(@Param("user_id") Long user_id);
|
|
||||||
|
|
||||||
// 根据动态ID查询评论列表
|
|
||||||
@Select("SELECT * FROM comments WHERE post_id = #{post_id} ORDER BY created_at DESC")
|
|
||||||
List<Comments> getCommentsByPostId(@Param("post_id") Long post_id);
|
|
||||||
}
|
|
||||||
16
src/main/java/com/bao/dating/mapper/NoticeMapper.java
Normal file
16
src/main/java/com/bao/dating/mapper/NoticeMapper.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.entity.Notice;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告Mapper接口
|
||||||
|
*/
|
||||||
|
public interface NoticeMapper {
|
||||||
|
/**
|
||||||
|
* 查询所有公告
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
|
List<Notice> selectNoticeList();
|
||||||
|
}
|
||||||
40
src/main/java/com/bao/dating/pojo/entity/Notice.java
Normal file
40
src/main/java/com/bao/dating/pojo/entity/Notice.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.bao.dating.pojo.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Notice {
|
||||||
|
/**
|
||||||
|
* 公告ID
|
||||||
|
*/
|
||||||
|
private Long noticeId;
|
||||||
|
/**
|
||||||
|
* 公告标题
|
||||||
|
*/
|
||||||
|
private String noticeTitle;
|
||||||
|
/**
|
||||||
|
* 公告内容
|
||||||
|
*/
|
||||||
|
private String noticeContent;
|
||||||
|
/**
|
||||||
|
* 状态(0正常 1关闭)
|
||||||
|
*/
|
||||||
|
private String noticeStatus;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.bao.dating.service;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.common.Comments;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface CommentsService{
|
|
||||||
// 添加评论
|
|
||||||
boolean addComment(Comments comments);
|
|
||||||
|
|
||||||
// 删除评论
|
|
||||||
boolean deleteComment(Long user_id);
|
|
||||||
|
|
||||||
// 根据动态ID查询评论
|
|
||||||
List<Comments> getCommentByPostId(Long post_id);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
16
src/main/java/com/bao/dating/service/NoticeService.java
Normal file
16
src/main/java/com/bao/dating/service/NoticeService.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.bao.dating.service;
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.entity.Notice;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告服务接口
|
||||||
|
*/
|
||||||
|
public interface NoticeService {
|
||||||
|
/**
|
||||||
|
* 查询所有公告
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
|
List<Notice> getNoticeList();
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.bao.dating.service.impl;
|
|
||||||
|
|
||||||
import com.bao.dating.common.Comments;
|
|
||||||
|
|
||||||
import com.bao.dating.mapper.CommentsMapper;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.service.CommentsService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CommentsServiceImpl implements CommentsService {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CommentsMapper commentsMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addComment(Comments comments) {
|
|
||||||
// 设置创建时间
|
|
||||||
comments.setCreated_at(LocalDateTime.now());
|
|
||||||
return commentsMapper.addComment(comments) > 0;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean deleteComment(Long user_id) {
|
|
||||||
return commentsMapper.deleteComments(user_id) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Comments> getCommentByPostId(Long post_id) {
|
|
||||||
return commentsMapper.getCommentsByPostId(post_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bao.dating.service.impl;
|
||||||
|
|
||||||
|
import com.bao.dating.mapper.NoticeMapper;
|
||||||
|
import com.bao.dating.pojo.entity.Notice;
|
||||||
|
import com.bao.dating.service.NoticeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
@Service
|
||||||
|
public class NoticeServiceImpl implements NoticeService {
|
||||||
|
@Autowired
|
||||||
|
private NoticeMapper noticeMapper;
|
||||||
|
@Override
|
||||||
|
public List<Notice> getNoticeList() {
|
||||||
|
return noticeMapper.selectNoticeList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -166,7 +166,7 @@ public class PostServiceImpl implements PostService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deletePostById(Integer postId) {
|
public void deletePostById(Integer postId) {
|
||||||
postMapper.deletePostById(Long.valueOf(postId));
|
postMapper.deletePostById(postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
20
src/main/resources/com/bao/dating/mapper/NoticeMapper.xml
Normal file
20
src/main/resources/com/bao/dating/mapper/NoticeMapper.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bao.dating.mapper.NoticeMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询结果列 -->
|
||||||
|
<sql id="Notice_Column_List">
|
||||||
|
notice_id, notice_title, notice_content, notice_status, create_time, update_time
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- 查询所有公告 -->
|
||||||
|
<select id="selectNoticeList" resultType="com.bao.dating.pojo.entity.Notice">
|
||||||
|
select
|
||||||
|
<include refid="Notice_Column_List"/>
|
||||||
|
from sys_notice
|
||||||
|
where notice_status = '0'
|
||||||
|
order by create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user