mybatis like concat
时间: 2023-10-17 08:25:28 浏览: 141
In MyBatis, you can use the CONCAT function to concatenate strings and then use the LIKE operator for pattern matching. Here's an example:
```xml
<select id="searchUsers" parameterType="String" resultType="User">
SELECT * FROM users
WHERE CONCAT(first_name, ' ', last_name) LIKE CONCAT('%', #{keyword}, '%')
</select>
```
In this example, we are searching for users whose first name or last name contains a specific keyword. The CONCAT function concatenates the first name and last name separated by a space, and then the LIKE operator is used to perform the pattern matching.
You can replace the `users` table, `first_name`, `last_name`, and `User` with your own table and column names. Also, `#{keyword}` is a parameter that you can pass to the query to specify the search keyword.
Hope this helps! Let me know if you have any more questions.
阅读全文