DELL
2024-08-29 abd9823f366dc3efc33446fa4e98f7cc278f1d78
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.fgkj;
 
import com.fgkj.pojo.Dev_A200_TestParam;
import com.fgkj.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
 
public class Main {
    public static void main(String[] args) throws IOException {
 
        //1.加载mybatis 的核心配置文件,获取SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
 
        //2.获取 SqlSession 对象,用它执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();
 
        System.out.println(sqlSession);
        //3.执行sql
        List<User> users = sqlSession.selectList("com.fgkj.mapper.UserMapper.selectAll");
        System.out.println(users);
 
        //4.释放资源
        sqlSession.close();
 
 
 
    }
}