Mybatis创建过程
1.在resource下创建mybatis-config.xml,用于连接数据库
2.创建工具类从 XML 中构建 SqlSessionFactory
public class MybatisUtils{
private static SqlSessionFactory sqlSessionFactory;
static{
try{
String resource = "org/mybatis/example/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
}catch(IOException e){
e.printStackTrace();
}
}
public static SqlSession getSqlSession(){
return sqlSessionFactory.openSession();
}
}
3.实体类例如User
4.UserMapper(UserDao)
public interface UserMapper{
public List findAll();
}
5.创建UserMapper.xml
select * from Blog where id = #{id}



