一、Mybatis
第一个简单的Mybatis小程序
1.在pom.xml里面导入依赖
2.工具类的使用
注意过程
private static SqlSessionFactory sqlSessionFactory;
static {
try {
//mybatis 获取 sqlsessionfactory对象
String resource = “mybatis-config.xml”;
InputStream inputStream = Resources.getResourceAsStream(resource);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
// 既然有了 SqlSessionFactory,顾名思义,我们可以从中获得 SqlSession 的实例。
// SqlSession 提供了在数据库执行 SQL 命令所需的所有方法
public static SqlSession getSqlSession(){
return sqlSessionFactory.openSession();
}
3.mybatis-config.xml的编写
4.编写实体类
private int id;
private String name;
private String pwd;
然后gettter、setter、