What is the method for performing a multi-table query in Java using QueryWrapper?
Performing multi-table queries in Java usually requires using a query builder (QueryWrapper), which is a query condition encapsulation tool provided by MyBatis-Plus. QueryWrapper makes it convenient to build multi-table query conditions, supports chained calls, and allows for flexible combination of query conditions.
Here is an example code demonstrating how to use QueryWrapper for multi-table queries.
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
queryWrapper.eq("status", 1);
List<User> userList = userMapper.selectList(queryWrapper);
In this example, we used QueryWrapper to construct a query condition that includes a specific user ID and a status of 1 across multiple tables. Finally, we executed the query using the selectList method to retrieve the query results.
It is important to note that specific multi-table query operations should be flexibly chosen based on specific business needs and database table structures.