后端项目初始化,增加AOP切面校验,实体类,Controller,Service,Mapper

main
会飞的鱼 4 days ago
parent 48ad7bfe3f
commit aba38ceb3b

1
.gitignore vendored

@ -1,2 +1,3 @@
/.idea/
/src/FishPics-backend/target/
/src/FishPics-backend/.idea/

@ -1 +0,0 @@
Subproject commit 889c294b976edba8196e2fdf3c63ed57df67fb00

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hk.ljx</groupId>
<artifactId>FishPics-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FishPics-backend</name>
<description>FishPics-backend</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.7.6</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://baomidou.com/ -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.15</version>
</dependency>
<!-- https://doc.hutool.cn/ -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.38</version>
</dependency>
<!-- https://doc.xiaominfo.com/ -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>hk.ljx.fishpicsbackend.FishPicsBackendApplication</mainClass>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,15 @@
package hk.ljx.fishpicsbackend;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("hk.ljx.fishpicsbackend.mapper")
public class FishPicsBackendApplication {
public static void main(String[] args) {
SpringApplication.run(FishPicsBackendApplication.class, args);
}
}

@ -0,0 +1,12 @@
package hk.ljx.fishpicsbackend.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface AuthCheck {
// 权限
String role() default "";
}

@ -0,0 +1,56 @@
package hk.ljx.fishpicsbackend.common.aop;
import hk.ljx.fishpicsbackend.common.annotation.AuthCheck;
import hk.ljx.fishpicsbackend.common.exception.BaseException;
import hk.ljx.fishpicsbackend.common.exception.ExcUtils;
import hk.ljx.fishpicsbackend.common.exception.ExceptionCode;
import hk.ljx.fishpicsbackend.entity.User;
import hk.ljx.fishpicsbackend.enums.UserRoleEnum;
import hk.ljx.fishpicsbackend.service.UserService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Aspect
@Component
public class AuthInterceptor {
@Resource
private UserService userService;
/**
*
*
* @param joinPoint
* @param authCheck
*/
@Around("@annotation(authCheck)")
public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable {
String mustRole = authCheck.role();
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
// 当前登录用户
User loginUser = userService.getLoginUser(request);
UserRoleEnum mustRoleEnum = UserRoleEnum.getEnumByRole(mustRole);
// 不需要权限,放行
if (mustRoleEnum == null) {
return joinPoint.proceed();
}
// 以下为:必须有该权限才通过
// 获取当前用户具有的权限
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByRole(loginUser.getRole());
// 没有权限,拒绝
ExcUtils.throwIfTrue(userRoleEnum == null, ExceptionCode.UNAUTHORIZED);
// 要求必须有管理员权限,但用户没有管理员权限,拒绝
ExcUtils.throwIfTrue(UserRoleEnum.ADMIN.equals(mustRoleEnum) && !UserRoleEnum.ADMIN.equals(userRoleEnum), ExceptionCode.UNAUTHORIZED);
// 通过权限校验,放行
return joinPoint.proceed();
}
}

@ -0,0 +1,22 @@
package hk.ljx.fishpicsbackend.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 覆盖所有请求
registry.addMapping("/**")
// 允许发送 Cookie
.allowCredentials(true)
// 放行哪些域名(必须用 patterns否则 * 会和 allowCredentials 冲突)
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("*");
}
}

@ -0,0 +1,9 @@
package hk.ljx.fishpicsbackend.common.constants;
public interface UserConstants {
// 登录类
String LOGIN_SUCCESS = "登录成功";
String LOGIN_FAIL = "登录失败";
String LOGOUT_SUCCESS = "登出成功";
}

@ -0,0 +1,17 @@
package hk.ljx.fishpicsbackend.common.exception;
import lombok.Getter;
@Getter
public class BaseException extends RuntimeException{
/**
*
*/
private Integer code;
public BaseException(Integer code, String message) {
super(message);
this.code = code;
}
}

@ -0,0 +1,33 @@
package hk.ljx.fishpicsbackend.common.exception;
public class ExcUtils {
public static BaseException error(ExceptionCode exceptionCode) {
throw new BaseException(exceptionCode.getCode(), exceptionCode.getMessage());
}
public static BaseException error(ExceptionCode exceptionCode, String message) {
throw new BaseException(exceptionCode.getCode(), message);
}
public static BaseException error(Integer code, String message) {
return new BaseException(code, message);
}
public static void throwIfTrue(Boolean flag, ExceptionCode exceptionCode) {
if (flag) {
throw error(exceptionCode);
}
}
public static void throwIfTrue(Boolean flag, String message) {
if (flag) {
throw error(0,message);
}
}
public static void throwIfFalse(Boolean flag, ExceptionCode exceptionCode) {
if (!flag) {
throw error(exceptionCode);
}
}
}

@ -0,0 +1,25 @@
package hk.ljx.fishpicsbackend.common.exception;
import lombok.Getter;
@Getter
public enum ExceptionCode {
PARAMETER_ERROR(40001, "参数错误"),
UNAUTHORIZED(40002, "未授权"),
FORBIDDEN(40003, "禁止访问"),
NOT_FOUND(40004, "资源未找到"),
NOT_LOGIN(40005, "未登录"),
INTERNAL_SERVER_ERROR(50000, "服务器内部错误"),
UNPROCESSABLE_ENTITY(40022, "无法处理的实体"),
TOO_MANY_REQUESTS(40029, "请求过多"),
SERVICE_UNAVAILABLE(50003, "服务不可用");
private Integer code;
private String message;
ExceptionCode(Integer code, String message) {
this.code = code;
this.message = message;
}
}

@ -0,0 +1,24 @@
package hk.ljx.fishpicsbackend.common.exception;
import hk.ljx.fishpicsbackend.common.response.ResUtils;
import hk.ljx.fishpicsbackend.common.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(BaseException.class)
public Response<?> handleException(BaseException be) {
log.error("====> 业务异常,异常码:{},异常信息:{}", be.getCode(), be.getMessage());
return ResUtils.fail(be);
}
@ExceptionHandler(RuntimeException.class)
public Response<?> runtimeException(RuntimeException re) {
log.error("====> 系统异常,异常信息:{}", re.getMessage());
return ResUtils.fail(re);
}
}

@ -0,0 +1,28 @@
package hk.ljx.fishpicsbackend.common.response;
import hk.ljx.fishpicsbackend.common.exception.BaseException;
import java.io.Serializable;
public class ResUtils implements Serializable {
public static Response success(){
return new Response(1, "success", null);
}
public static <T> Response<T> success(T data) {
return new Response(1, "success", data);
}
public static Response fail(BaseException be) {
return new Response(be.getCode(), be.getMessage(), null);
}
public static Response fail(RuntimeException re) {
return new Response(0, re.getMessage(), null);
}
public static Response fail(String message) {
return new Response(0, message, null);
}
}

@ -0,0 +1,28 @@
package hk.ljx.fishpicsbackend.common.response;
import lombok.Data;
@Data
public class Response<T> {
/**
* 1-
*/
private Integer code;
/**
*
*/
private String message;
/**
*
*/
private T data;
public Response(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
}

@ -0,0 +1,18 @@
package hk.ljx.fishpicsbackend.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
@PostMapping("/login")
public String userLogin(){
return "login";
}
}

@ -0,0 +1,10 @@
package hk.ljx.fishpicsbackend.dto.base;
import lombok.Data;
import java.io.Serializable;
@Data
public class DeleteById implements Serializable {
private Long id;
}

@ -0,0 +1,26 @@
package hk.ljx.fishpicsbackend.dto.base;
import lombok.Data;
@Data
public class PageRequest {
/**
*
*/
private int current = 1;
/**
*
*/
private int pageSize = 10;
/**
*
*/
private String sortField;
/**
*
*/
private String sortOrder = "descend";
}

@ -0,0 +1,24 @@
package hk.ljx.fishpicsbackend.dto.user;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserLogin implements Serializable {
private String username;
private String password;
/**
*
*/
private String checkCode;
}

@ -0,0 +1,51 @@
package hk.ljx.fishpicsbackend.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName comment
*/
@TableName(value ="comment")
@Data
public class Comment {
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
*
*/
private Long userId;
/**
*
*/
private Long postId;
/**
*
*/
private String content;
/**
* 1- 0- 2-
*/
private Integer status;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
}

@ -0,0 +1,66 @@
package hk.ljx.fishpicsbackend.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName picture
*/
@TableName(value ="picture")
@Data
public class Picture {
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* id
*/
private Long userId;
/**
*
*/
private Long pictureName;
/**
*
*/
private String url;
/**
*
*/
private String width;
/**
*
*/
private String height;
/**
*
*/
private String size;
/**
* 1- 0- 2-
*/
private Integer status;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
}

@ -0,0 +1,63 @@
package hk.ljx.fishpicsbackend.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName post
*/
@TableName(value ="post")
@Data
public class Post {
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
*
*/
private Long userId;
/**
*
*/
private String title;
/**
*
*/
private String content;
/**
* id
*/
private String pictureIds;
/**
* 1- 0- 2-
*/
private Integer status;
/**
* 0-, 1-
*/
@TableLogic
private Integer delete;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
}

@ -0,0 +1,78 @@
package hk.ljx.fishpicsbackend.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName user
*/
@TableName(value ="user")
@Data
public class User {
/**
* ID
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
*
*/
private String username;
/**
*
*/
private String password;
/**
* URL
*/
private String avatar;
/**
*
*/
private String email;
/**
*
*/
private String phone;
/**
*
*/
private String nickname;
/**
* 1- 0- 2-
*/
private Integer status;
/**
* 0-, 1-
*/
@TableLogic
private Integer delete;
/**
*
*/
private String role;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
}

@ -0,0 +1,34 @@
package hk.ljx.fishpicsbackend.enums;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
@Getter
public enum UserRoleEnum {
ADMIN("admin", "管理员"),
USER("user", "普通用户");
private final String role;
private final String message;
UserRoleEnum(String role, String message) {
this.role = role;
this.message = message;
}
/**
* role
*/
public static UserRoleEnum getEnumByRole(String role) {
if (StrUtil.isBlank(role)) {
return null;
}
for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
if (userRoleEnum.getRole().equals(role)) {
return userRoleEnum;
}
}
return null;
}
}

@ -0,0 +1,18 @@
package hk.ljx.fishpicsbackend.mapper;
import hk.ljx.fishpicsbackend.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 30574
* @description comment()Mapper
* @createDate 2026-04-13 21:24:56
* @Entity hk.ljx.fishpicsbackend.entity.Comment
*/
public interface CommentMapper extends BaseMapper<Comment> {
}

@ -0,0 +1,18 @@
package hk.ljx.fishpicsbackend.mapper;
import hk.ljx.fishpicsbackend.entity.Picture;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 30574
* @description picture()Mapper
* @createDate 2026-04-13 21:24:49
* @Entity hk.ljx.fishpicsbackend.entity.Picture
*/
public interface PictureMapper extends BaseMapper<Picture> {
}

@ -0,0 +1,18 @@
package hk.ljx.fishpicsbackend.mapper;
import hk.ljx.fishpicsbackend.entity.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 30574
* @description post()Mapper
* @createDate 2026-04-13 21:24:41
* @Entity hk.ljx.fishpicsbackend.entity.Post
*/
public interface PostMapper extends BaseMapper<Post> {
}

@ -0,0 +1,18 @@
package hk.ljx.fishpicsbackend.mapper;
import hk.ljx.fishpicsbackend.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 30574
* @description user()Mapper
* @createDate 2026-04-13 21:24:26
* @Entity hk.ljx.fishpicsbackend.entity.User
*/
public interface UserMapper extends BaseMapper<User> {
}

@ -0,0 +1,13 @@
package hk.ljx.fishpicsbackend.service;
import hk.ljx.fishpicsbackend.entity.Comment;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author 30574
* @description comment()Service
* @createDate 2026-04-13 21:24:56
*/
public interface CommentService extends IService<Comment> {
}

@ -0,0 +1,13 @@
package hk.ljx.fishpicsbackend.service;
import hk.ljx.fishpicsbackend.entity.Picture;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author 30574
* @description picture()Service
* @createDate 2026-04-13 21:24:49
*/
public interface PictureService extends IService<Picture> {
}

@ -0,0 +1,13 @@
package hk.ljx.fishpicsbackend.service;
import hk.ljx.fishpicsbackend.entity.Post;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author 30574
* @description post()Service
* @createDate 2026-04-13 21:24:41
*/
public interface PostService extends IService<Post> {
}

@ -0,0 +1,21 @@
package hk.ljx.fishpicsbackend.service;
import hk.ljx.fishpicsbackend.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletRequest;
/**
* @author 30574
* @description user()Service
* @createDate 2026-04-13 21:24:26
*/
public interface UserService extends IService<User> {
/**
*
* @param request request
* @return
*/
User getLoginUser(HttpServletRequest request);
}

@ -0,0 +1,22 @@
package hk.ljx.fishpicsbackend.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hk.ljx.fishpicsbackend.entity.Comment;
import hk.ljx.fishpicsbackend.service.CommentService;
import hk.ljx.fishpicsbackend.mapper.CommentMapper;
import org.springframework.stereotype.Service;
/**
* @author 30574
* @description comment()Service
* @createDate 2026-04-13 21:24:56
*/
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment>
implements CommentService {
}

@ -0,0 +1,22 @@
package hk.ljx.fishpicsbackend.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hk.ljx.fishpicsbackend.entity.Picture;
import hk.ljx.fishpicsbackend.service.PictureService;
import hk.ljx.fishpicsbackend.mapper.PictureMapper;
import org.springframework.stereotype.Service;
/**
* @author 30574
* @description picture()Service
* @createDate 2026-04-13 21:24:49
*/
@Service
public class PictureServiceImpl extends ServiceImpl<PictureMapper, Picture>
implements PictureService {
}

@ -0,0 +1,22 @@
package hk.ljx.fishpicsbackend.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hk.ljx.fishpicsbackend.entity.Post;
import hk.ljx.fishpicsbackend.service.PostService;
import hk.ljx.fishpicsbackend.mapper.PostMapper;
import org.springframework.stereotype.Service;
/**
* @author 30574
* @description post()Service
* @createDate 2026-04-13 21:24:41
*/
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post>
implements PostService{
}

@ -0,0 +1,43 @@
package hk.ljx.fishpicsbackend.service.impl;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hk.ljx.fishpicsbackend.common.exception.ExcUtils;
import hk.ljx.fishpicsbackend.entity.User;
import hk.ljx.fishpicsbackend.service.UserService;
import hk.ljx.fishpicsbackend.mapper.UserMapper;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @author 30574
* @description user()Service
* @createDate 2026-04-13 21:24:26
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
implements UserService{
@Resource
private StringRedisTemplate stringRedisTemplate;
/**
*
*
* @param request request
* @return
*/
@Override
public User getLoginUser(HttpServletRequest request) {
String authorization = request.getHeader("Authorization");
ExcUtils.throwIfTrue(authorization == null || !authorization.startsWith("Bearer "), "未登录");
String user = stringRedisTemplate.opsForValue().get(authorization);
return JSONUtil.toBean(user, User.class);
}
}

@ -0,0 +1,29 @@
server:
port: 8080
servlet:
context-path: /api
spring:
application:
name: FishPic-backend
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/FishPics
username: root
password: 123456
redis:
host: 192.168.163.101:6379
database: 0
knife4j:
enable: true
openapi:
title: fish图库测试文档
description: "fish图库测试文档"
email: fish.java.react@gmail.com
concat: fish
version: v0.5
group:
test:
group-name: 开发测试
api-rule: package
api-rule-resources:
- hk.ljx.fishpicsbackend.controller

@ -0,0 +1,21 @@
<?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="hk.ljx.fishpicsbackend.mapper.CommentMapper">
<resultMap id="BaseResultMap" type="hk.ljx.fishpicsbackend.entity.Comment">
<id property="id" column="id" />
<result property="userId" column="user_id" />
<result property="postId" column="post_id" />
<result property="content" column="content" />
<result property="status" column="status" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="Base_Column_List">
id,user_id,post_id,content,status,create_time,
update_time
</sql>
</mapper>

@ -0,0 +1,24 @@
<?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="hk.ljx.fishpicsbackend.mapper.PictureMapper">
<resultMap id="BaseResultMap" type="hk.ljx.fishpicsbackend.entity.Picture">
<id property="id" column="id" />
<result property="userId" column="user_id" />
<result property="pictureName" column="picture_name" />
<result property="url" column="url" />
<result property="width" column="width" />
<result property="height" column="height" />
<result property="size" column="size" />
<result property="status" column="status" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="Base_Column_List">
id,user_id,picture_name,url,width,height,
size,status,create_time,update_time
</sql>
</mapper>

@ -0,0 +1,23 @@
<?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="hk.ljx.fishpicsbackend.mapper.PostMapper">
<resultMap id="BaseResultMap" type="hk.ljx.fishpicsbackend.entity.Post">
<id property="id" column="id" />
<result property="userId" column="user_id" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="pictureIds" column="picture_ids" />
<result property="delete" column="delete" />
<result property="status" column="status" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="Base_Column_List">
id,user_id,title,content,picture_ids,`status`,`delete`,
create_time,update_time
</sql>
</mapper>

@ -0,0 +1,27 @@
<?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="generator.mapper.UserMapper">
<resultMap id="BaseResultMap" type="hk.ljx.fishpicsbackend.entity.User">
<id property="id" column="id" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="avatar" column="avatar" />
<result property="email" column="email" />
<result property="phone" column="phone" />
<result property="nickname" column="nickname" />
<result property="status" column="status" />
<result property="delete" column="delete" />
<result property="role" column="role" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="Base_Column_List">
id,username,password,avatar,email,phone,
nickname,status,delete,role,create_time,
update_time
</sql>
</mapper>

@ -0,0 +1,68 @@
create database if not exists FishPics;
use FishPics;
-- 创建用户表
create table if not exists `user` (
`id` bigint unsigned not null auto_increment comment '用户ID',
`username` varchar(32) null comment '用户名(登录用)',
`password` varchar(128) null comment '密码',
`avatar` varchar(256) default null comment '头像URL',
`email` varchar(64) default null comment '邮箱',
`phone` varchar(16) default null comment '手机号',
`nickname` varchar(32) default null comment '昵称(展示用)',
`status` tinyint null default 1 comment '状态 1-正常 0-禁用 2-待审核',
`delete` tinyint null default 0 comment '0-逻辑未删除, 1-逻辑删除',
`role` varchar(32) null default 'user' comment '用户的权限',
`create_time` datetime not null default current_timestamp comment '创建时间',
`update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (`id`),
unique key `uk_username` (`username`) using btree,
unique key `uk_nickname` (`nickname`) using btree
) engine = innodb default charset = utf8mb4 comment = '用户表';
-- 创建图片表
create table `picture`(
`id` bigint not null auto_increment comment '主键',
`user_id` bigint not null comment '用户id', -- 关联用户表
`picture_name` bigint not null comment '图片名称',
`url` varchar(512) not null comment '图片地址',
`width` varchar(32) null comment '宽度',
`height` varchar(32) null comment '高度',
`size` varchar(32) null comment '大小',
`status` tinyint null default 1 comment '状态 1-正常 0-禁用 2-待审核',
`create_time` datetime not null default current_timestamp comment '创建时间',
`update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (`id`),
key `idx_user_id` (`user_id`) using btree,
key `idx_picture_name` (`picture_name`) using btree
) engine = innodb default charset = utf8mb4 comment = '图片表';
-- 创建帖子表
create table `post`(
`id` bigint not null auto_increment comment '主键',
`user_id` bigint not null comment '关联用户表',
`title` varchar(256) not null comment '标题',
`content` text not null comment '内容',
`picture_ids` varchar(512) null comment '图片id数组',
`status` tinyint null default 1 comment '状态 1-正常 0-禁用 2-待审核',
`create_time` datetime not null default current_timestamp comment '创建时间',
`update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (`id`),
key `idx_user_id` (`user_id`) using btree,
key `idx_title` (`title`) using btree
) engine = innodb default charset = utf8mb4 comment = '帖子表';
-- 创建评论表
create table `comment`(
`id` bigint not null auto_increment comment '主键',
`user_id` bigint not null comment '关联用户表',
`post_id` bigint not null comment '关联帖子表',
`content` text not null comment '评论内容',
`status` tinyint null default 1 comment '状态 1-正常 0-禁用 2-待审核',
`create_time` datetime not null default current_timestamp comment '创建时间',
`update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (`id`),
key `idx_user_id` (`user_id`) using btree,
key `idx_post_id` (`post_id`) using btree
) engine = innodb default charset = utf8mb4 comment = '评论表';

@ -0,0 +1,13 @@
package hk.ljx.fishpicsbackend;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FishPicsBackendApplicationTests {
@Test
void contextLoads() {
}
}
Loading…
Cancel
Save