概述
效果展示
数据库设计
专栏表
DROP TABLE IF EXISTS `blog_column`;
CREATE TABLE `blog_column` (
`blogColumnId` int(11) NOT NULL AUTO_INCREMENT,
`blogColumnName` varchar(255) DEFAULT NULL,
`blogColumnCoverImg` longtext,
`blogColumnIntroduction` longtext,
`userId` int(11) DEFAULT NULL,
PRIMARY KEY (`blogColumnId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
标签表
DROP TABLE IF EXISTS `blog_tag`;
CREATE TABLE `blog_tag` (
`blogTagId` int(11) NOT NULL AUTO_INCREMENT,
`blogTagName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`blogTagId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
博客类型表
DROP TABLE IF EXISTS `blog_type`;
CREATE TABLE `blog_type` (
`blogTypeId` int(11) NOT NULL AUTO_INCREMENT,
`blogTypeName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`blogTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
评论表
DROP TABLE IF EXISTS `blog_comment`;
CREATE TABLE `blog_comment` (
`blogCommentId` int(11) NOT NULL AUTO_INCREMENT,
`blogCommentContent` varchar(255) DEFAULT NULL,
`blogCommentTime` varchar(255) DEFAULT NULL,
`userId` int(11) DEFAULT NULL,
`blogId` int(11) DEFAULT NULL,
PRIMARY KEY (`blogCommentId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
可见范围表
DROP TABLE IF EXISTS `blog_visibility`;
CREATE TABLE `blog_visibility` (
`blogVisibilityId` int(11) NOT NULL AUTO_INCREMENT,
`blogVisibilityName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`blogVisibilityId`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
博客表
DROP TABLE IF EXISTS `blog`;
CREATE TABLE `blog` (
`blogId` int(11) NOT NULL AUTO_INCREMENT,
`blogTitle` varchar(255) DEFAULT NULL,
`blogCoverImg` longtext,
`blogSummary` longtext,
`blogContent` longtext,
`blogCreateData` varchar(255) DEFAULT NULL,
`blogShow` int(11) DEFAULT NULL,
`blogRead` int(11) DEFAULT NULL,
`blogLike` int(11) DEFAULT NULL,
`blogFavorite` int(11) DEFAULT NULL,
`userId` int(11) DEFAULT NULL,
`blogTypeId` int(11) DEFAULT NULL,
`blogVisibilityId` int(11) DEFAULT NULL,
`blogStatus` varchar(255) DEFAULT NULL,
PRIMARY KEY (`blogId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
博客专栏关联表
DROP TABLE IF EXISTS `blog_blog_column`;
CREATE TABLE `blog_blog_column` (
`blogId` int(11) DEFAULT NULL,
`blogColumnId` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
博客标签关联表
DROP TABLE IF EXISTS `blog_blog_tag`;
CREATE TABLE `blog_blog_tag` (
`blogId` int(11) DEFAULT NULL,
`blogTagId` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
实体类设计
Blog
/**
* 博客文章实体类
*/
@Data
public class Blog implements Serializable {
@TableId
private Integer blogId;
private String blogCoverImg;//封面
private String blogTitle;//标题
private String blogSummary;//摘要
private String blogContent;//内容
private String blogCreateData;//创作时间
private String blogStatus;//状态【0:审核/1:发布】
private Integer blogShow;//展现量
private Integer blogRead;//阅读量
private Integer blogLike;//点赞量
private Integer blogFavorite;//收藏量
private Integer userId;//作者
@TableField(exist = false)
private User user;
private Integer blogTypeId;//类型
@TableField(exist = false)
private BlogType blogType;
private Integer blogVisibilityId;//可见范围
@TableField(exist = false)
private BlogVisibility blogVisibility;
@TableField(exist = false)
private List<BlogTag> tags;//标签
@TableField(exist = false)
private List<BlogColumn> columns;//专栏
}
BlogColumn
/**
* 专栏
* 博客和专栏是多对多的关系
* 用户和专栏是一对多的关系
*/
@Data
public class BlogColumn implements Serializable {
@TableId
private Integer blogColumnId;
private String blogColumnName;//名称
private String blogColumnCoverImg;//封面
private String blogColumnIntroduction;//简介
private Integer userId;//用户
}
BlogComment
/**
* 评论
*/
@Data
public class BlogComment implements Serializable {
@TableId
private Integer blogCommentId;
private String blogCommentTime;//评论时间
private String blogCommentContent;//内容
private Integer userId;//评论者
private Integer blogId;//博客
}
BlogTag
/**
* 标签
* 博客和标签是多对多的关系
*/
@Data
public class BlogTag implements Serializable {
@TableId
private Integer blogTagId;
private String blogTagName;//标签名
}
BlogType
/**
* 类型
*/
@Data
public class BlogType implements Serializable {
@TableId
private Integer blogTypeId;
private String blogTypeName;//类型名
}
BlogVisibility
/**
* 可见范围
*/
@Data
public class BlogVisibility implements Serializable {
@TableId
private Integer blogVisibilityId;
private String blogVisibilityName;//名称
}
Mapper层编写
BlogColumnMapper
public interface BlogColumnMapper extends BaseMapper<BlogColumn> {
//根据标签id删除博客_专栏关联表的数据
void deleteBlog_columnByBlogColumnId(Integer blogColumnId);
}
BlogColumnMapper.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">
<mapper namespace="jkw.mapper.BlogColumnMapper">
<delete id="deleteBlog_columnByBlogColumnId" parameterType="int">
DELETE
FROM blog_blog_column
WHERE blogColumnId = #{blogColumnId}
</delete>
</mapper>
BlogCommentMapper
public interface BlogCommentMapper extends BaseMapper<BlogComment> {
}
BlogMapper
public interface BlogMapper extends BaseMapper<Blog> {
//添加博客_专栏中间表的数据
void addBlog_column(@Param("blogId") Integer blogId, @Param("blogColumnId") Integer blogColumnId);
//删除博客_专栏中间表的数据
void deleteBlog_column(@Param("blogId") Integer blogId, @Param("blogColumnId") Integer blogColumnId);
//根据博客id删除博客_专栏中间表的数据
void deleteBlog_columnByBlogId(Integer blogId);
//根据博客id查询博客_专栏中间表的专栏数据
List<BlogColumn> findColumnByBlogId(Integer blogId);
//添加博客_标签中间表的数据
void addBlog_tag(@Param("blogId") Integer blogId, @Param("blogTagId") Integer blogTagId);
//删除博客_标签中间表的数据
void deleteBlog_tag(@Param("blogId") Integer blogId, @Param("blogTagId") Integer blogTagId);
//根据博客id删除博客_标签中间表的数据
void deleteBlog_tagByBlogId(Integer blogId);
//根据博客id查询博客_标签中间表的标签数据
List<BlogTag> findTagByBlogId(Integer blogId);
//删除博客对应的所有评论
void deleteAllComments(Integer blogId);
//根据id查询博客内容【封装数据】
Blog findById(Integer blogId);
//条件分页分页查询博客内容【封装数据】
Page<Blog> search(Page<Blog> page, @Param(Constants.WRAPPER) Wrapper<Blog> wrapper);
//条件分页分页查询博客内容【封装数据并且为发布状态】
Page<Blog> searchWhenStatus(Page<Blog> page, @Param(Constants.WRAPPER) Wrapper<Blog> wrapper);
}
BlogMapper.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">
<mapper namespace="jkw.mapper.BlogMapper">
<resultMap id="blogMapper" type="jkw.pojo.Blog">
<id property="blogId" column="blogId"></id>
<result property="blogTitle" column="blogTitle"></result>
<result property="blogCoverImg" column="blogCoverImg"></result>
<result property="blogSummary" column="blogSummary"></result>
<result property="blogContent" column="blogContent"></result>
<result property="blogCreateData" column="blogCreateData"></result>
<result property="blogStatus" column="blogStatus"></result>
<result property="blogShow" column="blogShow"></result>
<result property="blogRead" column="blogRead"></result>
<result property="blogLike" column="blogLike"></result>
<result property="blogFavorite" column="blogFavorite"></result>
<result property="userId" column="userId"></result>
<result property="blogTypeId" column="blogTypeId"></result>
<result property="blogVisibilityId" column="blogVisibilityId"></result>
<result property="userId" column="userId"></result>
<collection property="user" column="userId" ofType="jkw.pojo.User">
<id property="userId" column="userId"></id>
<result property="userImg" column="userImg"></result>
<result property="nickname" column="nickname"></result>
<result property="email" column="email"></result>
<result property="username" column="username"></result>
<result property="signature" column="signature"></result>
</collection>
<collection property="blogType" column="blogTypeId" ofType="jkw.pojo.BlogType">
<id property="blogTypeId" column="blogTypeId"></id>
<result property="blogTypeName" column="blogTypeName"></result>
</collection>
<collection property="blogVisibility" column="blogVisibilityId" ofType="jkw.pojo.BlogVisibility">
<id property="blogVisibilityId" column="blogVisibilityId"></id>
<result property="blogVisibilityName" column="blogVisibilityName"></result>
</collection>
<collection property="tags" column="blogId" ofType="jkw.pojo.BlogTag">
<id property="blogTagId" column="blogTagId"></id>
<result property="blogTagName" column="blogTagName"></result>
</collection>
<collection property="columns" column="blogId" ofType="jkw.pojo.BlogColumn">
<id property="blogColumnId" column="blogColumnId"></id>
<result property="blogColumnName" column="blogColumnName"></result>
<result property="blogColumnCoverImg" column="blogColumnCoverImg"></result>
<result property="blogColumnIntroduction" column="blogColumnIntroduction"></result>
<result property="userId" column="userId"></result>
</collection>
</resultMap>
<insert id="addBlog_column">
INSERT INTO blog_blog_column
VALUES (#{blogId}, #{blogColumnId});
</insert>
<delete id="deleteBlog_column" parameterType="int">
DELETE
FROM blog_blog_column
WHERE blogId = #{blogId}
and blogColumnId = #{blogColumnId});
</delete>
<delete id="deleteBlog_columnByBlogId" parameterType="int">
DELETE
FROM blog_blog_column
WHERE blogId = #{blogId}
</delete>
<select id="findColumnByBlogId" resultType="jkw.pojo.BlogColumn" parameterType="int">
select blog_column.*
from blog_column
left join blog_blog_column
on blog_blog_column.blogColumnId = blog_column.blogColumnId
where blog_blog_column.blogId = #{blogId}
</select>
<insert id="addBlog_tag">
INSERT INTO blog_blog_tag
VALUES (#{blogId}, #{blogTagId});
</insert>
<delete id="deleteBlog_tag" parameterType="int">
DELETE
FROM blog_blog_tag
WHERE blogId = #{blogId}
and blogTagId = #{blogTagId})
</delete>
<delete id="deleteBlog_tagByBlogId" parameterType="int">
DELETE
FROM blog_blog_tag
WHERE blogId = #{blogId}
</delete>
<select id="findTagByBlogId" resultType="jkw.pojo.BlogTag" parameterType="int">
select blog_tag.*
from blog_tag
left join blog_blog_tag
on blog_blog_tag.blogTagId = blog_tag.blogTagId
where blog_blog_tag.blogId = #{blogId}
</select>
<delete id="deleteAllComments" parameterType="int">
DELETE
FROM blog_comment
WHERE blogId = #{blogId}
</delete>
<select id="findById" parameterType="int" resultMap="blogMapper">
SELECT *
FROM blog
LEFT JOIN user
ON blog.userId = user.userId
LEFT JOIN blog_type
ON blog.blogTypeId = blog_type.blogTypeId
LEFT JOIN blog_visibility
ON blog.blogVisibilityId = blog_visibility.blogVisibilityId
LEFT JOIN blog_blog_tag
ON blog.blogId = blog_blog_tag.blogId
LEFT JOIN blog_tag
ON blog_blog_tag.blogTagId = blog_tag.blogTagId
LEFT JOIN blog_blog_column
ON blog.blogId = blog_blog_column.blogId
LEFT JOIN blog_column
ON blog_column.blogColumnId = blog_blog_column.blogColumnId
WHERE blog.blogId = #{blogId}
</select>
<select id="search" resultMap="blogMapper">
SELECT *
FROM blog
LEFT JOIN user
ON blog.userId = user.userId
LEFT JOIN blog_type
ON blog.blogTypeId = blog_type.blogTypeId
LEFT JOIN blog_visibility
ON blog.blogVisibilityId = blog_visibility.blogVisibilityId
LEFT JOIN blog_blog_tag
ON blog.blogId = blog_blog_tag.blogId
LEFT JOIN blog_tag
ON blog_blog_tag.blogTagId = blog_tag.blogTagId
LEFT JOIN blog_blog_column
ON blog.blogId = blog_blog_column.blogId
LEFT JOIN blog_column
ON blog_column.blogColumnId = blog_blog_column.blogColumnId
${ew.customSqlSegment}
ORDER BY blog.blogId desc
</select>
<select id="searchWhenStatus" resultMap="blogMapper">
SELECT *
FROM blog
LEFT JOIN user
ON blog.userId = user.userId
LEFT JOIN blog_type
ON blog.blogTypeId = blog_type.blogTypeId
LEFT JOIN blog_visibility
ON blog.blogVisibilityId = blog_visibility.blogVisibilityId
LEFT JOIN blog_blog_tag
ON blog.blogId = blog_blog_tag.blogId
LEFT JOIN blog_tag
ON blog_blog_tag.blogTagId = blog_tag.blogTagId
LEFT JOIN blog_blog_column
ON blog.blogId = blog_blog_column.blogId
LEFT JOIN blog_column
ON blog_column.blogColumnId = blog_blog_column.blogColumnId ${ew.customSqlSegment} and blog.blogStatus=1
ORDER BY blog.blogId desc
</select>
</mapper>
BlogTagMapper
public interface BlogTagMapper extends BaseMapper<BlogTag> {
//根据标签id删除博客_标签关联表的数据
void deleteBlog_tagByBlogTagId(Integer blogTagId);
}
BlogTagMapper.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">
<mapper namespace="jkw.mapper.BlogTagMapper">
<delete id="deleteBlog_tagByBlogTagId" parameterType="int">
DELETE
FROM blog_blog_tag
WHERE blogTagId = #{blogTagId}
</delete>
</mapper>
BlogTypeMapper
public interface BlogTypeMapper extends BaseMapper<BlogType> {
}
BlogVisibilityMapper
public interface BlogVisibilityMapper extends BaseMapper<BlogVisibility> {
}
服务层接口
BlogColumnService
public interface BlogColumnService {
void add(BlogColumn blogColumn);
void update(BlogColumn blogColumn);
void delete(Integer id);
BlogColumn findById(Integer id);
List<BlogColumn> findAll();
Page<BlogColumn> search(String search, int page, int size);
//根据用户id分页查询专栏
Page<BlogColumn> searchByUserId(Integer userId, int page, int size);
}
BlogCommentService
public interface BlogCommentService {
void add(BlogComment blogComment);
void update(BlogComment blogComment);
void delete(Integer id);
BlogComment findById(Integer id);
List<BlogComment> findAll();
Page<BlogComment> search(String search, int page, int size);
//根据博客id分页查询
Page<BlogComment> searchByBlogId(Integer blogId, int page, int size);
}
BlogService
public interface BlogService {
void add(Blog blog);
void update(Blog blog);
void delete(Integer id);
Blog findById(Integer id);
List<Blog> findAll();
Page<Blog> search(String search, int page, int size);
//分页查询状态为发布的博客
Page<Blog> searchForStatus(String search, int page, int size);
//更新博客状态
void updateStatus(Integer id);
//根据用户名分页查找博客文章
Page<Blog> searchByUserId(Integer userId, int page, int size);
//添加博客_专栏中间表的数据
void addBlog_column(Integer blogId, Integer blogColumnId);
//删除博客_专栏中间表的数据
void deleteBlog_column(Integer blogId, Integer blogColumnId);
//根据博客id查询博客_专栏中间表的专栏数据
List<BlogColumn> findColumnByBlogId(Integer blogId);
//添加博客_标签中间表的数据
void addBlog_tag(Integer blogId, Integer blogTagId);
//删除博客_标签中间表的数据
void deleteBlog_tag(Integer blogId, Integer blogTagId);
//根据博客id查询博客_标签中间表的标签数据
List<BlogTag> findTagByBlogId(Integer blogId);
}
BlogTagService
public interface BlogTagService {
void add(BlogTag blogTag);
void update(BlogTag blogTag);
void delete(Integer id);
BlogTag findById(Integer id);
List<BlogTag> findAll();
Page<BlogTag> search(String search, int page, int size);
}
BlogTypeService
public interface BlogTypeService {
void add(BlogType blogType);
void update(BlogType blogType);
void delete(Integer id);
BlogType findById(Integer id);
List<BlogType> findAll();
Page<BlogType> search(String search, int page, int size);
}
BlogVisibilityService
public interface BlogVisibilityService {
void add(BlogVisibility blogVisibility);
void update(BlogVisibility blogVisibility);
void delete(Integer id);
BlogVisibility findById(Integer id);
List<BlogVisibility> findAll();
Page<BlogVisibility> search(String search, int page, int size);
}
服务层实现
BlogColumnServiceImpl
@Service
@Transactional
public class BlogColumnServiceImpl implements BlogColumnService {
@Autowired
private BlogColumnMapper blogColumnMapper;
@Override
public void add(BlogColumn blogColumn) {
blogColumnMapper.insert(blogColumn);
}
@Override
public void update(BlogColumn blogColumn) {
blogColumnMapper.updateById(blogColumn);
}
@Override
public void delete(Integer id) {
//删除博客_专栏关联表的数据
blogColumnMapper.deleteBlog_columnByBlogColumnId(id);
//删除关联表的数据
blogColumnMapper.deleteById(id);
}
@Override
public BlogColumn findById(Integer id) {
return blogColumnMapper.selectById(id);
}
@Override
public List<BlogColumn> findAll() {
return blogColumnMapper.selectList(null);
}
@Override
public Page<BlogColumn> search(String search, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogColumnMapper.selectPage(new Page<>(page, size), queryWrapper);
}
@Override
public Page<BlogColumn> searchByUserId(Integer userId, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("userId", userId);
return blogColumnMapper.selectPage(new Page<>(page, size), queryWrapper);
}
}
BlogCommentServiceImpl
@Service
@Transactional
public class BlogCommentServiceImpl implements BlogCommentService {
@Autowired
private BlogCommentMapper blogCommentMapper;
@Override
public void add(BlogComment blogComment) {
blogCommentMapper.insert(blogComment);
}
@Override
public void update(BlogComment blogComment) {
blogCommentMapper.updateById(blogComment);
}
@Override
public void delete(Integer id) {
blogCommentMapper.deleteById(id);
}
@Override
public BlogComment findById(Integer id) {
return blogCommentMapper.selectById(id);
}
@Override
public List<BlogComment> findAll() {
return blogCommentMapper.selectList(null);
}
@Override
public Page<BlogComment> search(String search, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogCommentMapper.selectPage(new Page<>(page, size), queryWrapper);
}
@Override
public Page<BlogComment> searchByBlogId(Integer blogId, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("blogId", blogId);
return blogCommentMapper.selectPage(new Page<>(page, size), queryWrapper);
}
}
BlogServiceImpl
@Service
@Transactional
public class BlogServiceImpl implements BlogService {
@Autowired
private BlogMapper blogMapper;
@Override
public void add(Blog blog) {
blogMapper.insert(blog);
}
@Override
public void update(Blog blog) {
blogMapper.updateById(blog);
}
@Override
public void delete(Integer id) {
//删除博客_专栏中间表的数据
blogMapper.deleteBlog_columnByBlogId(id);
//删除博客_标签中间表的数据
blogMapper.deleteBlog_tagByBlogId(id);
//删除博客对应的所有评论
blogMapper.deleteAllComments(id);
blogMapper.deleteById(id);
}
@Override
public Blog findById(Integer id) {
return blogMapper.findById(id);
}
@Override
public List<Blog> findAll() {
return blogMapper.selectList(null);
}
@Override
public Page<Blog> search(String search, int page, int size) {
QueryWrapper<Blog> queryWrapper = new QueryWrapper();
if (search != null) {
queryWrapper.like("blogTitle", search);
}
return blogMapper.search(new Page<>(page, size), queryWrapper);
}
@Override
public Page<Blog> searchForStatus(String search, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogMapper.searchWhenStatus(new Page<>(page, size), queryWrapper);
}
@Override
public Page<Blog> searchByUserId(Integer userId, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("userId", userId);
return blogMapper.search(new Page<>(page, size), queryWrapper);
}
@Override
public void updateStatus(Integer id) {
Blog blog = blogMapper.selectById(id);
if (blog.getBlogStatus().equals("1")) {
blog.setBlogStatus("0");
blogMapper.updateById(blog);
} else {
blog.setBlogStatus("1");
blogMapper.updateById(blog);
}
}
@Override
public void addBlog_column(Integer blogId, Integer blogColumnId) {
blogMapper.addBlog_column(blogId, blogColumnId);
}
@Override
public void deleteBlog_column(Integer blogId, Integer blogColumnId) {
blogMapper.deleteBlog_column(blogId, blogColumnId);
}
@Override
public List<BlogColumn> findColumnByBlogId(Integer blogId) {
return blogMapper.findColumnByBlogId(blogId);
}
@Override
public void addBlog_tag(Integer blogId, Integer blogTagId) {
blogMapper.addBlog_tag(blogId, blogTagId);
}
@Override
public void deleteBlog_tag(Integer blogId, Integer blogTagId) {
blogMapper.deleteBlog_tag(blogId, blogTagId);
}
@Override
public List<BlogTag> findTagByBlogId(Integer blogId) {
return blogMapper.findTagByBlogId(blogId);
}
}
BlogTagServiceImpl
@Service
@Transactional
public class BlogTagServiceImpl implements BlogTagService {
@Autowired
private BlogTagMapper blogTagMapper;
@Override
public void add(BlogTag blogTag) {
blogTagMapper.insert(blogTag);
}
@Override
public void update(BlogTag blogTag) {
blogTagMapper.updateById(blogTag);
}
@Override
public void delete(Integer id) {
//删除博客_标签关联表的数据
blogTagMapper.deleteBlog_tagByBlogTagId(id);
//删除标签
blogTagMapper.deleteById(id);
}
@Override
public BlogTag findById(Integer id) {
return blogTagMapper.selectById(id);
}
@Override
public List<BlogTag> findAll() {
return blogTagMapper.selectList(null);
}
@Override
public Page<BlogTag> search(String search, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogTagMapper.selectPage(new Page<>(page, size), queryWrapper);
}
}
BlogTypeServiceImpl
@Service
@Transactional
public class BlogTypeServiceImpl implements BlogTypeService {
@Autowired
private BlogTypeMapper blogTypeMapper;
@Override
public void add(BlogType blogType) {
blogTypeMapper.insert(blogType);
}
@Override
public void update(BlogType blogType) {
blogTypeMapper.updateById(blogType);
}
@Override
public void delete(Integer id) {
blogTypeMapper.deleteById(id);
}
@Override
public BlogType findById(Integer id) {
return blogTypeMapper.selectById(id);
}
@Override
public List<BlogType> findAll() {
return blogTypeMapper.selectList(null);
}
@Override
public Page<BlogType> search(String search, int page, int size) {
QueryWrapper queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogTypeMapper.selectPage(new Page<>(page, size), queryWrapper);
}
}
BlogVisibilityServiceImpl
@Service
@Transactional
public class BlogVisibilityServiceImpl implements BlogVisibilityService {
@Autowired
private BlogVisibilityMapper blogVisibilityMapper;
@Override
public void add(BlogVisibility blogVisibility) {
blogVisibilityMapper.insert(blogVisibility);
}
@Override
public void update(BlogVisibility blogVisibility) {
blogVisibilityMapper.updateById(blogVisibility);
}
@Override
public void delete(Integer id) {
blogVisibilityMapper.deleteById(id);
}
@Override
public BlogVisibility findById(Integer id) {
return blogVisibilityMapper.selectById(id);
}
@Override
public List<BlogVisibility> findAll() {
return blogVisibilityMapper.selectList(null);
}
@Override
public Page<BlogVisibility> search(String search, int page, int size) {
QueryWrapper<BlogVisibility> queryWrapper = new QueryWrapper();
if (search != null) {
}
return blogVisibilityMapper.selectPage(new Page<>(page, size), queryWrapper);
}
}
后台控制层接口
BlogColumnCon
@CrossOrigin
@RequestMapping("/back/blogColumn")
@RestController
public class BlogColumnCon {
@Autowired
private BlogColumnService blogColumnService;
/**
* 新增
*
* @param blogColumn
* @return
*/
@PostMapping("/add")
public BaseResult add(BlogColumn blogColumn) {
blogColumnService.add(blogColumn);
return BaseResult.ok();
}
/**
* 修改
*
* @param blogColumn
* @return
*/
@PostMapping("/update")
public BaseResult update(BlogColumn blogColumn) {
blogColumnService.update(blogColumn);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogColumnId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogColumnId) {
blogColumnService.delete(blogColumnId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogColumnId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogColumnId) {
BlogColumn blogColumn = blogColumnService.findById(blogColumnId);
return BaseResult.ok(blogColumn);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<BlogColumn> all = blogColumnService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<BlogColumn> brandPage = blogColumnService.search(search, page, size);
return BaseResult.ok(brandPage);
}
/**
* 根据用户id分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/searchByUserId")
public BaseResult search(Integer userId, int page, int size) {
Page<BlogColumn> brandPage = blogColumnService.searchByUserId(userId, page, size);
return BaseResult.ok(brandPage);
}
}
BlogCommentCon
@CrossOrigin
@RequestMapping("/back/blogComment")
@RestController
public class BlogCommentCon {
@Autowired
private BlogCommentService blogCommentService;
/**
* 新增
*
* @param blogComment
* @return
*/
@PostMapping("/add")
public BaseResult add(BlogComment blogComment) {
blogCommentService.add(blogComment);
return BaseResult.ok();
}
/**
* 修改
*
* @param blogComment
* @return
*/
@PostMapping("/update")
public BaseResult update(BlogComment blogComment) {
blogCommentService.update(blogComment);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogCommentId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogCommentId) {
blogCommentService.delete(blogCommentId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogCommentId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogCommentId) {
BlogComment blogComment = blogCommentService.findById(blogCommentId);
return BaseResult.ok(blogComment);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<BlogComment> all = blogCommentService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<BlogComment> brandPage = blogCommentService.search(search, page, size);
return BaseResult.ok(brandPage);
}
/**
* 根据博客id分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/searchByBlogId")
public BaseResult searchByBlogId(Integer blogId, int page, int size) {
Page<BlogComment> brandPage = blogCommentService.searchByBlogId(blogId, page, size);
return BaseResult.ok(brandPage);
}
}
BlogCon
package jkw.controller.back;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.Blog;
import jkw.pojo.BlogColumn;
import jkw.pojo.BlogTag;
import jkw.service.BlogService;
import jkw.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@CrossOrigin
@RequestMapping("/back/blog")
@RestController
public class BlogCon {
@Autowired
private BlogService blogService;
/**
* 新增
*
* @param blog
* @return
*/
@PostMapping("/add")
public BaseResult add(Blog blog) {
blogService.add(blog);
return BaseResult.ok();
}
/**
* 修改
*
* @param blog
* @return
*/
@PostMapping("/update")
public BaseResult update(Blog blog) {
blogService.update(blog);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogId) {
blogService.delete(blogId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogId) {
Blog blog = blogService.findById(blogId);
return BaseResult.ok(blog);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<Blog> all = blogService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<Blog> brandPage = blogService.search(search, page, size);
return BaseResult.ok(brandPage);
}
/**
* 根据用户名分页查找博客文章
*
* @param page
* @param size
* @return
*/
@GetMapping("/searchByUserId")
public BaseResult search(Integer userId, int page, int size) {
Page<Blog> brandPage = blogService.searchByUserId(userId, page, size);
return BaseResult.ok(brandPage);
}
/**
* 更新博客状态
*
* @param blogId
* @return
*/
@PostMapping("/updateStatus")
public BaseResult update(Integer blogId) {
blogService.updateStatus(blogId);
return BaseResult.ok();
}
/**
* 添加博客_专栏中间表的数据
*
* @param blogId 博客id
* @param blogColumnId 专栏id
* @return
*/
@PostMapping("/addColumn")
public BaseResult addColumn(Integer blogId, Integer blogColumnId) {
blogService.addBlog_column(blogId, blogColumnId);
return BaseResult.ok();
}
/**
* 删除博客_专栏中间表的数据
*
* @param blogId 博客id
* @param blogColumnId 专栏id
* @return
*/
@DeleteMapping("/deleteColumn")
public BaseResult deleteColumn(Integer blogId, Integer blogColumnId) {
blogService.deleteBlog_column(blogId, blogColumnId);
return BaseResult.ok();
}
/**
* 根据博客id查询博客_专栏中间表的专栏数据
*
* @param blogId
* @return
*/
@GetMapping("/findColumnByBlogId")
public BaseResult findColumnByBlogId(Integer blogId) {
List<BlogColumn> blogColumnList = blogService.findColumnByBlogId(blogId);
return BaseResult.ok(blogColumnList);
}
/**
* 添加博客_标签中间表的数据
*
* @param blogId 博客id
* @param blogTagId 标签id
* @return
*/
@PostMapping("/addTag")
public BaseResult addTag(Integer blogId, Integer blogTagId) {
blogService.addBlog_tag(blogId, blogTagId);
return BaseResult.ok();
}
/**
* 删除博客_标签中间表的数据
*
* @param blogId 博客id
* @param blogTagId 标签id
* @return
*/
@DeleteMapping("/deleteTag")
public BaseResult deleteTag(Integer blogId, Integer blogTagId) {
blogService.deleteBlog_tag(blogId, blogTagId);
return BaseResult.ok();
}
/**
* 根据博客id查询博客_标签中间表的标签数据
*
* @param blogId
* @return
*/
@GetMapping("/findTagByBlogId")
public BaseResult findTagByBlogId(Integer blogId) {
List<BlogTag> blogTagList = blogService.findTagByBlogId(blogId);
return BaseResult.ok(blogTagList);
}
}
BlogTagCon
@CrossOrigin
@RequestMapping("/back/blogTag")
@RestController
public class BlogTagCon {
@Autowired
private BlogTagService blogTagService;
/**
* 新增
*
* @param blogTag
* @return
*/
@PostMapping("/add")
public BaseResult add(BlogTag blogTag) {
blogTagService.add(blogTag);
return BaseResult.ok();
}
/**
* 修改
*
* @param blogTag
* @return
*/
@PostMapping("/update")
public BaseResult update(BlogTag blogTag) {
blogTagService.update(blogTag);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogTagId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogTagId) {
blogTagService.delete(blogTagId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogTagId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogTagId) {
BlogTag blogTag = blogTagService.findById(blogTagId);
return BaseResult.ok(blogTag);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<BlogTag> all = blogTagService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<BlogTag> brandPage = blogTagService.search(search, page, size);
return BaseResult.ok(brandPage);
}
}
BlogTypeCon
@CrossOrigin
@RequestMapping("/back/blogType")
@RestController
public class BlogTypeCon {
@Autowired
private BlogTypeService blogTypeService;
/**
* 新增
*
* @param blogType
* @return
*/
@PostMapping("/add")
public BaseResult add(BlogType blogType) {
blogTypeService.add(blogType);
return BaseResult.ok();
}
/**
* 修改
*
* @param blogType
* @return
*/
@PostMapping("/update")
public BaseResult update(BlogType blogType) {
blogTypeService.update(blogType);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogTypeId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogTypeId) {
blogTypeService.delete(blogTypeId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogTypeId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogTypeId) {
BlogType blogType = blogTypeService.findById(blogTypeId);
return BaseResult.ok(blogType);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<BlogType> all = blogTypeService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<BlogType> brandPage = blogTypeService.search(search, page, size);
return BaseResult.ok(brandPage);
}
}
BlogVisibilityCon
@CrossOrigin
@RequestMapping("/back/blogVisibility")
@RestController
public class BlogVisibilityCon {
@Autowired
private BlogVisibilityService blogVisibilityService;
/**
* 新增
*
* @param blogVisibility
* @return
*/
@PostMapping("/add")
public BaseResult add(BlogVisibility blogVisibility) {
blogVisibilityService.add(blogVisibility);
return BaseResult.ok();
}
/**
* 修改
*
* @param blogVisibility
* @return
*/
@PostMapping("/update")
public BaseResult update(BlogVisibility blogVisibility) {
blogVisibilityService.update(blogVisibility);
return BaseResult.ok();
}
/**
* 删除
*
* @param blogVisibilityId
* @return
*/
@DeleteMapping("/delete")
public BaseResult delete(Integer blogVisibilityId) {
blogVisibilityService.delete(blogVisibilityId);
return BaseResult.ok();
}
/**
* 根据id查询
*
* @param blogVisibilityId
* @return
*/
@GetMapping("/findById")
public BaseResult findById(Integer blogVisibilityId) {
BlogVisibility blogVisibility = blogVisibilityService.findById(blogVisibilityId);
return BaseResult.ok(blogVisibility);
}
/**
* 查询所有
*
* @return
*/
@GetMapping("/findAll")
public BaseResult findAll() {
List<BlogVisibility> all = blogVisibilityService.findAll();
return BaseResult.ok(all);
}
/**
* 分页查询
*
* @param page
* @param size
* @return
*/
@GetMapping("/search")
public BaseResult search(String search, int page, int size) {
Page<BlogVisibility> blogVisibilityPage = blogVisibilityService.search(search, page, size);
return BaseResult.ok(blogVisibilityPage);
}
}