SpringBoot集成MyBatis
常见访问数据库方式
1、原始java访问数据库
开发流程麻烦
注册驱动/加载驱动
Class.forName("com.mysql.jdbc.Driver")
- 建立连接
> Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname","root","root");
- 创建Statement
- 执行SQL语句
- 处理结果集
- 关闭连接,释放资源
2、apache dbutils框架
比上一步简单点官网
3、jpa框架
spring-data-jpa:jpa在复杂查询的时候性能不是很好
4、Hiberante
ORM:对象关系映射Object Relational Mapping
企业大都喜欢使用hibernate
5、Mybatis框架
互联网行业通常使用mybatis
不提供对象和关系模型的直接映射,半ORM
集成步骤
添加依赖
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
mysql
mysql-connector-java
添加配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/tjsdemo?useUnicode=true&c