mybatis写sql注入参数的两种方式

mybatis写sql注入参数的两种方式

//mapper接口中当用到@注解时这样写
List<TopicInfo> selectUserTopics
(@Param("userId")int userId, @Param("keyword")String keyword);

mapper.xml中则这样写
<select id="selectUserTopics" resultMap="BaseResultMap">
 select t1.*
    from tms_topic_info t1,
    tms_topic_sysusers t2
    where t2.is_deleted = 0 and t1.id = t2.topic_id and t2.user_id =#{userId,jdbcType=INTEGER}
    <if test="keyword != null">
      and t1.topic_name like #{keyword,jdbcType=VARCHAR}
    </if>
    order by created_time desc
</select>

 //mypper接口中不使用@注解时
 //根据分类查询文章 文章id
 List<Map<String, Object>> selectArticleByCategory(Integer id);

<select id="selectArticleByCategory" parameterType="java.lang.Integer" resultType="java.util.Map">
   SELECT    t1.id as categoryId,
             t1.topic_id as topicId,
             t1.category_name as categoryName,
             t1.category_type as categoryType,
             t1.type as type,
             t2.id as categoryContentId,
             t3.id as contentId,
             t3.article_name as title,
             t3.introduce as introduce,
             t3.article_url as contentUrl,
             DATE_FORMAT(t2.created_time,'%y-%m-%d') as createdTime

     from    tms_category t1,
             tms_category_content t2,
             tms_article_info t3

     where
                t2.is_deleted = 0
            and t1.id = t2.category_id
            and t2.content_id = t3.id
            and t1.ct_parent = #{id}
     order by    t3.is_top desc, t3.created_time desc

 </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值