mybatis增加cache

This commit is contained in:
shuzheng 2016-10-18 17:32:15 +08:00
parent 15ad1b8d94
commit 2de8d5e2fd
21 changed files with 344 additions and 2 deletions

View File

@ -184,4 +184,5 @@
name = #{name,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -186,4 +186,5 @@
category_id = #{categoryId,jdbcType=INTEGER}
where article_category_id = #{articleCategoryId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -469,4 +469,5 @@
orders = #{orders,jdbcType=BIGINT}
where article_id = #{articleId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -186,4 +186,5 @@
tag_id = #{tagId,jdbcType=INTEGER}
where article_tag_id = #{articleTagId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -293,4 +293,5 @@
orders = #{orders,jdbcType=BIGINT}
where category_id = #{categoryId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -186,4 +186,5 @@
tag_id = #{tagId,jdbcType=INTEGER}
where category_tag_id = #{categoryTagId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -328,4 +328,5 @@
ctime = #{ctime,jdbcType=BIGINT}
where comment_id = #{commentId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -263,4 +263,5 @@
orders = #{orders,jdbcType=BIGINT}
where tag_id = #{tagId,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -292,4 +292,5 @@
ctime = #{ctime,jdbcType=BIGINT}
where id = #{id,jdbcType=INTEGER}
</update>
<cache eviction="LRU" flushInterval="60000" readOnly="true" size="1024" />
</mapper>

View File

@ -47,4 +47,31 @@ public class Book implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Book other = (Book) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUserid() == null ? other.getUserid() == null : this.getUserid().equals(other.getUserid()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUserid() == null) ? 0 : getUserid().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result;
}
}

View File

@ -201,4 +201,59 @@ public class CmsArticle implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsArticle other = (CmsArticle) that;
return (this.getArticleId() == null ? other.getArticleId() == null : this.getArticleId().equals(other.getArticleId()))
&& (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
&& (this.getAuthor() == null ? other.getAuthor() == null : this.getAuthor().equals(other.getAuthor()))
&& (this.getFromurl() == null ? other.getFromurl() == null : this.getFromurl().equals(other.getFromurl()))
&& (this.getImage() == null ? other.getImage() == null : this.getImage().equals(other.getImage()))
&& (this.getKeywords() == null ? other.getKeywords() == null : this.getKeywords().equals(other.getKeywords()))
&& (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getAllowcomments() == null ? other.getAllowcomments() == null : this.getAllowcomments().equals(other.getAllowcomments()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getUp() == null ? other.getUp() == null : this.getUp().equals(other.getUp()))
&& (this.getDown() == null ? other.getDown() == null : this.getDown().equals(other.getDown()))
&& (this.getReadnumber() == null ? other.getReadnumber() == null : this.getReadnumber().equals(other.getReadnumber()))
&& (this.getCtime() == null ? other.getCtime() == null : this.getCtime().equals(other.getCtime()))
&& (this.getOrders() == null ? other.getOrders() == null : this.getOrders().equals(other.getOrders()))
&& (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getArticleId() == null) ? 0 : getArticleId().hashCode());
result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
result = prime * result + ((getAuthor() == null) ? 0 : getAuthor().hashCode());
result = prime * result + ((getFromurl() == null) ? 0 : getFromurl().hashCode());
result = prime * result + ((getImage() == null) ? 0 : getImage().hashCode());
result = prime * result + ((getKeywords() == null) ? 0 : getKeywords().hashCode());
result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getAllowcomments() == null) ? 0 : getAllowcomments().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getUp() == null) ? 0 : getUp().hashCode());
result = prime * result + ((getDown() == null) ? 0 : getDown().hashCode());
result = prime * result + ((getReadnumber() == null) ? 0 : getReadnumber().hashCode());
result = prime * result + ((getCtime() == null) ? 0 : getCtime().hashCode());
result = prime * result + ((getOrders() == null) ? 0 : getOrders().hashCode());
result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
return result;
}
}

View File

@ -47,4 +47,31 @@ public class CmsArticleCategory implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsArticleCategory other = (CmsArticleCategory) that;
return (this.getArticleCategoryId() == null ? other.getArticleCategoryId() == null : this.getArticleCategoryId().equals(other.getArticleCategoryId()))
&& (this.getArticleId() == null ? other.getArticleId() == null : this.getArticleId().equals(other.getArticleId()))
&& (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getArticleCategoryId() == null) ? 0 : getArticleCategoryId().hashCode());
result = prime * result + ((getArticleId() == null) ? 0 : getArticleId().hashCode());
result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
return result;
}
}

View File

@ -47,4 +47,31 @@ public class CmsArticleTag implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsArticleTag other = (CmsArticleTag) that;
return (this.getArticleTagId() == null ? other.getArticleTagId() == null : this.getArticleTagId().equals(other.getArticleTagId()))
&& (this.getArticleId() == null ? other.getArticleId() == null : this.getArticleId().equals(other.getArticleId()))
&& (this.getTagId() == null ? other.getTagId() == null : this.getTagId().equals(other.getTagId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getArticleTagId() == null) ? 0 : getArticleTagId().hashCode());
result = prime * result + ((getArticleId() == null) ? 0 : getArticleId().hashCode());
result = prime * result + ((getTagId() == null) ? 0 : getTagId().hashCode());
return result;
}
}

View File

@ -124,4 +124,45 @@ public class CmsCategory implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsCategory other = (CmsCategory) that;
return (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()))
&& (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid()))
&& (this.getLevel() == null ? other.getLevel() == null : this.getLevel().equals(other.getLevel()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
&& (this.getIcon() == null ? other.getIcon() == null : this.getIcon().equals(other.getIcon()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getAlias() == null ? other.getAlias() == null : this.getAlias().equals(other.getAlias()))
&& (this.getCtime() == null ? other.getCtime() == null : this.getCtime().equals(other.getCtime()))
&& (this.getOrders() == null ? other.getOrders() == null : this.getOrders().equals(other.getOrders()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode());
result = prime * result + ((getLevel() == null) ? 0 : getLevel().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
result = prime * result + ((getIcon() == null) ? 0 : getIcon().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getAlias() == null) ? 0 : getAlias().hashCode());
result = prime * result + ((getCtime() == null) ? 0 : getCtime().hashCode());
result = prime * result + ((getOrders() == null) ? 0 : getOrders().hashCode());
return result;
}
}

View File

@ -47,4 +47,31 @@ public class CmsCategoryTag implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsCategoryTag other = (CmsCategoryTag) that;
return (this.getCategoryTagId() == null ? other.getCategoryTagId() == null : this.getCategoryTagId().equals(other.getCategoryTagId()))
&& (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()))
&& (this.getTagId() == null ? other.getTagId() == null : this.getTagId().equals(other.getTagId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getCategoryTagId() == null) ? 0 : getCategoryTagId().hashCode());
result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
result = prime * result + ((getTagId() == null) ? 0 : getTagId().hashCode());
return result;
}
}

View File

@ -113,4 +113,43 @@ public class CmsComment implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsComment other = (CmsComment) that;
return (this.getCommentId() == null ? other.getCommentId() == null : this.getCommentId().equals(other.getCommentId()))
&& (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid()))
&& (this.getArticleId() == null ? other.getArticleId() == null : this.getArticleId().equals(other.getArticleId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getIp() == null ? other.getIp() == null : this.getIp().equals(other.getIp()))
&& (this.getAgent() == null ? other.getAgent() == null : this.getAgent().equals(other.getAgent()))
&& (this.getCtime() == null ? other.getCtime() == null : this.getCtime().equals(other.getCtime()))
&& (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getCommentId() == null) ? 0 : getCommentId().hashCode());
result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode());
result = prime * result + ((getArticleId() == null) ? 0 : getArticleId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode());
result = prime * result + ((getAgent() == null) ? 0 : getAgent().hashCode());
result = prime * result + ((getCtime() == null) ? 0 : getCtime().hashCode());
result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
return result;
}
}

View File

@ -102,4 +102,41 @@ public class CmsTag implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CmsTag other = (CmsTag) that;
return (this.getTagId() == null ? other.getTagId() == null : this.getTagId().equals(other.getTagId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
&& (this.getIcon() == null ? other.getIcon() == null : this.getIcon().equals(other.getIcon()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getAlias() == null ? other.getAlias() == null : this.getAlias().equals(other.getAlias()))
&& (this.getCtime() == null ? other.getCtime() == null : this.getCtime().equals(other.getCtime()))
&& (this.getOrders() == null ? other.getOrders() == null : this.getOrders().equals(other.getOrders()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getTagId() == null) ? 0 : getTagId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
result = prime * result + ((getIcon() == null) ? 0 : getIcon().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getAlias() == null) ? 0 : getAlias().hashCode());
result = prime * result + ((getCtime() == null) ? 0 : getCtime().hashCode());
result = prime * result + ((getOrders() == null) ? 0 : getOrders().hashCode());
return result;
}
}

View File

@ -91,4 +91,39 @@ public class User implements Serializable {
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
User other = (User) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
&& (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
&& (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname()))
&& (this.getSex() == null ? other.getSex() == null : this.getSex().equals(other.getSex()))
&& (this.getCtime() == null ? other.getCtime() == null : this.getCtime().equals(other.getCtime()))
&& (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode());
result = prime * result + ((getSex() == null) ? 0 : getSex().hashCode());
result = prime * result + ((getCtime() == null) ? 0 : getCtime().hashCode());
result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
return result;
}
}

View File

@ -27,6 +27,17 @@
<!-- 生成一个新的selectByExample方法这个方法可以接受一个RowBounds参数主要用来实现分页 -->
<plugin type="com.zheng.common.plugin.PaginationPlugin"></plugin>
<!-- 生成在XML中的<cache>元素 -->
<plugin type="org.mybatis.generator.plugins.CachePlugin">
<property name="cache_eviction" value="LRU" />
<property name="cache_flushInterval" value="60000" />
<property name="cache_readOnly" value="true" />
<property name="cache_size" value="1024" />
</plugin>
<!-- Java模型生成equals和hashcode方法 -->
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
<!-- 生成的代码去掉注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />

View File

@ -4,6 +4,11 @@
<configuration>
<!-- 全局配置 -->
<settings>
<setting name="cacheEnabled" value="true"/>
</settings>
<!-- 该包下的model不用写包名会使用 model的首字母小写的非限定类名来作为它的别名若有注解@Alias("xxx"),则别名为注解值 -->
<typeAliases>
<package name="com.zheng.cms.dao.model" />

View File

@ -21,7 +21,7 @@ public class PaginationPlugin extends PluginAdapter {
}
/**
* 为每个Example类添加limit和offset属性已经setget方法
* 为每个Example类添加limit和offset属性setget方法
*/
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
@ -72,7 +72,7 @@ public class PaginationPlugin extends PluginAdapter {
}
/**
* 为Mapper.xml的selectByExample添加limit
* 为Mapper.xml的selectByExample添加limit,offset
*/
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element,
@ -96,4 +96,6 @@ public class PaginationPlugin extends PluginAdapter {
return true;
}
}