mybaits故障
这里的名字是叫mybatis-config.xml位于项目根目录下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/study"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper url="file:TestMapper.xml"/>
</mappers>
</configuration>
这里的名字是叫mybatis-config.xml也是位于项目根目录下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="TestMapper">
<select id="selectStudent" resultType="Mybaits_Test.entity.Student">
select * from student
</select>
</mapper>
名字叫做Student.java绝对路径位于D:\JavaWeb\src\Mybatis_Test\entity\Student.java
package Mybatis_Test.entity;
import lombok.Data;
@Data
public class Student {
int Sid;
String Sname;
String Ssex;
}
名字是叫Main.java绝对路径位于D:\JavaWeb\src\Mybatis_Test\Main.java
package Mybatis_Test;
import JDBC_mysql.Student;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
//通过SqlSessionFactory得到一个SqlSessionFactory对象
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(new FileInputStream("mybatis-config.xml"));
//获取一个SqlSessionFactory
try(SqlSession session = sqlSessionFactory.openSession(true)){//自动提交
List<Student> list = session.selectList("selectStudent");
list.forEach(System.out::println);
}
}
}
数据库如下已连接
运行Main.java后报很多错
弄了半天还是没能解决问题,麻烦知情者帮忙解答!!谢谢