1. 需求
(1)实用maven管理jar
(2)springboot 整合,mybaties
(3) 使用整合jsp进行显示数据(数据从数据库表中查出)
2.搭建maven环境
参考:
https://my.oschina.net/springMVCAndspring/blog/1817609
3. 给Eclipse安装springboot插件
参考:
https://my.oschina.net/springMVCAndspring/blog/1808502
4. 整合
4.1 搭建项目
等待jar 下载完成
4.2 配置pom.xml 红色部分为要添加的jar
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
4.3 设计一个简单的数据
创建数据库
创建表
表中添加数据
4.4 创建实体类
4.5 配置数据源
#1.配置端口 server.port=9000 #2.连接数据源 spring.datasource.url=jdbc:mysql://localhost:3306/studydb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=root #spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#3.连接池的配置信息
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat,wall,log4j
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
#4.统一配置实体类包路径
mybatis.type-aliases-package=cn.ma.sm.pojo
#5.开启驼峰命名
mybatis.configuration.map-underscore-to-camel-case=true
4.6 controller层
4.7 service层
4.8 mapper
4.9 springboot 启动器中配置mapper包路径
4.10 编写jsp页面
5. 效果
6.代码
https://gitee.com/Luck\_Me/springbootAndMybaties