[Programming problem] Solve the problem that the resultType of the mapper.xml file becomes popular: Cannot resolve symbol 'xxx'

System: Win10
JDK: 1.8.0_333
IDEA: 2022.2.4
SpringBoot: 2.7.6

1. Problem description

When developing a SpringBoot project and using MybatisPlus to return the entity class, the resultType attribute of the configured mapper.xml file exploded, and the mouse was placed on it to prompt: Cannot
resolve symbol 'TmsTb01'
as shown in the figure below:
insert image description here
Open the corresponding Mapper file, you can It is found that the corresponding method is also popular, and the mouse is put on it to prompt:
Result type not match for select id="selectByTime"
srcType:
targetType: com.electric.srm.entity.tms.TmsTb01

as shown in the following figure:
insert image description here

2. Problem analysis

I checked here and found that there are various things on the Internet that may cause this problem. I will describe the situation of my project here.

  • 1. There is no problem with the project running (the codes are all correct, the configuration has been configured, it is just a display problem) For example, the type-aliases-package: com.electric.srm.entity alias scanning
    hereok
  • 2. There are no redundant or missing plug-ins (here I see that other people may have installed plug-ins that should not be installed, or some plug-ins are missing, I am not here), I have installed
    the Lombok plug-in

3. Problem solving

3.1 Configuration annotations (recommended)

Add an annotation on the returned entity class: @Alias("TmsTb01") , here you can see that after the addition, the resultType will not become popular
insert image description here

3.2 Configure full class name

Here, if we change the resultType to the full class name, we can also achieve the effect of eliminating redness (tested), but it seems that the alias scanning we configured is stupid, so I don't use this solution

3.3 Delete plugin

I saw that another solution is to delete the MybatisX plugin. This plugin is very cute to use. I didn’t consider this solution, but it should work.

4. Event insights

This time, it took me about two hours from discovering this problem to dealing with it. Although this problem does not affect the normal operation of the project, when I see these popular tips, it is quite uncomfortable and a little obsessive-compulsive . However, the above three solutions are not my ideal solutions. I feel that since the code can run and no error is reported, it means that the code is correct. Why is it prompted to report an error in red?
I feel that there is a high probability that this error is caused by the problem of MybatisX. I hope that the later plug-in can be updated to deal with this problem, or someone will say that this is not the problem and give me a better solution.
In the process of solving the problem this time, I also thought about whether it might be a dependency version problem or a configuration problem. In the final analysis, it is still a lack of knowledge and skills. I hope that I can continue to learn and grow gradually in the future. If you encounter bugs, don’t worry about it. Be afraid, but face it bravely, persistence is victory, Ollie.

Guess you like

Origin blog.csdn.net/qq_35132089/article/details/130236918