mybatis like
时间: 2023-08-15 12:07:44 浏览: 115
MyBatis provides support for SQL LIKE queries through the use of the `LIKE` keyword. You can use the `%` wildcard character to match any sequence of characters and the `_` wildcard character to match any single character.
Here's an example of using the `LIKE` keyword in MyBatis:
```xml
<select id="searchUsers" resultType="User">
SELECT * FROM users
WHERE username LIKE #{keyword}
</select>
```
In this example, `#{keyword}` is a parameter that you can pass to the query. You can use the `%` wildcard character in the parameter value to match any sequence of characters. For example, if you pass the parameter value `%john%`, it will match usernames like "john", "johnny", "johnson", etc.
You can also use the `%` or `_` wildcard characters directly in the SQL query like this:
```xml
<select id="searchUsers" resultType="User">
SELECT * FROM users
WHERE username LIKE '%john%'
</select>
```
This will achieve the same result as the previous example.
Remember to properly escape user input to prevent SQL injection attacks when using `LIKE` queries with user-provided values.
阅读全文