mybatis mysql select like
时间: 2023-09-29 18:03:52 浏览: 95
To perform a 'LIKE' query in MyBatis with MySQL, you can use the 'LIKE' keyword along with the '%' wildcard character. Here's an example:
```xml
<select id="selectByValue" resultType="YourResultType">
SELECT * FROM your_table
WHERE your_column LIKE CONCAT('%', #{value}, '%')
</select>
```
In this example, `your_table` is the name of your table, `your_column` is the column you want to search in, and `#{value}` is the parameter you pass to the query. The `CONCAT` function is used to concatenate the wildcard characters '%' before and after the parameter value.
You can then invoke this query in your Java code using MyBatis like this:
```java
YourResultType result = sqlSession.selectOne("selectByValue", "your_search_value");
```
Replace `YourResultType`, `your_table`, `your_column`, and `"your_search_value"` with your actual values. This query will return the rows where the specified column value contains the search value.
Remember to properly configure and initialize MyBatis and create the necessary mapper interface and XML configuration files before using this query.
阅读全文