/*点击次数处理*/
@Override
public Article updateClick(String oldurl) {
System.out.println(oldurl);
String url="/static/template/"+oldurl;
Article article = mapper.findByURL(url);
article.setClickCount(article.getClickCount()+1);
/*把数据库的点击数也要修改并且回显*/
mapper.update(article);
System.out.println(article);
return article;
}
}
文章管理实现类会调用的mapper
package cn.itsource.mapper;
import java.util.List;
import cn.itsource.domain.Article;
import cn.itsource.query.IArticleQuery;
public interface Articlemapper {
List<Article> findAll(IArticleQuery query);
Integer findTotalCount(IArticleQuery query);
void delete(Long id);
List<Article> findArticleByCode(String constant);
void add(Article article);
void update(Article article);
Article findOne(Long id);
void del(Long id);
Article findById(Long id);
Article findByURL(String url);
}
文章管理mapper映射文件
<?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的主要功能就是写sql
mapper:根
namespace:命令空间 (用来确定唯一)以前这个是可以不加的,现在必需加
namespace的值:接口的完全限定名
-->
<mapper namespace="cn.itsource.mapper.Articlemapper">
<!-- void update(Article article);修改 -->
<update parameterType="Article">
update t_article set url=#{url},clickCount=#{clickCount},title=#{title},typeId=#{typeId},enable=#{enable},content=#{content},createDate=#{createDate} where id=#{id}
</update>
<!-- void add(Article article);添加 -->
<insert parameterType="Article">
insert into t_article (title,typeId,enable,url,content,createDate)
values (#{title},#{typeId},#{enable},#{url},#{content},#{createDate})
</insert>
<!-- void delete(Long id);删除 -->
<delete>
delete from t_article where id=#{id}
</delete>
<select resultType="int" parameterType="ArticleQuery">
select count(id) from t_article
<include refid="query"></include>
</select>
<!-- List<Article> findAll(ArticleQuery query); -->
<select resultType="Article" parameterType="ArticleQuery">
select * from t_article
<include refid="query"></include><!-- 先高级查询然后在分页 -->
limit #{begin},#{pageSize}
</select>
<sql>
<where>
<if test="typeId != null">
and typeId = #{typeId}
</if>
<if test="enable != null">
and enable = #{enable}
</if>
<!-- test里面的写法是ognl表达式,trim()是ognl语法:去掉两端的空白 -->
<if test="title != null and '' != title.trim()">
<!-- concat是mysql的函数:用于拼接字符串的 -->
and title like concat('%',trim(#{title}),'%')
</if>
</where>
</sql>
<!-- Article findByURL(String url); 根据url查找Article-->
<select resultType="article">
select * from t_Article where url=#{url}
</select>
<!-- List<Article> findArticleByCode(String constant); -->
<select resultType="article">
SELECT * FROM t_article t1
INNER JOIN t_article_type t2 on t1.typeId=t2.id
WHERE t1.`enable`=1 and t2.code=#{constant}
ORDER BY t1.createDate desc
LIMIT 0,8
</select>
<!--Article findById(Long id);-->
<select parameterType="long" resultType="article">
select * from t_article where id = #{id}
</select>
<!-- Article findOne(Long id); -->
<select parameterType="long" resultType="article">
select * from t_article where id = #{id}
</select>
</mapper>
功能模块:
后台高级查询,后台crud,添加运用到freemark
业务流程:
项目资源布局: