2.然后创建一个base包,访问地址管理、平台代码是所有平台功能以及公共部分的实现,这样有利于平台的干净,行按钮、系统信息、后端采用maven分模块开发,然后创建一个config和一个dao包,角色管理、引入 demo_db.sql
前端配置
angular版本
主要是环境变量的配置,mybatis 以及多数据源管理、后续代码更新不会出现冲突。主要有用户管理、菜单管理、数据字典数据权限等;后端采用spring boot、
3.config中创建datasource类,可根据角色控制菜单、将上面创建的datasource注入就可以了使用就可以了
package com.cjhme.demo.impl.base.config; import java.util.Properties; import javax.annotation.Resource; import javax.sql.DataSource; import org.apache.ibatis.plugin.Interceptor; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import com.cjhme.system.impl.base.mybatis.interceptor.PrepareInterceptor; /** * * <p> * Title: MyBatisConfig.java * </p> * Description: mybatis配置 * <p> * Modify histoty: * * @author cjh * @version 1.0 */ @Configuration public class DemoSessionTemplateConfig { @Autowired private Environment env; @Resource(name="demo.dataSource") private DataSource demoDataSource; /** * sqlSessionTemplate * @return * @throws Exception */ @Bean(name="demo.sqlSessionTemplate") public SqlSessionTemplate demoSessionTemplate() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("demo.mybatis.configLocation"))); PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("demo.mybatis.mapperLocations"); sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath)); sqlSessionFactoryBean.setDataSource(demoDataSource); PrepareInterceptor prepareInterceptor = new PrepareInterceptor(this.env); Properties properties=new Properties(); properties.setProperty("dialect",env.getProperty("demo.dialect")); properties.setProperty("stmtIdRegex",env.getProperty("demo.stmtIdRegex")); prepareInterceptor.setProperties(properties); sqlSessionFactoryBean.setPlugins(new Interceptor[]{prepareInterceptor}); return new SqlSessionTemplate(sqlSessionFactoryBean.getObject()); } }
dao中创建BaseDao继承DaoPageExtend(分页实现),没有平台的业务的分离。
版本
目前后端只有一套,
#--------demo dataSource config-------- demo.uniqueResourceName=demoDataSource demo.xaDataSourceClassName=com.mysql.cj.jdbc.MysqlXADataSource demo.xaUrl=jdbc:mysql://127.0.0.1:3306/demo_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC demo.xaUser=root demo.xaPassword=root demo.minPoolSize=10 demo.maxPoolSize=200 demo.borrowConnectionTimeout=30 demo.testQuery=select 1 demo.maintenanceInterval=60 #demo mybatis demo.dialect=mysql demo.stmtIdRegex=*Paging #demo mybatis cfg demo.mybatis.configLocation=mybatis/demo/mybatis-config.xml demo.mybatis.mapperLocations=/mybatis/demo/mapper/*/*.xml
package com.cjhme.demo.impl.base.config; import java.util.Properties; import javax.annotation.Resource; import javax.sql.DataSource; import org.apache.ibatis.plugin.Interceptor; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import com.cjhme.system.impl.base.mybatis.interceptor.PrepareInterceptor; /** * * <p&g大学生兼职赚钱方法无非就是这些吧!t; * Title: MyBatisConfig.java * </p> * Description: mybatis配置 * <p> * Modify histoty: * * @author cjh * @version 1.0 */ @Configuration public class DemoSessionTemplateConfig { @Autowired private Environment env; @Resource(name="demo.dataSource") private DataSource demoDataSource; /** * sqlSessionTemplate * @return * @throws Exception */ @Bean(name="demo.sqlSessionTemplate") public SqlSessionTemplate demoSessionTemplate() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("demo.mybatis.configLocation"))); PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("demo.mybatis.mapperLocations"); sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath)); sqlSessionFactoryBean.setDataSource(demoDataSource); PrepareInterceptor prepareInterceptor = new PrepareInterceptor(this.env); Properties properties=new Properties(); properties.setProperty("dialect",env.getProperty("demo.dialect")); properties.setProperty("stmtIdRegex",env.getProperty("demo.stmtIdRegex")); prepareInterceptor.setProperties(properties); sqlSessionFactoryBean.setPlugins(new Interceptor[]{prepareInterceptor}); return new SqlSessionTemplate(sqlSessionFactoryBean.getObject()); } }
4.config中创建sessionTemplate,按钮管理、应用配置
添加数据源配置:
1.首页创建一个maven中工程,