5.续Dao及MyBatis映射配置
发表于:2017-06-24 10:06:11 分类:博客源码 阅读:718次
5.CategoryMapper
package top.ersredma.blog.dao; import top.ersredma.blog.bean.Category; import javax.annotation.Resource; import java.util.List; @Resource public interface CategoryMapper { int deleteByPrimaryKey(Integer id); int insert(Category record); int insertSelective(Category record); Category selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Category record); int updateByPrimaryKey(Category record); List<Category> selectByUser(Integer user_id); }
6.CategoryMapper.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="top.ersredma.blog.dao.CategoryMapper" > <resultMap id="BaseResultMap" type="top.ersredma.blog.bean.Category" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="catname" property="catname" jdbcType="VARCHAR" /> <result column="user_id" property="userId" jdbcType="INTEGER" /> </resultMap> <sql id="Base_Column_List" > id, catname, user_id </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from category where id = #{id,jdbcType=INTEGER} </select> <select id="selectByUser" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from category where user_id = #{user_id,jdbcType=INTEGER} or id=1 </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from category where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="top.ersredma.blog.bean.Category" > insert into category (id, catname, user_id ) values (#{id,jdbcType=INTEGER}, #{catname,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER} ) </insert> <insert id="insertSelective" parameterType="top.ersredma.blog.bean.Category" > insert into category <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="catname != null" > catname, </if> <if test="userId != null" > user_id, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=INTEGER}, </if> <if test="catname != null" > #{catname,jdbcType=VARCHAR}, </if> <if test="userId != null" > #{userId,jdbcType=INTEGER}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="top.ersredma.blog.bean.Category" > update category <set > <if test="catname != null" > catname = #{catname,jdbcType=VARCHAR}, </if> <if test="userId != null" > user_id = #{userId,jdbcType=INTEGER}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="top.ersredma.blog.bean.Category" > update category set catname = #{catname,jdbcType=VARCHAR}, user_id = #{userId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> </mapper>
7.CommentMapper
package top.ersredma.blog.dao; import top.ersredma.blog.anotations.AntiXSS; import top.ersredma.blog.bean.Comment; import javax.annotation.Resource; import java.util.List; @Resource public interface CommentMapper { int deleteByPrimaryKey(Integer id); @AntiXSS int insert(Comment record); int insertSelective(Comment record); Comment selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Comment record); int updateByPrimaryKey(Comment record); List<Comment> selectByEssay(Integer essay_id); }
8.CommentMapper.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="top.ersredma.blog.dao.CommentMapper" > <resultMap id="BaseResultMap" type="top.ersredma.blog.bean.Comment" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="content" property="content" jdbcType="VARCHAR" /> <result column="user_id" property="userId" jdbcType="VARCHAR" /> <result column="essay_id" property="essayId" jdbcType="INTEGER" /> <result column="time" property="time" jdbcType="INTEGER" /> <result column="state" property="state" jdbcType="INTEGER" /> </resultMap> <sql id="Base_Column_List" > id, content, user_id, essay_id, time, state </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from comment where id = #{id,jdbcType=INTEGER} </select> <select id="selectByEssay" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from comment where essay_id = #{essay_id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from comment where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="top.ersredma.blog.bean.Comment" > insert into comment (id, content, user_id, essay_id, time, state ) values (#{id,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{essayId,jdbcType=INTEGER}, #{time,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER} ) </insert> <insert id="insertSelective" parameterType="top.ersredma.blog.bean.Comment" > insert into comment <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="content != null" > content, </if> <if test="userId != null" > user_id, </if> <if test="essayId != null" > essay_id, </if> <if test="time != null" > time, </if> <if test="state != null" > state, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=INTEGER}, </if> <if test="content != null" > #{content,jdbcType=VARCHAR}, </if> <if test="userId != null" > #{userId,jdbcType=VARCHAR}, </if> <if test="essayId != null" > #{essayId,jdbcType=INTEGER}, </if> <if test="time != null" > #{time,jdbcType=VARCHAR}, </if> <if test="state != null" > #{state,jdbcType=INTEGER}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="top.ersredma.blog.bean.Comment" > update comment <set > <if test="content != null" > content = #{content,jdbcType=VARCHAR}, </if> <if test="userId != null" > user_id = #{userId,jdbcType=VARCHAR}, </if> <if test="essayId != null" > essay_id = #{essayId,jdbcType=INTEGER}, </if> <if test="time != null" > time = #{time,jdbcType=VARCHAR}, </if> <if test="state != null" > state = #{state,jdbcType=INTEGER}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="top.ersredma.blog.bean.Comment" > update comment set content = #{content,jdbcType=VARCHAR}, user_id = #{userId,jdbcType=VARCHAR}, essay_id = #{essayId,jdbcType=INTEGER}, time = #{time,jdbcType=VARCHAR}, state = #{state,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> </mapper>
9.KeywordMapper
package top.ersredma.blog.dao; import top.ersredma.blog.bean.KeyWord; import java.util.List; public interface KeyWordMapper { int insert(KeyWord record); List<KeyWord> selectTop10(); }
10.KeywordMapper.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="top.ersredma.blog.dao.KeyWordMapper" > <resultMap id="BaseResultMap" type="top.ersredma.blog.bean.KeyWord" > <result column="essay_id" property="essayId" jdbcType="INTEGER" /> <result column="keyword" property="keyword" jdbcType="VARCHAR" /> </resultMap> <insert id="insert" parameterType="top.ersredma.blog.bean.KeyWord" > insert into keyword (essay_id, keyword) values (#{essayId,jdbcType=INTEGER}, #{keyword,jdbcType=VARCHAR}) </insert> <select id="selectTop10" resultType="top.ersredma.blog.bean.KeyWord"> SELECT kw.essay_id essay_id, kw.keyword keyword ,COUNT(*) counts FROM keyword kw WHERE kw.keyword IN (SELECT keyword FROM keyword) GROUP BY keyword ORDER BY counts DESC LIMIT 10 </select> </mapper>
关键词:blog源码,dao