What is the method for querying multiple parameters in MyBatis?

In MyBatis, you can pass multiple parameters for querying by using either the @Param annotation or a Map object. Next, we will explain these two methods individually.

  1. Could you provide information about the parameter?
@Select("SELECT * FROM table_name WHERE column1 = #{param1} AND column2 = #{param2}")
List<YourEntity> selectByParams(@Param("param1") String param1, @Param("param2") String param2);
  1. Chart
@Select("SELECT * FROM table_name WHERE column1 = #{param1} AND column2 = #{param2}")
List<YourEntity> selectByParams(Map<String, Object> params);

When calling these two methods, you need to pass in the corresponding parameters as shown below:

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);

More tutorials

How to query database data with Python?(Opens in a new browser tab)

How to execute a stored procedure in PL/SQL?(Opens in a new browser tab)

How to handle a null return from selectOne in MyBatis?(Opens in a new browser tab)

What is the usage of selectOne in MyBatis?(Opens in a new browser tab)

What is the purpose of selectone in mybatis?(Opens in a new browser tab)

How can Mybatis return fields from multiple tables?(Opens in a new browser tab)


Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds