首页 > 其他 > 详细

Mybatis

时间:2017-12-17 20:25:41      阅读:249      评论:0      收藏:0      [点我收藏+]

1、介绍

持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集

2、一般SQL调用

Class.forName("driver");// 1
Connection c = DriverManager.getConnection();// 2
Statement s = c.createStatement();ResultSet r = s.executeQuery("sql");
//或者
PreparedStatement pst = conn.prepareStatement(sql2);pst.setString(1,"8888");pst.setInt(2,198);pst.executeUpdate();// 3
r.close();c.close();// 4

3、调用逻辑

String resource = "org/mybatis/example/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

SqlSession session = sqlSessionFactory.openSession();
try {
  BlogMapper mapper = session.getMapper(BlogMapper.class);
  Blog blog = mapper.selectBlog(101);
} finally {
  session.close();
}
 

 

Mybatis

原文:http://www.cnblogs.com/beaconSky/p/8052964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!