Type interface is not known to the MapperRegistry错误

Type interface is not known to the MapperRegistry错误

It happens when mybatis annotations and configuration files are used together.
Because when I name the interface, the name of one of the interfaces is the same as the folder where the interface is located. When
mapping the class file, no matter how to fill in the path, the second mapped file will be Go and find the text class with the same name

List<pirc> pirc = sqlsession.getMapper(Map.Map.class).selectBymuch();
        for (Pirc pirc: pirc) {
    
    
            System.out.println(pirc);
        }
List<pirc> pirc = sqlsession.getMapper(Map.Map2.class).selectBymuch();
        for (Pirc pirc: pirc) {
    
    
            System.out.println(pirc);
        }
        更改前无论怎么改Map2都报红,而且是idea提示输入进去的都报红   

After the change ()

List<pirc> pirc = sqlsession.getMapper(Map.Map1.class).selectBymuch();
        for (Pirc pirc: pirc) {
    
    
            System.out.println(pirc);
        }
List<pirc> pirc = sqlsession.getMapper(Map.Map2.class).selectBymuch();
        for (Pirc pirc: pirc) {
    
    
            System.out.println(pirc);
        }

Until I changed the name of that interface. . .
Good guy, the first level directory of the second file I configured has actually changed. Only then did I know that idea consistently regarded the first-level directory I configured as the class file.
Solution
1: Rename to avoid conflicts.
Method 2: Do not alias the entire package. .
Method 3: Check whether the mapping file
is introduced in the configuration file Method 4: Check whether the namespace matches and whether the interface method name is the same as the id of the sql statement
Method 5: Configuration file configuration import configuration file (configuration file scheme), import implementation class interface ( Annotation scheme), the full path name must be used. Generally, the configuration file can be directly placed in the project directory as the file name. The interface must remember the full path.
Method 6: When using the configuration file scheme, the name space in the mapping file must be a full path! The annotation does not matter, the annotation does not need to map the configuration file. But remember to change the mixed use

Guess you like

Origin blog.csdn.net/m0_49194578/article/details/112112266