springboot不熟,代码可优化空间比较大
spring.datasource.url=jdbc:mysql://****:3306/jfinal_club?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false&useInformationSchema=true
spring.datasource.username=root
spring.datasource.password=****
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
package com.skywalker.arp.config; import com.alibaba.druid.wall.WallFilter; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.druid.DruidPlugin; import com.jfinal.template.source.ClassPathSourceFactory; import com.mysql.jdbc.Connection; import com.skywalker.model._MappingKit; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class ActiveRecordPluginConfig { @Value("${spring.datasource.username}") private String username; @Value("${spring.datasource.password}") private String password; @Value("${spring.datasource.url}") private String url; @Bean public ActiveRecordPlugin ininitActiveRecordPlugin(){ DruidPlugin druidPlugin= new DruidPlugin(url,username,password); // 加强数据库安全 WallFilter wallFilter=new WallFilter(); wallFilter.setDbType("mysql"); druidPlugin.addFilter(wallFilter); // 添加 StatFilter 才会有统计数据 // druidPlugin.addFilter(new StatFilter()); // 必须手动调用start druidPlugin.start(); ActiveRecordPlugin arp=new ActiveRecordPlugin(druidPlugin); arp.setTransactionLevel(Connection.TRANSACTION_READ_COMMITTED); _MappingKit.mapping(arp); arp.setShowSql(false); arp.getEngine().setSourceFactory(new ClassPathSourceFactory()); arp.addSqlTemplate("/sql/all_sqls.sql"); // 必须手动调用start arp.start(); return arp; } }
EnjoyConfig抄jfinal文档即可。copy了很多次,不知道为什么会格式乱掉