概述
詳細
一、准備工作
本例子需要使用mysql,運行之前請確保已經安裝mysql,如果未安裝請自行下載,或者再百度網盤中下載,下載地址:https://pan.baidu.com/s/1pLDKOm3#list/path=%2F
本例子整合了springboot、mysql、easyUI,並提供了一個簡單的easyUI datagrid列表樣例
運行本例子前請先執行create.sql創建數據庫(下載包里面有)
二、程序實現
1、源碼截圖
2、具體設計到哪些代碼
① MyBatisConfig類配置了mybatis的事務、sqlSessionFactory、mapper、model;MyBatisMapperScannerConfig配置了mybatis的model,MybatisCustomVFS是自定義的VFS,springboot項目打包之后class文件全都在BOOT-INF/classes/目錄下,所以model會因為路徑問題掃描不到,在VFS中處理該問題,WebConfig中配置了CharacterEncodingFilter,防止出現亂碼
① plugins目錄下的jQuery和easyUI插件未做任何改變
3、配置文件說明
spring: application: name: springtest datasource: type: com.alibaba.druid.pool.DruidDataSource #使用druid連接池 url: jdbc:mysql://localhost:3306/role?characterEncoding=UTF-8 username: root password: root driver-class-name: com.mysql.jdbc.Driver max-idle: 5 max-wait: 60000 maxWait: 60000 min-idle: 5 minIdle: 5 maxActive: 20 initial-size: 5 initialSize: 5 validation-query: SELECT 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 filters: stat,wall,log4j connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 useGlobalDataSourceStat: true jdbc-interceptors: ConnectionState;SlowQueryReport(threshold=50) thymeleaf: cache: false cache-period: 0 template: cache: false server: port: 8080 tomcat: uri-encoding: UTF-8
三、運行效果
1、直接執行com.springtest.Application即可運行(含有main方法,直接運行即可),訪問地址是http://localhost:8080/
2、運行時的截圖
四、其他補充
例子中只是簡單的對springboot 、mybatis 、 easyUI做了整合,mybatis未加入分頁插件,如果需要請自行加入,和標准的Java項目使用方式無任何區別,easyUI和在標准的Java項目中使用方式也沒區別
mybatis文檔:http://www.mybatis.org/mybatis-3/zh/index.html
分頁插件:https://github.com/pagehelper/Mybatis-PageHelper
注:本文著作權歸作者,由demo大師發表,拒絕轉載,轉載需要作者授權