您的位置:宽带测速网 > 编程知识 > mybatis多个参数查询的方法是什么

mybatis多个参数查询的方法是什么

2025-06-17 15:28来源:互联网 [ ]

在MyBatis中,可以使用@Param注解或者Map对象来传递多个参数进行查询。下面分别介绍这两种方法:

    使用@Param注解:
@Select("SELECT * FROM table_name WHERE column1 = #{param1} AND column2 = #{param2}")List<YourEntity> selectByParams(@Param("param1") String param1, @Param("param2") String param2);
    使用Map对象:
@Select("SELECT * FROM table_name WHERE column1 = #{param1} AND column2 = #{param2}")List<YourEntity> selectByParams(Map<String, Object> params);

在调用这两种方法时,需要传入对应的参数,如下所示:

List<YourEntity> result = yourMapper.selectByParams("value1", "value2");// 或者使用Map对象Map<String, Object> params = new HashMap<>();params.put("param1", "value1");params.put("param2", "value2");List<YourEntity> result = yourMapper.selectByParams(params);