8、SpringBoot+Mybatis整合------参数取值方式

前言:

我们知道,在mybatis中,参数取值方式有两种:

#{ } 和 ${ }

下面,我们来探讨下#{ }与${ }不同。


一、#{ }

例:

select * from student where name=#{name}

编译后执行的sql语句:

select * from student where name=?

说明:

#{ }适合sql语句中的参数传值,构建sql语句#{ }是不可以的。

二、${ }

例:

select * from student where name=${name}

编译后执行的sql语句:

select * from student where name=name

说明:

${ }取参方式是简单的字符串拼接,不适合进行参数传值,不然会有sql语句注入的危险。

它更加适合的是构建sql语句。


                                                                                                  2018-07-03

猜你喜欢

转载自www.cnblogs.com/TimerHotel/p/springboot_matatis_08.html