@MapperpublicinterfaceCommentMapper{intdeleteByPrimaryKey(Long id);@Insert("insert into comment(user_id,article_id,content,created_at)"+" values(#{userId},#{articleId},#{content},#{createdAt})")intinsert(Comment record);
List<Comment>selectAll();
List<Comment>queryComments(Long id);}
二、绑定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" ><mappernamespace="com.pang.dao.CommentMapper"><resultMapid="BaseResultMap"type="comment"><idcolumn="id"property="id"/><resultcolumn="user_id"property="userId"/><resultcolumn="article_id"property="articleId"/><resultcolumn="content"property="content"/><resultcolumn="created_at"property="createdAt"/><associationproperty="user"resultMap="com.pang.dao.UserMapper.BaseResultMap"><idcolumn="user_id"property="id"/></association></resultMap><deleteid="deleteByPrimaryKey"parameterType="java.lang.Long">
delete from comment
where id = #{id}
</delete><updateid="updateByPrimaryKey"parameterType="comment">
update comment
set user_id = #{userId},
article_id = #{articleId},
content = #{content},
created_at = #{createdAt}
where id = #{id}
</update><selectid="selectByPrimaryKey"resultMap="BaseResultMap"parameterType="java.lang.Long">
select id, user_id, article_id, content, created_at
from comment
where id = #{id}
</select><selectid="selectAll"resultMap="BaseResultMap">
select id, user_id, article_id, content, created_at
from comment
</select><selectid="queryComments"resultMap="BaseResultMap">
select c.id,
c.user_id,
c.article_id,
c.content,
c.created_at,
u.avatar,
u.nickname
from comment c
join user u on c.user_id = u.id
where c.article_id = #{id}
</select></mapper>