mybatis @param的解释

来源:互联网 发布:窗帘轨道品牌 知乎 编辑:程序博客网 时间:2024/06/07 03:45

mybtis的数据库XML文件对参数的书写格式有两种

① SELECT * FROM tableName
  where time>=#{startTime}
 and time <=#{endTime}  order by time

SELECT * FROM tableName
  where time>= '${param1}'and time <= '${param1}' order by time


当你使用了使用@Param注解来声明参数时,如果使用 #{} 或 ${} 的方式都可以。

① SELECT * FROM tableName
  where time>=#{startTime}
 and time <=#{endTime}  order by time

② SELECT * FROM tableName
  where time>=${startTime}
 and time <=${endTime}  order by time


当你不使用@Param注解来声明参数时,必须使用使用 #{}方式。如果使用 ${} 的方式,会报错。

 SELECT * FROM tableName
  where time>=${startTime}
 and time <=${endTime}  order by time

0 0