finish postTagService and test, modify sth in postService
Change-Id: I76b5982f578b5bffe3c48b0afeda219e01307455
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 6bde80e..7f85f87 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,4 +1,4 @@
-spring.datasource.password=123456
+spring.datasource.password=12345678
spring.datasource.username=root
spring.datasource.url=jdbc:mysql://localhost:3306/g8backend
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 0907033..607d353 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -1 +1,11 @@
-# 后面统一数据库数据用
\ No newline at end of file
+# # 后面统一数据库数据用
+#
+# # tags表父标签
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (1, '电影', NULL);
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (2, '游戏', NULL);
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (3, '音乐', NULL);
+#
+# # tags表子标签
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (4, '动作', 1);
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (5, '喜剧', 1);
+# INSERT INTO `tags` (tag_id, tag_name, parent_id) VALUES (6, '科幻', 1);
\ No newline at end of file
diff --git a/src/main/resources/mapper/PostMapper.xml b/src/main/resources/mapper/PostMapper.xml
index c1dbda7..52d3be7 100644
--- a/src/main/resources/mapper/PostMapper.xml
+++ b/src/main/resources/mapper/PostMapper.xml
@@ -1,4 +1,3 @@
-.xml
<?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">
diff --git a/src/main/resources/mapper/PostTagMapper.xml b/src/main/resources/mapper/PostTagMapper.xml
new file mode 100644
index 0000000..b2cfc69
--- /dev/null
+++ b/src/main/resources/mapper/PostTagMapper.xml
@@ -0,0 +1,22 @@
+<?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.example.g8backend.entity.PostTag">
+ <select id="getPostsByTagIds" resultType="com.example.g8backend.entity.Post">
+ SELECT DISTINCT p.* FROM posts p JOIN post_tag pt ON p.post_id = pt.post_id
+ WHERE pt.tag_id IN
+ <foreach collection="tagIds" item="tagId" open="(" separator="," close=")">
+ #{tagId}
+ </foreach>
+ </select>
+
+ <select id="getTagsByPostId">
+ SELECT DISTINCT t.* FROM tags t JOIN post_tag pt ON t.tag_id = pt.tag_id
+ </select>
+
+ <delete id="deleteByIds">
+ DELETE FROM post_tag
+ WHERE post_id = #{postId} AND tag_id = #{tagId}
+ </delete>
+</mapper>
\ No newline at end of file