专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

mybatis常用写法

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

未经允许不得转载:搜云库技术团队 » mybatis常用写法

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们