mybatisPlus Map<String, String>
时间: 2023-11-18 11:36:31 浏览: 162
MyBatis Plus is an enhanced version of the MyBatis framework, which is a popular persistence framework for Java. It simplifies the usage of MyBatis and provides additional features.
In MyBatis Plus, you can use the `Map<String, String>` type to represent key-value pairs. This can be useful in scenarios where you want to pass dynamic parameters to a SQL query or store dynamic properties in a database column.
Here's an example of how you can use `Map<String, String>` with MyBatis Plus:
```java
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import java.util.HashMap;
import java.util.Map;
public class MyBatisPlusExample {
public static void main(String[] args) {
// Create a map with key-value pairs
Map<String, String> params = new HashMap<>();
params.put("name", "John");
params.put("age", "30");
// Create a query wrapper
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
// Add conditions using the map
params.forEach((key, value) -> queryWrapper.eq(key, value));
// Execute the query
UserMapper userMapper = new UserMapper();
List<User> userList = userMapper.selectList(queryWrapper);
}
}
```
In this example, we create a `Map<String, String>` called `params`, which contains key-value pairs representing the conditions we want to add to the query. We then iterate over the map using `forEach` and add each condition to the `QueryWrapper` using the `eq` method. Finally, we execute the query and retrieve the results.
Note that this is just a basic example, and you can use `Map<String, Object>` if you need to handle values of different types. MyBatis Plus provides many other features and utilities that can simplify your database operations.
阅读全文