在Mybatis中,@Select注解可以使用参数来传递参数。有两种方式可以传递参数:
@Select("SELECT * FROM users WHERE id = #{userId}")
User getUserById(int userId);
@Select("SELECT * FROM users WHERE id = #{userId}")
User getUserById(@Param("userId") int userId);
这样就可以在@Select注解中传递参数。需要注意的是,在使用@Param注解时,需要注意参数名与@Param注解中的value值要一致。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:mybatis怎么传递多个参数