首页 技术 正文
技术 2022年11月19日
0 收藏 968 点赞 2,518 浏览 1316 个字

通常来说,参数传递可以使用#与$进行编写,但是使用#的效率更高,使用$方式,查看日志更方便些,尤其是当执行的sql语句非常麻烦的时候.

1) 接口 形式 以下方式 [传递参数是一个实体]

public List<Attachment> getAttachment(Attachment query);

xml文件配置如下

<select id="getAttachment"  resultMap="baseMap">
SELECT
<include refid="columns"/>
FROM
T_OA_ATTACH atta
WHERE 1 = 1
<if test="name != null and name !='' ">
AND atta.NAME like '%'||#{name,jdbcType=VARCHAR}||'%'
</if>
<if test="type != null and type !='' ">
AND atta.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="path != null and path !='' ">
AND atta.PATH = #{path,jdbcType=VARCHAR}
</if>
<if test="createUser != null and createUser !='' ">
AND atta.CREATE_BY = #{createUser,jdbcType=BIGINT}
</if>
</select>

2) 接口形如以下方式 [传递参数是基本类型数据]

@Update("UPDATE T_OA_ATTACH SET STATUS = '0' WHERE ID = #{id} ")
public int delAttachment(@Param("id") Long id);

上面为annotation配置方式

xml配置如下,其中,使用$的时候,控制台打印的sql语句,语句不会使用?作为占位符

<if test="id!= null and id!='' ">
AND atta.id= #{id,jdbcType=BIGINT}
</if>或者如下
<if test="id!= null and id!='' ">
AND atta.id= ${id}
</if>

2) 接口形如以下方式 [传递参数是基本类型数据 和 对象]

public List<MyScheduling> getMyWapScheduling(@Param("curUserId")Long currentUserId,@Param("queryDayFirst")String dayFirst,@Param("query")MyScheduling query);

此时,需要使用@Param修饰参数变量,同时,对象中的参数,需要使用对象值进行前缀引导,否则绑定不了变量

and d.period_rq between to_date('${queryDayFirst}', 'yyyymmdd') and last_day(to_date('${queryDayFirst}', 'yyyymmdd'))<if test="query.pId != null and query.pId !='' ">
and a2.p_id = #{query.pId,jdbcType=BIGINT}
</if>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295