spring-boot-realworld-examp.../src/main/resources/mapper/CommentMapper.xml
2017-08-18 17:08:27 +08:00

35 lines
1.3 KiB
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="io.spring.infrastructure.mybatis.mapper.CommentMapper">
<insert id="insert">
insert into comments(id, body, user_id, article_id, created_at, updated_at)
values (
#{comment.id},
#{comment.body},
#{comment.userId},
#{comment.articleId},
#{comment.createdAt},
#{comment.createdAt}
)
</insert>
<delete id="delete">
delete from comments where id = #{id}
</delete>
<select id="findById" resultMap="comment">
select
id commentId,
body commentBody,
user_id commentUserId,
article_id commentArticleId,
created_at commentCreatedAt
from comments
where id = #{id} and article_id = #{articleId}
</select>
<resultMap id="comment" type="io.spring.core.comment.Comment">
<id column="commentId" property="id"/>
<result column="commentBody" property="body"/>
<result column="commentUserId" property="userId"/>
<result column="commentArticleId" property="articleId"/>
<result column="commentCreatedAt" property="createdAt"/>
</resultMap>
</mapper>