专业手机网站公司吗,同ip网站做301,象山县住房建设局网站,网站优化说明SpringBootAdmin是码云上一个以springboot为核心的开源的后台管理系统。这里是链接地址#xff1a;点击打开链接由于是后台系统#xff0c;应该采用数据库分离#xff0c;权限#xff0c;用户#xff0c;角色和业务模块分开。application.properties
#服务端口
server.por… SpringBootAdmin是码云上一个以springboot为核心的开源的后台管理系统。这里是链接地址点击打开链接由于是后台系统应该采用数据库分离权限用户角色和业务模块分开。application.properties
#服务端口
server.port 8001
# ĿcontextPath
server.context-path /
# session
server.session-timeout60
#which active
#spring.profiles.activepro logging.level.com.mys.my.mapper DEBUG#主数据库配置
spring.datasource.master.type com.alibaba.druid.pool.DruidDataSource
spring.datasource.master.driver-class-name com.mysql.jdbc.Driver
spring.datasource.master.name geekcattle
spring.datasource.master.urljdbc:mysql://localhost:3306/geekcattle?useUnicodetruecharacterEncodingUTF-8
spring.datasource.master.username root
spring.datasource.master.password 1234
spring.datasource.master.filters stat
spring.datasource.master.maxActive 20
spring.datasource.master.initialSize 5
spring.datasource.master.maxWait 60000
spring.datasource.master.minIdle 20
spring.datasource.master.timeBetweenEvictionRunsMillis 60000
spring.datasource.master.minEvictableIdleTimeMillis 300000
spring.datasource.master.validationQuery select x
spring.datasource.master.testWhileIdle true
spring.datasource.master.testOnBorrow false
spring.datasource.master.testOnReturn false
spring.datasource.master.poolPreparedStatements true
spring.datasource.master.maxOpenPreparedStatements 20#从数据库配置
spring.datasource.film.type com.alibaba.druid.pool.DruidDataSource
spring.datasource.film.driver-class-name com.mysql.jdbc.Driver
spring.datasource.film.name film
spring.datasource.film.urljdbc:mysql://localhost:3306/film?useUnicodetruecharacterEncodingUTF-8
spring.datasource.film.username root
spring.datasource.film.password 1234
spring.datasource.film.filters stat
spring.datasource.film.maxActive 20
spring.datasource.film.initialSize 1
spring.datasource.film.maxWait 60000
spring.datasource.film.minIdle 20
spring.datasource.film.timeBetweenEvictionRunsMillis 60000
spring.datasource.film.minEvictableIdleTimeMillis 300000
spring.datasource.film.validationQuery select x
spring.datasource.film.testWhileIdle true
spring.datasource.film.testOnBorrow false
spring.datasource.film.testOnReturn false
spring.datasource.film.poolPreparedStatements true
spring.datasource.film.maxOpenPreparedStatements 20#MVC
spring.mvc.view.prefix classpath:/templates/
spring.mvc.view.suffix .html
spring.mvc.date-formatyyyy-MM-dd HH:mm:ss
#
spring.thymeleaf.mode HTML5
spring.thymeleaf.cache false
spring.thymeleaf.encoding UTF-8
spring.thymeleaf.content-type text/html
#mybaties
spring.mapper.plugin tk.mybatis.mapper.generator.MapperPlugin
spring.mapper.Mapper com.mys.my.util.CustomerMapper
#json
spring.jackson.time-zoneAsia/Chongqing
spring.jackson.date-formatyyyy-MM-dd HH:mm:ss
spring.jackson.joda-date-time-formatyyyy-MM-dd HH:mm:ss# Redis数据库索引默认为0
spring.redis.database1
# Redis服务器地址
spring.redis.host
# Redis服务器连接端口
spring.redis.port6379
# Redis服务器连接密码默认为空
spring.redis.password
# 连接池最大连接数使用负值表示没有限制
spring.redis.pool.max-active30
# 超时时间
spring.redis.timeout100000
# 连接池中的最大空闲连接
spring.redis.pool.max-idle20
# 连接池最大阻塞等待时间使用负值表示没有限制
spring.redis.pool.max-wait-1MyBatisConfig.java /** Copyright (c) 2017 l_iupeiyuqq.com All rights reserved.*/package com.mys.my.conf;import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;import javax.sql.DataSource;import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;import com.github.pagehelper.PageHelper;
/*** MyBatis基础配置*/
Configuration
PropertySource(classpath:application.properties)
//EnableTransactionManagement
public class MyBatisConfig {// Autowired
// DataSource dataSource;Bean(namemasterDataSource)ConfigurationProperties(prefix spring.datasource.master)Primary//默认数据源public DataSource dataSource() {System.out.println(DataSourceBuilder.create().build());return DataSourceBuilder.create().build();}Bean(namemasterSqlSessionFactory)Primary//默认数据源public SqlSessionFactory sqlSessionFactoryBean(Qualifier(masterDataSource) DataSource dataSource) throws SQLException {SqlSessionFactoryBean bean new SqlSessionFactoryBean();System.out.println(dataSourcedataSource);bean.setDataSource(dataSource);bean.setTypeAliasesPackage(com.mys.my.model);//分页插件PageHelper pageHelper new PageHelper();Properties properties new Properties();properties.setProperty(reasonable, true);properties.setProperty(supportMethodsArguments, true);properties.setProperty(returnPageInfo, check);properties.setProperty(params, countcountSql);pageHelper.setProperties(properties);//添加插件bean.setPlugins(new Interceptor[]{pageHelper});//添加XML目录ResourcePatternResolver resolver new PathMatchingResourcePatternResolver();try {bean.setMapperLocations(resolver.getResources(classpath:mapper/*.xml));bean.setMapperLocations(resolver.getResources(classpath:mapper/*/*.xml));return bean.getObject();} catch (Exception e) {e.printStackTrace();throw new RuntimeException(e);}}Bean(masterSqlSessionTemplate)Primarypublic SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory){return new SqlSessionTemplate(sqlSessionFactory);}Bean(masterTransactionManager)Primarypublic PlatformTransactionManager annotationDrivenTransactionManager(Qualifier(masterDataSource) DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}
}新建一个数据库配置文件
MyBatisConfigFilm.java /** Copyright (c) 2017 l_iupeiyuqq.com All rights reserved.*/package com.mys.my.conf;import java.sql.SQLException;
import java.util.Properties;import javax.sql.DataSource;import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;import com.github.pagehelper.PageHelper;
/*** MyBatis基础配置*/
Configuration
MapperScan(basePackages{com.mys.my.mapper.fiz},sqlSessionFactoryReffilmSqlSessionFactory)
public class MyBatisConfigFilm{Bean(namefilmDatasource)ConfigurationProperties(prefix spring.datasource.film)public DataSource dataSource() {System.out.println(DataSourceBuilder.create().build());return DataSourceBuilder.create().build();}Bean(namefilmSqlSessionFactory)public SqlSessionFactory sqlSessionFactoryBean(Qualifier(filmDatasource) DataSource dataSource) throws SQLException {SqlSessionFactoryBean bean new SqlSessionFactoryBean();System.out.println(dataSourcedataSource());bean.setDataSource(dataSource());bean.setTypeAliasesPackage(com.mys.my.pojo);//分页插件PageHelper pageHelper new PageHelper();Properties properties new Properties();properties.setProperty(reasonable, true);properties.setProperty(supportMethodsArguments, true);properties.setProperty(returnPageInfo, check);properties.setProperty(params, countcountSql);pageHelper.setProperties(properties);//添加插件bean.setPlugins(new Interceptor[]{pageHelper});//添加XML目录ResourcePatternResolver resolver new PathMatchingResourcePatternResolver();try {
// bean.setMapperLocations(resolver.getResources(classpath:mapper/*.xml));bean.setMapperLocations(resolver.getResources(classpath:mapper/fiz/*.xml));return bean.getObject();} catch (Exception e) {e.printStackTrace();throw new RuntimeException(e);}}Bean(filmSqlSessionTemplate)public SqlSessionTemplate sqlSessionTemplate(Qualifier(filmSqlSessionFactory)SqlSessionFactory sqlSessionFactory){return new SqlSessionTemplate(sqlSessionFactory);}Bean(name filmTransactionManager)public PlatformTransactionManager annotationDrivenTransactionManager(Qualifier(filmDatasource) DataSource dataSource) {return new DataSourceTransactionManager(dataSource());}
}
MapperScan(basePackages{com.mys.my.mapper.fiz}的配置是扫描配置的dao文件 *.java bean.setMapperLocations(resolver.getResources(classpath:mapper/fiz/*.xml)); 这个配置是扫描对应的mapper文件 *.xml。
MyBatisMapperScannerConfig.java
/** Copyright (c) 2017 l_iupeiyuqq.com All rights reserved.*/package com.mys.my.conf;import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;//import com.mys.my.mapper.dataSource.MyFilmDatasource;import tk.mybatis.spring.mapper.MapperScannerConfigurer;import java.util.Properties;/*** MyBatis扫描接口使用的tk.mybatis.spring.mapper.MapperScannerConfigurer如果你不使用通用Mapper*/
Configuration
//TODO 注意由于MapperScannerConfigurer执行的比较早所以必须有下面的注解
AutoConfigureAfter(MyBatisConfig.class)
public class MyBatisMapperScannerConfig {Beanpublic MapperScannerConfigurer mapperScannerConfigurer() {MapperScannerConfigurer mapperScannerConfigurer new MapperScannerConfigurer();mapperScannerConfigurer.setSqlSessionFactoryBeanName(masterSqlSessionFactory);mapperScannerConfigurer.setSqlSessionTemplateBeanName(masterSqlSessionTemplate);mapperScannerConfigurer.setBasePackage(com.mys.my.mapper);Properties properties new Properties();properties.setProperty(mappers, com.mys.my.util.CustomerMapper);properties.setProperty(notEmpty, false);properties.setProperty(IDENTITY, MYSQL);mapperScannerConfigurer.setProperties(properties);return mapperScannerConfigurer;}
}