博客中的文章归档是如何实现的
发布时间:2020-12-14 18:06:01 所属栏目:大数据 来源:网络整理
导读:我的效果图如下(这个是我实现的): wordpress的效果图如下: sql代码: SELECT DISTINCT YEAR(post.post_modified)AS `year`,MONTH(post.post_modified) AS `month` FROM wp_posts AS post xml代码: ?xml version= " 1.0 " encoding= UTF-8 " ?!DOCTYPE mapper
我的效果图如下(这个是我实现的): wordpress的效果图如下: sql代码: SELECT DISTINCT YEAR(post.post_modified)AS `year`,MONTH(post.post_modified) AS `month` FROM wp_posts AS post 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=com.blog.springboot.dao.PostsDao"> <!-- 通用查询映射结果 --> <resultMap id=BaseResultMap" type=com.blog.springboot.entity.Posts"> <id column=ID" property=id" /> <result column=post_authorpostAuthorpost_datepostDatepost_date_gmtpostDateGmtpost_contentpostContentpost_titlepostTitlepost_excerptpostExcerptpost_statuspostStatuscomment_statuscommentStatusping_statuspingStatuspost_passwordpostPasswordpost_namepostNameto_pingtoPingpingedpost_modifiedpostModifiedpost_modified_gmtpostModifiedGmtpost_content_filteredpostContentFilteredpost_parentpostParentguidmenu_ordermenuOrderpost_typepostTypepost_mime_typepostMimeTypecomment_countcommentCountyear"/> <result column=month"/> </resultMap> <!-- 通用查询结果列 --> <sql id=Base_Column_List" > ID AS id,post_author AS postAuthor,post_date AS postDate,post_date_gmt AS postDateGmt,post_content AS postContent,post_title AS postTitle,post_excerpt AS postExcerpt,post_status AS postStatus,comment_status AS commentStatus,ping_status AS pingStatus,post_password AS postPassword,post_name AS postName,to_ping AS toPing,pinged,post_modified AS postModified,post_modified_gmt AS postModifiedGmt,post_content_filtered AS postContentFiltered,post_parent AS postParent,guid,menu_order AS menuOrder,post_type AS postType,post_mime_type AS postMimeType,comment_count AS commentCount </sql> <!-- 文章归档 --> <select id=articleArchive" resultMap="> SELECT DISTINCT YEAR(post.post_modified)AS `year`,MONTH(post.post_modified) AS `month` FROM wp_posts AS post </select> </mapper> 实体: package com.blog.springboot.entity; import java.io.Serializable; import java.util.List; import com.baomidou.mybatisplus.activerecord.Model; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; @TableName(wp_posts") public class Posts extends Model<Posts> { private static final long serialVersionUID = 1L; @TableId(value = ",type = IdType.AUTO) private Integer id; @TableField() Long postAuthor; @TableField( String postDate; @TableField( String postDateGmt; @TableField( String postContent; @TableField( String postTitle; @TableField( String postExcerpt; @TableField( String postStatus; @TableField( String commentStatus; @TableField( String pingStatus; @TableField( String postPassword; @TableField( String postName; @TableField( String toPing; String pinged; @TableField( String postModified; @TableField( String postModifiedGmt; @TableField( String postContentFiltered; @TableField( Long postParent; String guid; @TableField( Integer menuOrder; @TableField( String postType; @TableField( String postMimeType; @TableField( Integer commentCount; @TableField(exist=falseprivate List<TermTaxonomy> termTaxonomy; @TableField(exist=private List<Terms> terms; @TableField(exist=private List<Users> users; @TableField( String year; @TableField( String month; public String getMonth() { return month; } void setMonth(String month) { this.month = String getYear() { year; } setYear(String year) { this.year = year; } public List<Users> getUsers() { users; } void setUsers(List<Users> users) { this.users =public List<TermTaxonomy> getTermTaxonomy() { termTaxonomy; } void setTermTaxonomy(List<TermTaxonomy> termTaxonomy) { this.termTaxonomy =public List<Terms> getTerms() { terms; } void setTerms(List<Terms> terms) { this.terms = Integer getId() { id; } setId(Integer id) { this.id = Long getPostAuthor() { postAuthor; } setPostAuthor(Long postAuthor) { this.postAuthor = String getPostDate() { postDate; } setPostDate(String postDate) { this.postDate = String getPostDateGmt() { postDateGmt; } setPostDateGmt(String postDateGmt) { this.postDateGmt = String getPostContent() { postContent; } setPostContent(String postContent) { this.postContent = String getPostTitle() { postTitle; } setPostTitle(String postTitle) { this.postTitle = String getPostExcerpt() { postExcerpt; } setPostExcerpt(String postExcerpt) { this.postExcerpt = String getPostStatus() { postStatus; } setPostStatus(String postStatus) { this.postStatus = String getCommentStatus() { commentStatus; } setCommentStatus(String commentStatus) { this.commentStatus = String getPingStatus() { pingStatus; } setPingStatus(String pingStatus) { this.pingStatus = String getPostPassword() { postPassword; } setPostPassword(String postPassword) { this.postPassword = String getPostName() { postName; } setPostName(String postName) { this.postName = String getToPing() { toPing; } setToPing(String toPing) { this.toPing = String getPinged() { pinged; } setPinged(String pinged) { this.pinged = String getPostModified() { postModified; } setPostModified(String postModified) { this.postModified = String getPostModifiedGmt() { postModifiedGmt; } setPostModifiedGmt(String postModifiedGmt) { this.postModifiedGmt = String getPostContentFiltered() { postContentFiltered; } setPostContentFiltered(String postContentFiltered) { this.postContentFiltered = Long getPostParent() { postParent; } setPostParent(Long postParent) { this.postParent = String getGuid() { guid; } setGuid(String guid) { this.guid = Integer getMenuOrder() { menuOrder; } setMenuOrder(Integer menuOrder) { this.menuOrder = String getPostType() { postType; } setPostType(String postType) { this.postType = String getPostMimeType() { postMimeType; } setPostMimeType(String postMimeType) { this.postMimeType = Integer getCommentCount() { commentCount; } setCommentCount(Integer commentCount) { this.commentCount = commentCount; } @Override protected Serializable pkVal() { return this.id; } @Override String toString() { return Posts{" + ,id=" + id + " + postAuthor + " + postDate + " + postDateGmt + " + postContent + " + postTitle + " + postExcerpt + " + postStatus + " + commentStatus + " + pingStatus + " + postPassword + " + postName + " + toPing + " + pinged + " + postModified + " + postModifiedGmt + " + postContentFiltered + " + postParent + " + guid + " + menuOrder + " + postType + " + postMimeType + " + commentCount + }; } } dao代码: package com.blog.springboot.dao; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.blog.springboot.entity.Posts; interface PostsDao extends BaseMapper<Posts> { //文章归档 public List<Posts> articleArchive(); } service代码: interface PostsService extends IService<Posts> articleArchive(); } 实现类: package com.blog.springboot.service.impl; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.blog.springboot.dao.PostsDao; import com.blog.springboot.entity.Posts; import com.blog.springboot.service.PostsService; @Service class PostsServiceImpl extends ServiceImpl<PostsDao,Posts> implements PostsService { @Autowired PostsDao postDao; @Override articleArchive() { postDao.articleArchive(); } } 后台Controller: /** * 文章归档 * @return */ @GetMapping(value=/articleArchive JSONObject writePost() { List<Posts> post = postService.articleArchive(); if(!post.isEmpty()) { json.put(code000000); json.put(msg获取文章归档postelse { json.put(222222暂无文章归档); } json; } 前端js实现: 文章归档 function articleArchive(){ $.ajax({ url: Blog.url.api.articleArchive,type: GET'json'var rows = ""; $.each(data.post,function(index,post) { var year = post.year+年; var month = post.month+月var date = year + month; rows= rows +; rows= rows +<li><a href='#'>"+date+</a></li><hr/>; }); $(#articleArchive).html(rows); },error: function(XMLHttpRequest,textStatus,errorThrown) { console.log(XMLHttpRequest.status); console.log(XMLHttpRequest.readyState); console.log(textStatus); } }); } ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |