2017-08-15 09:47:18 +07:00
|
|
|
<?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.application.article.ArticleReadService">
|
2017-08-15 15:36:07 +07:00
|
|
|
<sql id="profileColumns">
|
|
|
|
U.id userId,
|
|
|
|
U.username userUsername,
|
|
|
|
U.bio userBio,
|
|
|
|
U.image userImage
|
|
|
|
</sql>
|
2017-08-15 10:21:55 +07:00
|
|
|
<sql id="selectArticleData">
|
2017-08-15 09:47:18 +07:00
|
|
|
select
|
2017-08-15 10:21:55 +07:00
|
|
|
A.id articleId,
|
|
|
|
A.slug articleSlug,
|
|
|
|
A.title articleTitle,
|
|
|
|
A.description articleDescription,
|
|
|
|
A.body articleBody,
|
|
|
|
A.created_at articleCreatedAt,
|
|
|
|
A.updated_at articleUpdatedAt,
|
|
|
|
T.name as tagName,
|
2017-08-15 15:36:07 +07:00
|
|
|
<include refid="profileColumns"/>
|
2017-08-15 09:47:18 +07:00
|
|
|
from
|
2017-08-15 10:21:55 +07:00
|
|
|
articles A
|
|
|
|
left join article_tags AT on A.id = AT.article_id
|
|
|
|
left join tags T on T.id = AT.article_id
|
|
|
|
left join users U on U.id = A.user_id
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
<select id="findById" resultMap="articleData">
|
|
|
|
<include refid="selectArticleData"/>
|
2017-08-15 09:47:18 +07:00
|
|
|
where A.id = #{id}
|
|
|
|
</select>
|
2017-08-15 10:21:55 +07:00
|
|
|
<select id="findBySlug" resultMap="articleData">
|
|
|
|
<include refid="selectArticleData"/>
|
|
|
|
where A.slug = #{slug}
|
|
|
|
</select>
|
2017-08-15 09:47:18 +07:00
|
|
|
|
|
|
|
<resultMap id="articleData" type="io.spring.application.article.ArticleData">
|
|
|
|
<id column="articleId" property="id"/>
|
|
|
|
<result column="articleSlug" property="slug"/>
|
|
|
|
<result column="articleTitle" property="title"/>
|
|
|
|
<result column="articleDescription" property="description"/>
|
|
|
|
<result column="articleBody" property="body"/>
|
|
|
|
<result column="articleCreatedAt" property="createdAt"/>
|
|
|
|
<result column="articleUpdatedAt" property="updatedAt"/>
|
|
|
|
<association property="profileData" resultMap="profileData"/>
|
|
|
|
<collection property="tagList" ofType="arraylist" column="tagName" javaType="string"/>
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
<resultMap id="profileData" type="io.spring.application.profile.ProfileData">
|
|
|
|
<id column="userId" property="id"/>
|
|
|
|
<result column="userUsername" property="username"/>
|
|
|
|
<result column="userBio" property="bio"/>
|
|
|
|
<result column="userImage" property="image"/>
|
|
|
|
</resultMap>
|
|
|
|
</mapper>
|