1. 获取所有分区 2. 根据分区获得作品列表
增加了分区以及作品的swagger接口描述,并调整到正确的项目结构中
Change-Id: I36850cd93eeb93992cad7d342f2688dd8e50e6bc
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index db34ebe..668bc3b 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,13 +1,15 @@
# ??MySQL??
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.url=jdbc:mysql://localhost:3306/groupone_db\
+spring.datasource.url=jdbc:mysql://localhost:3306/llksh\
?useSSL=false\
&serverTimezone=Asia/Shanghai\
&characterEncoding=utf8\
&allowPublicKeyRetrieval=true
spring.datasource.username=root
-spring.datasource.password=Rfw@2935
+spring.datasource.password=wuxiaorui123
+# src/main/resources/application.properties
+spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
# ???????????
spring.datasource.hikari.maximum-pool-size=10
@@ -16,4 +18,12 @@
spring.datasource.hikari.connection-timeout=30000
# ???? MyBatis ?????
-mybatis.configuration.map-underscore-to-camel-case=true
\ No newline at end of file
+mybatis.configuration.map-underscore-to-camel-case=true
+
+
+
+# ?????????
+mybatis.type-aliases-package=edu.bjtu.groupone.backend.domain.entity
+
+# ????????
+mybatis.mapper-locations=classpath:mapper/*.xml
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 6cf60f3..2d79bf4 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -15,9 +15,9 @@
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://localhost:3306/groupone_db?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8
+ url: jdbc:mysql://localhost:3306/llksh?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8
username: root
- password: "Rfw@2935"
+ password: "wuxiaorui123"
hikari:
maximum-pool-size: 10
minimum-idle: 5
diff --git a/src/main/resources/mapper/CategoryMybatisMapper.xml b/src/main/resources/mapper/CategoryMybatisMapper.xml
new file mode 100644
index 0000000..1a8e7e0
--- /dev/null
+++ b/src/main/resources/mapper/CategoryMybatisMapper.xml
@@ -0,0 +1,19 @@
+<?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">
+<!-- 修改1:使用全限定类名 -->
+<mapper namespace="edu.bjtu.groupone.backend.mapper.CategoryMybatisMapper">
+
+ <!-- 查询所有分类 -->
+ <select id="findAll"
+ resultType="edu.bjtu.groupone.backend.domain.entity.Category">
+ SELECT * FROM categories
+ </select>
+
+ <!-- 根据父分类ID查询 -->
+ <select id="findByParentId" parameterType="Long"
+ resultType="edu.bjtu.groupone.backend.domain.entity.Category">
+ SELECT * FROM categories WHERE parent_id = #{parentId}
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/WorkMybatisMapper.xml b/src/main/resources/mapper/WorkMybatisMapper.xml
new file mode 100644
index 0000000..dd0d444
--- /dev/null
+++ b/src/main/resources/mapper/WorkMybatisMapper.xml
@@ -0,0 +1,37 @@
+<?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="edu.bjtu.groupone.backend.mapper.WorkMybatisMapper">
+
+ <!-- 结果集映射 -->
+ <resultMap id="WorkResultMap" type="Work">
+ <id property="id" column="id"/>
+ <result property="title" column="title"/>
+ <result property="description" column="description"/>
+ <result property="categoryId" column="category_id"/>
+ <result property="createTime" column="create_time"/>
+ </resultMap>
+
+ <!-- 查询所有作品 -->
+ <select id="findAll" resultMap="WorkResultMap">
+ SELECT id, title, description, category_id, create_time
+ FROM works
+ </select>
+
+ <!-- 根据分类ID列表分页查询 -->
+ <select id="findByCategoryIdIn" resultMap="WorkResultMap">
+ SELECT * FROM works
+ <where>
+ <if test="categoryIds != null and categoryIds.size() > 0">
+ category_id IN
+ <foreach item="categoryId" collection="categoryIds"
+ open="(" separator="," close=")">
+ #{categoryId}
+ </foreach>
+ </if>
+ </where>
+ ORDER BY create_time DESC
+ LIMIT #{pageable.pageSize} OFFSET #{pageable.offset}
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index 823ecdf..beb0cc7 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -1,3 +1,4 @@
+-- 使用反引号包裹保留字表名
CREATE TABLE `user` (
`user_id` INT PRIMARY KEY AUTO_INCREMENT,
`username` VARCHAR(255) NOT NULL UNIQUE,
@@ -6,27 +7,25 @@
`address` VARCHAR(255),
`role` VARCHAR(50) NOT NULL DEFAULT 'user',
`profile_pic` VARCHAR(255),
- `registration_date` DATETIME NOT NULL, -- 推荐用时间类型(而非字符串)
- `identification_number` VARCHAR(18), -- 身份证号建议用 VARCHAR(18)
+ `registration_date` DATETIME NOT NULL,
+ `identification_number` VARCHAR(18),
`avatar` VARCHAR(255),
- `isfollowed` BOOLEAN NOT NULL DEFAULT FALSE,
- INDEX `idx_user_id` (`user_id`) -- 可选:主键通常自带索引
+ `isfollowed` BOOLEAN NOT NULL DEFAULT FALSE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-
-
+-- 外键表同样使用反引号
CREATE TABLE user_follow (
- follower_id INT NOT NULL,
- followed_id INT NOT NULL,
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (follower_id, followed_id),
- FOREIGN KEY (follower_id) REFERENCES user(user_id),
- FOREIGN KEY (followed_id) REFERENCES user(user_id)
+ `follower_id` INT NOT NULL,
+ `followed_id` INT NOT NULL,
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`follower_id`, `followed_id`),
+ FOREIGN KEY (`follower_id`) REFERENCES `user`(`user_id`),
+ FOREIGN KEY (`followed_id`) REFERENCES `user`(`user_id`)
);
+-- 插入语句使用反引号包裹表名和列名
INSERT INTO `user` (
- username, email, password, registration_date, identification_number, role
+ `username`, `email`, `password`, `registration_date`, `identification_number`, `role`
) VALUES (
- 'admin', 'admin@example.com', 'admin123', NOW(), 87654321, 'admin'
- );
-
+ 'admin', 'admin@example.com', 'admin123', NOW(), '87654321', 'admin'
+ );
\ No newline at end of file