My girlfriend asked me, why should I use MyBatis? Let's see the difference between using traditional methods and mybatis?

1. Use traditional JDBC to access the database:

1、使用JDBC访问数据库有大量重复代码(比如注册驱动、获取连接、获取传输器、释放资源等);
2、JDBC自身没有连接池,会频繁的创建连接和关闭连接,效率低;
3、SQL是写死在程序中,一旦修改SQL,需要对类重新编译;
4、对查询SQL执行后返回的ResultSet对象,需要手动处理,有时会特别麻烦;
...

Second, use the mybatis framework to access the database:

1、Mybatis对JDBC对了封装,可以简化JDBC代码;
2、Mybatis自身支持连接池(也可以配置其他的连接池),因此可以提高程序的效率;
3、Mybatis是将SQL配置在mapper文件中,修改SQL只是修改配置文件,类不需要重新编译。
4、对查询SQL执行后返回的ResultSet对象,Mybatis会帮我们处理,转换成Java对象。
...

3. In short, all the problems in JDBC (the code is cumbersome, there are too many duplicate codes, too many objects need to be manipulated, the release of resources, the processing of the results is too troublesome, etc.), almost all have been solved in the Mybatis framework! !

Guess you like

Origin blog.csdn.net/m0_51570097/article/details/109323611