输入banner图图片脚本导航/分类

带参sql$和#的区别

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$和#的区别

标签: