在学习尚硅谷的mybatis-plus中,发现依托代码无法创建userMapperbean,在网上找了各种办法,终于是找到了一个大无语的办法。
只要将springboot的版本主动降到2.x.x之后便可以创建。可能mp是国人写的目前对springboot3.x.x并没有做适配,但是更进一步的方法正在思想中。
package com.example.bootMp; import com.example.bootMp.mapper.UserMapper; import com.example.bootMp.pojo.User; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.List; @SpringBootTest public class MybatisPlusTest { @Autowired private UserMapper userMapper; @Test public void testSelectList(){ List<User> users = userMapper.selectList(null); users.forEach(System.out::println); } }
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.11</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>boot-mp</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot-mp</name> <description>boot-mp</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.33</version> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
标签:springboot,spring,boot,springframework,bean,plus,import,org,com From: https://www.cnblogs.com/zhouselftest/p/17517886.html