xml中使用常量
yml文件中
imgLoc=http://127.0.0.1:8080/app/public/img/icon.png
常量类中
@Component
public class Constant {
@Value("${imgLoc}")
String imgLoc;
}
xml语法中
<sql id="baseConsts">
<bind name="DEFAULT_PIC" value="@com.zmd.sys.constants.Constant@imgLoc"/>
</sql>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
a.order_discuss_id AS "orderDiscussId",
a.order_id AS "orderId"
</sql>
<select id="orders">
<include refid="baseConsts" />
select #{imgLoc} imgLoc, <include refid="Base_Column_List" /> from orders
</select>
一对多写法1
@Select("select img from jc_img where is_del = 0 and content_id = #{contentId}")
List<Integer> img(@Param("contentId")Integer contentId);
@Select("select channel_id from jc_channel where is_del = 0 and content_id = #{contentId}")
List<Integer> channel(@Param("contentId")Integer contentId);
<resultMap id="ResultMap" type="com.zmd.sys.vo.content.response.ContentListResponse">
<association property="imgPaths" column="content_id" select="com.zmd.sys.mapper.content.ContentPictureMapper.img"/>
<association property="channels" column="content_id" select="com.zmd.sys.mapper.channel.ChannelMapper.channel"/>
</resultMap>
<select id="contentList" resultMap="ResultMap">
select a.content_id contentId,a.content_id from jc_content
</select>
一对多写法2
//查询 文章详情
@Results({
@Result(property = "imgPaths",column = "content_id",many = @Many(select = "com.zmd.sys.mapper.content.ContentPictureMapper.selectImgPathByContentId")),
@Result(property = "channel",column = "content_id",many = @Many(select = "com.zmd.sys.mapper.content.ContentChannelMapper.selectChannelIdsByContentId")),
@Result(property = "area",column = "content_id",many = @Many(select = "com.zmd.sys.mapper.content.ContentAreaMapper.selectAreaIdsByContentId"))
})
@Select("select a.content_id contentId,a.content_id,a.status,b.author_name,b.origin,b.title,b.short_title,b.title_img," +
"b.media_times,b.media_path,b.characters,b.release_date,c.txt text " +
"from jc_content a " +
"left join jc_content_ext b on a.content_id=b.content_id " +
"left join jc_content_txt c on a.content_id=c.content_id " +
"where a.content_id=#{contentId}")
SysContentDetailResponse detailContentById(@Param("contentId") Integer contentId);
if 语法 choose when otherwise(=else if)语法 foreach语法
<if test="param.channelId != null and param.channelId !='' ">
<choose>
<when test="param.isSubChannel == 1">
and d.channel_id in
<foreach collection="channels" item="channelId" index="index" open="(" close=")" separator=",">
#{channelId}
</foreach>
</when>
<otherwise>
and d.channel_id=#{param.channelId}
</otherwise>
</choose>
</if>
文章永久链接:https://tech.souyunku.com/19353