报错:
Cannot resolve plugin org.apache.maven.plugins:maven-clean-plugin:2.5
Failed org.codehaus.mojo:exec-maven-plugin3.0.0:exec (default-cli) on project
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:co
1. 删除仓库maven_repository中的plugins,重新下载(https://blog.csdn.net/lyg9966/article/details/105904175)
2. IDEA-file-Invalidate Caches 清除缓存restart
3. conf/setting.xml换阿里云仓库 mirrors /mirrors中增加
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>aliyunpublic</id>
<name>aliyunpublic</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>public</mirrorOf>
</mirror>
<mirror>
<id>centralmaven</id>
<mirrorOf>centralmaven</mirrorOf>
<name>centralmaven</name>
<url>http://central.maven.org/maven2/</url>
</mirror>
profiles /profiles中增加
<profile>
<id>default</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
5. 在pom 中增加exec-maven-plugin/ compiler版本
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
6. 新建maven quickstart工程,导入pom新增内容(https://blog.csdn.net/pcwlkpzc/article/details/106964154)
https://blog.csdn.net/fanrenxiang/article/details/80864908
IDEA2020
jdk1.8/ 14均可用
MybatisTest.java 中将main 改成测试, 增加 @Test
public class MybatisTest {
@Test
public void test() throws IOException {
/**
* 1 读取配置文件
* 2 创建SqlSessionFactory
* 3 使用工厂生产SqlSession对象
* 4 使用SqlSession创建Dao接口的代理对象
* 5 使用代理对象执行方法
* 6 释放资源
*/
//1 读取配置文件
InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
//2 创建SqlSessionFactory
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlSessionFactory = builder.build(inputStream);
//3 使用工厂生产SqlSession对象
SqlSession sqlSession = sqlSessionFactory.openSession();
//4 使用SqlSession创建Dao接口的代理对象
IUserDao userDao = sqlSession.getMapper(IUserDao.class);
//5 使用代理对象执行方法
List<User> users = userDao.findAll();
for (User user : users) {
System.out.println(user);
}
//6 释放资源
sqlSession.close();
inputStream.close();
}
}