SoFunction
Updated on 2025-04-11

How to connect mybatisPlus

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. AvailableleftJoinMethod 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:

  • useQueryWrapperBuild query conditions.
  • passleftJoinThe method can perform a left join operation, specifying the table name and join conditions of the join.
  • passselectMethods can specify the field to query.

Please note:

  • In the exampleuserTable andorderThe table is schematic
  • When using it, please replace it with the corresponding table name according to the actual situation.

By using MyBatis PlusleftJoinMethods 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 PlusleftJoinThe 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:

  1. 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.
  2. You can try to clean and rebuild the project to ensure that the cache and index files in the IDE are updated.
  3. If there is still no prompt, try manually importing the relevant classes and methods in the code.

For example, if you need to useleftJoinIn the method's class, manually add the following import statement:

import ;

Then useWrappersClass 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.