一、博客的主要功能模块
- 博客新增
- 博客查询
- 删除博客
- 编辑修改
- 搜索博客
老样子:实体类、控制层、持久层、业务层(接口和实现类)、mapper齐活
二、博客新增、查询
新增博客包括:标题、内容、分类、首图地址、博客描述、推荐、转载、赞赏、评论、原创等设置。
博客查询的内容包括:主键、标题、更新时间、是否推荐、是否发布、分类id、分类
1、博客查询实体类(BlogQuery)
public class BlogQuery {
private Long id;
private String title;
private Date updateTime;
private Boolean recommend;
private Boolean published;
private Long typeId;
private Type type;
}
2、持久层接口(BlogDao)
//保存新增博客
int saveBlog(Blog blog);
//查询文章管理列表
List<BlogQuery> getAllBlogQuery();
3、mapper
在mapper定义专门的resultMap用于映射多对一的关系
<!--新增保存文章-->
<insert id="saveBlog" parameterType="com.star.entity.Blog">
insert into myblog.t_blog (id,title, content, first_picture, flag,
views, comment_count, appreciation, share_statement, commentabled, published,
recommend, create_time, update_time, type_id, user_id, description)
values (#{id},#{title},#{content},#{firstPicture},#{flag},#{views},#{commentCount},#{appreciation},
#{shareStatement},#{commentabled},#{published},#{recommend},#{createTime},
#{updateTime},#{typeId},#{userId},#{description});
</insert>
<!--查询文章管理列表多对一配置-->
<resultMap id="blog" type="com.star.queryvo.BlogQuery">
<id property="id" column="id"/>
<result property="title" column="title"/>
<result property="updateTime" column="update_time"/>
<result property="recommend" column="recommend"/>
<result property="published" column="published"/>
<result property="typeId" column="type_id"/>
<association property="type" javaType="com.star.entity.Type