当前位置:Gxlcms > 数据库问题 > 带参sql$和#的区别

带参sql$和#的区别

时间:2021-07-01 10:21:17 帮助过:68人阅读

public User getUser(@Param("id")long id);

@Select("select id,name from user where id=${id}")
public User getUSer(@Param("id")long id);

如果id传入为1,则实际sql为

select id,name from user where id=‘1‘

select id,name from user where id=1

Mybaits方法有一种情况

@Select("select id,name from user where id=#{id}")
public User getUser(@Param("id") long id);

@Select("select id,name from user where id=#{id}")
public User getUser(long id);

以上两种都可以,因为传一个参数是可以省略@Param("")的,但是这种情况下不能使用${},

传两个参数以上时,必须要写@Param("")

 

带参sql$和#的区别

标签:

人气教程排行