mybatisPlus connect
I want to join a certain table left, does plus provide API? Type leftJoin method?
Yes, MyBatis Plus provides an API to support left-connection query. AvailableleftJoin
Method to perform left connection operation.
A sample code
import ; import ; import ; import ; import ; import ; import ; @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Autowired private OrderMapper orderMapper; public List<User> getUsersWithOrders() { QueryWrapper<User> queryWrapper = new QueryWrapper<>(); ("status", 1) .leftJoin("order", " = order.user_id") .select("user.*", "order.order_name"); return (queryWrapper); } }
In the above example:
- use
QueryWrapper
Build query conditions. - pass
leftJoin
The method can perform a left join operation, specifying the table name and join conditions of the join. - pass
select
Methods can specify the field to query.
Please note:
- In the example
user
Table andorder
The table is schematic - When using it, please replace it with the corresponding table name according to the actual situation.
By using MyBatis PlusleftJoin
Methods can easily perform left join operations and query the result set of left table related to right table.
If you do not find it while using MyBatis PlusleftJoin
The prompts for the method may be because your version does not support the method or your IDE's automatic completion function does not prompt correctly.
Please make sure you are using the latest version of MyBatis Plus and that the relevant dependencies have been imported correctly. You can find the latest version information in the official MyBatis Plus documentation or in the GitHub repository.
Additionally, if you are developing using an integrated development environment (IDE), such as IntelliJ IDEA or Eclipse, you can try the following to refresh and fix the automatic prompt issue:
- If you are using Maven or Gradle to manage project dependencies, try reimporting the Maven or Gradle project to make sure the dependencies load correctly.
- You can try to clean and rebuild the project to ensure that the cache and index files in the IDE are updated.
- If there is still no prompt, try manually importing the relevant classes and methods in the code.
For example, if you need to useleftJoin
In the method's class, manually add the following import statement:
import ;
Then useWrappers
Class to build query conditions, for example:
("LEFT JOIN order ON = order.user_id");
Summarize
The above is just an alternative, I hope it can help you solve the problem. If the problem persists, check your MyBatis Plus version and dependency configuration and make sure the correct classes and methods are imported.
These are just personal experience. I hope you can give you a reference and I hope you can support me more.