新增ssm-sharding分库分表模块,功能未实现
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# 欢迎查看boot-starter-ssm项目说明
|
||||
## 项目介绍
|
||||
`boot-starter-ssm`项目用于快速开启spring集成mybatis的项目,将本项目使用maven发布到本地仓库,在其他项
|
||||
目中引入该依赖进行相关配置即可使用.
|
||||
### boot-starter-ssm项目的参数配置
|
||||
得益于springboot的自动配置以及条件化装配的机制.我们可以扩展封装自己的ssm-boot,也是就是本项目中的boot-starter-ssm,本项目的自定义扩展配置如下:
|
||||
- 参考[druid官网的配置说明](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter)
|
||||
- `mybatis.typeAliasesPackage` pojo包所在的位置(必要参数),如果要指定多个包的话使用逗号分割
|
||||
- `mybatis.mappers` mapper映射文件所在的路径(必要参数)
|
||||
- `mybatis.pageHelperProperties` pagehelper分页插件的properties配置形式是key:value数组的形式,默认方言是mysql,如果需要自定义可以传入自己的配置,使用key:value的数
|
||||
组的形式.
|
||||
- 除此之外`mybatis`的`dao`层扫描的配置需要在项目中自行配置
|
||||
- 需要注意的是:当使用多数据源的时候,需要在使用的项目之中去除默认的数据源自动装配`@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)`
|
||||
- 对于数据源的切换方法是使用aop的方式对`@SwitchDataSource('数据源的名字')`进行拦截动态切换数据源,主数据源的名字是`master`,从数据源的名字是`slave`.对于没有注解默认的数据源是`master`.
|
||||
- PageHelper只对紧跟着的第一个SQL语句起作用
|
||||
- 如果向定义n个数据源,在自己项目使用中定义bean即可,但是数据源的名字请不要使用`salve` `master` `masterDataSource` `dataSource` `dynamicDataSource`
|
||||
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>boot-starter-ssm-sharding</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>boot-starter-ssm-sharding</name>
|
||||
<description>boot-starter-ssm-sharding</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.micro.fast</groupId>
|
||||
<artifactId>boot-starter</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- micro-fast-util-->
|
||||
<dependency>
|
||||
<groupId>com.micro.fast</groupId>
|
||||
<artifactId>boot-starter-util</artifactId>
|
||||
<version>${micro.fast.version}</version>
|
||||
</dependency>
|
||||
<!--fm模板引擎-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
</dependency>
|
||||
<!--web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--aop-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!--mybatis-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- mybatis pagehelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.miemiedev</groupId>
|
||||
<artifactId>mybatis-paginator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jsqlparser</groupId>
|
||||
<artifactId>jsqlparser</artifactId>
|
||||
</dependency>
|
||||
<!--数据库连接-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!--数据库连接池相关依赖-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--表单校验相关依赖-->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-el</artifactId>
|
||||
</dependency>
|
||||
<!--引入swagger2文档依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
<!--dao层生成-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.generator</groupId>
|
||||
<artifactId>mybatis-generator-core</artifactId>
|
||||
</dependency>
|
||||
<!--配置提示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.micro.fast</groupId>
|
||||
<artifactId>boot-starter-common</artifactId>
|
||||
<version>${micro.fast.version}</version>
|
||||
</dependency>
|
||||
<!-- 分库分表 -->
|
||||
<dependency>
|
||||
<groupId>io.shardingjdbc</groupId>
|
||||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<!--测试-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--对于被依赖的springboot项目一定要去掉此插件不然maven编译的时候结构会有问题-->
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.springframework.boot</groupId>-->
|
||||
<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
|
||||
<!--</plugin>-->
|
||||
<!--将lib目录下的文件编译时打包-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!--<artifactId>maven-javadoc-plugin</artifactId>-->
|
||||
<!--</plugin>-->
|
||||
</plugins>
|
||||
<finalName>boot-starter-ssm-sharding</finalName>
|
||||
</build>
|
||||
</project>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.micro.fast.ssm.sharding;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 配置类,该类将配置于META-INF/spring.factories文件中用于被EnableAutoConfiguration注解所识别实现自动配置
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"com.micro.fast.ssm.sharding"})
|
||||
public class CommonApplication {
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.micro.fast.ssm.sharding.config;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.micro.fast.ssm.sharding.config.param.MybatisParamConfig;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
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 javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* mybatis的相关配置
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
public class SqlSessionFactoryConfig implements TransactionManagementConfigurer{
|
||||
private static final Logger logger = LoggerFactory.getLogger(SqlSessionFactoryConfig.class);
|
||||
|
||||
/**
|
||||
* 数据源对象
|
||||
*/
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
/**
|
||||
* mybatis参数配置对象
|
||||
*/
|
||||
@Autowired
|
||||
private MybatisParamConfig mybatisParamConfig;
|
||||
|
||||
/**
|
||||
* mybatis连接工厂bean
|
||||
* @return sqlSessionFactory
|
||||
*/
|
||||
@Bean(name = "sqlSessionFactory")
|
||||
@Primary
|
||||
public SqlSessionFactory sqlSessionFactory() {
|
||||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
|
||||
//注入数据源
|
||||
sqlSessionFactoryBean.setDataSource(dataSource);
|
||||
//设置实体类所在的位置
|
||||
sqlSessionFactoryBean.setTypeAliasesPackage(mybatisParamConfig.getTypeAliasesPackage());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("micro-fast common mybatisConfig: typeAliasesPackage:{}", mybatisParamConfig.getTypeAliasesPackage());
|
||||
}
|
||||
//sqlSessionFactoryBean.setTypeAliasesPackage("com.micro.fast.upms.pojo");
|
||||
//设置mapper映射文件的位置
|
||||
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
try {
|
||||
sqlSessionFactoryBean.setMapperLocations(
|
||||
resolver.getResources(mybatisParamConfig.getMappers()));
|
||||
//resolver.getResources("classpath:/mappers/*.xml"));
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("micro-fast common mybatisConfig: mappers:{}", mybatisParamConfig.getMappers());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//设置分页插件
|
||||
PageHelper pageHelper = new PageHelper();
|
||||
Properties properties = new Properties();
|
||||
ArrayList<String> pageHelperProperties = mybatisParamConfig.getPageHelperProperties();
|
||||
if (pageHelperProperties != null && !pageHelperProperties.isEmpty()) {
|
||||
for (String param :
|
||||
pageHelperProperties) {
|
||||
String[] keyValue = param.split(":");
|
||||
String key = keyValue[0];
|
||||
String value = keyValue[1];
|
||||
properties.setProperty(key, value);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("micro-fast common 使用mybatisPageHelperPropertyConfig自定义配置: {}:{}", key, value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
properties.setProperty("dialect", "mysql");
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("micro-fast common 使用mybatisPageHelperPropertyConfig默认配置: {}:{}", "dialect", "mysql");
|
||||
}
|
||||
}
|
||||
pageHelper.setProperties(properties);
|
||||
sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
|
||||
//设置详细的配置
|
||||
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
|
||||
//开启下划线转驼峰命名
|
||||
configuration.setMapUnderscoreToCamelCase(true);
|
||||
//开启列别名
|
||||
configuration.setUseColumnLabel(true);
|
||||
//使用自动的主键生成
|
||||
configuration.setUseGeneratedKeys(true);
|
||||
//将详细配置放入到sqlSessionFactoryBean中
|
||||
sqlSessionFactoryBean.setConfiguration(configuration);
|
||||
SqlSessionFactory sqlSessionFactory = null;
|
||||
try {
|
||||
sqlSessionFactory = sqlSessionFactoryBean.getObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sqlSessionFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向事务管理器中注入数据源,由spring来进行事务管理
|
||||
*/
|
||||
@Override
|
||||
@Bean("transactionManager")
|
||||
@Primary
|
||||
public PlatformTransactionManager annotationDrivenTransactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* ssm配置包
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.micro.fast.ssm.sharding.config;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.micro.fast.ssm.sharding.config.param;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* mybatis配置参数
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore(com.micro.fast.ssm.sharding.config.SqlSessionFactoryConfig.class)
|
||||
@ConfigurationProperties(prefix = "mybatis")
|
||||
@Validated
|
||||
@Getter
|
||||
@Setter
|
||||
public class MybatisParamConfig {
|
||||
/**
|
||||
* pojo所在的包
|
||||
*/
|
||||
@NotNull
|
||||
private String typeAliasesPackage;
|
||||
/**
|
||||
* 映射文件所在的文件路径
|
||||
*/
|
||||
@NotNull
|
||||
private String mappers;
|
||||
/**
|
||||
* 分页插件的参数设置
|
||||
*/
|
||||
private ArrayList<String> pageHelperProperties;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* ssm热插拔模块参数配置包
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.micro.fast.ssm.sharding.config.param;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.micro.fast.ssm.sharding.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SsmMapper<T,ID> {
|
||||
|
||||
int deleteByPrimaryKey(ID id);
|
||||
|
||||
int insert(T record);
|
||||
|
||||
int insertSelective(T record);
|
||||
|
||||
T selectByPrimaryKey(ID id);
|
||||
|
||||
int updateByPrimaryKeySelective(T record);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(T record);
|
||||
|
||||
int updateByPrimaryKey(T record);
|
||||
|
||||
/**
|
||||
* 按条件分页查询
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
List<T> selectByCondition(T record);
|
||||
|
||||
int deleteByPrimaryKeys(List<ID> id);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* ssm公共配置模块包
|
||||
* @author lishouyu 18332763730@163.com 2017/10/02
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
package com.micro.fast.ssm.sharding;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.micro.fast.ssm.sharding.service;
|
||||
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ssm框架service基础操作接口
|
||||
* @author lsy
|
||||
*/
|
||||
public interface SsmService<T,ID> {
|
||||
/**
|
||||
* 增加
|
||||
*/
|
||||
ServerResponse add(T pojo);
|
||||
/**
|
||||
* 根据id查询
|
||||
*/
|
||||
ServerResponse getById(ID id);
|
||||
/**
|
||||
* 按条件分页查询
|
||||
*/
|
||||
ServerResponse getByCondition(T pojo,int pageNum,int pageSize,String orderBy);
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
ServerResponse update(T pojo);
|
||||
/**
|
||||
* 根据id删除单个
|
||||
*/
|
||||
ServerResponse deleteById(ID id);
|
||||
|
||||
/**
|
||||
* 根据id删除多个
|
||||
*/
|
||||
ServerResponse deleteByIds(List<ID> ids);
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.micro.fast.ssm.sharding.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.micro.fast.boot.starter.common.exception.SystemException;
|
||||
import com.micro.fast.boot.starter.common.response.BaseConst;
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
import com.micro.fast.ssm.sharding.service.SsmService;
|
||||
import com.micro.fast.ssm.sharding.dao.SsmMapper;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* T表示的是实体类型,ID表示的是主键类型,DAO表示的是dao层的类型
|
||||
* @author lsy
|
||||
*/
|
||||
@Setter
|
||||
public class SsmServiceImpl<T, ID extends Serializable, MAPPER extends SsmMapper<T,ID>> implements SsmService<T,ID> {
|
||||
|
||||
/**
|
||||
* 这个属性一定要使用子类的覆盖,不然会报空指针
|
||||
*/
|
||||
private MAPPER mapper;
|
||||
|
||||
|
||||
@Override
|
||||
public ServerResponse add(T pojo) {
|
||||
int insert = mapper.insertSelective(pojo);
|
||||
if (insert!=1){
|
||||
throw new SystemException(BaseConst.SystemResponse.DATABASE_INSERT_FAILURE);
|
||||
}
|
||||
return ServerResponse.successMsg("添加成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse getById(ID id)
|
||||
{
|
||||
T t = mapper.selectByPrimaryKey(id);
|
||||
return ServerResponse.successData(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse getByCondition(T pojo,int pageSize,int pageNum,String orderBy){
|
||||
// 判断是否排序
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
}else{
|
||||
// 是否排序的标记
|
||||
boolean isOrderBy = false;
|
||||
// 判断传入的排序条件是否正确
|
||||
String[] split = orderBy.split(BaseConst.ORDER_SPLIT);
|
||||
if (split.length==2){
|
||||
Class<?> aClass = pojo.getClass();
|
||||
Field[] declaredFields = aClass.getDeclaredFields();
|
||||
for (Field declaredField : declaredFields) {
|
||||
String name = declaredField.getName();
|
||||
if (name.equals(split[0])){
|
||||
if (split[1].equals("desc")||split[1].equals("asc")){
|
||||
PageHelper.startPage(pageNum, pageSize,split[0]+BaseConst.ORDER_CONTACT+split[1]);
|
||||
isOrderBy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果排序条件不正确就简单分页查询
|
||||
if (isOrderBy == false){
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
}
|
||||
}
|
||||
List<T> list = mapper.selectByCondition(pojo);
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
return ServerResponse.successData(pageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse update(T pojo) {
|
||||
int i = mapper.updateByPrimaryKeySelective(pojo);
|
||||
if (i<1){
|
||||
ServerResponse.errorMsg("更新失败");
|
||||
}
|
||||
return ServerResponse.successMsg("更新成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse deleteById(ID id) {
|
||||
int i = mapper.deleteByPrimaryKey(id);
|
||||
if (i<1){
|
||||
ServerResponse.errorMsg("删除失败");
|
||||
}
|
||||
return ServerResponse.successMsg("删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse deleteByIds(List<ID> ids) {
|
||||
int i = mapper.deleteByPrimaryKeys(ids);
|
||||
if (i<1){
|
||||
ServerResponse.errorMsg("没有删除任何记录");
|
||||
}
|
||||
return ServerResponse.successMsg("删除成功");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.micro.fast.ssm.sharding.util;
|
||||
|
||||
/**
|
||||
* 永远
|
||||
*/
|
||||
public class My {
|
||||
private static final String world="李新";
|
||||
public static void main(String[] args) {
|
||||
System.out.println(My.world);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# 自动化装配
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.micro.fast.ssm.sharding.CommonApplication
|
||||
@@ -3,7 +3,7 @@
|
||||
`boot-starter-ssm`项目用于快速开启spring集成mybatis的项目,将本项目使用maven发布到本地仓库,在其他项
|
||||
目中引入该依赖进行相关配置即可使用.
|
||||
### boot-starter-ssm项目的参数配置
|
||||
得益于springboot的自动配置以及条件化装配的机制.我们可以扩展封装自己的ssm-boot,也是就是本项目中的commom,本项目的自定义扩展配置如下:
|
||||
得益于springboot的自动配置以及条件化装配的机制.我们可以扩展封装自己的ssm-boot,也是就是本项目中的boot-starter-ssm,本项目的自定义扩展配置如下:
|
||||
- 参考[druid官网的配置说明](https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter)
|
||||
- `mybatis.typeAliasesPackage` pojo包所在的位置(必要参数),如果要指定多个包的话使用逗号分割
|
||||
- `mybatis.mappers` mapper映射文件所在的路径(必要参数)
|
||||
@@ -12,4 +12,5 @@
|
||||
- 除此之外`mybatis`的`dao`层扫描的配置需要在项目中自行配置
|
||||
- 需要注意的是:当使用多数据源的时候,需要在使用的项目之中去除默认的数据源自动装配`@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)`
|
||||
- 对于数据源的切换方法是使用aop的方式对`@SwitchDataSource('数据源的名字')`进行拦截动态切换数据源,主数据源的名字是`master`,从数据源的名字是`slave`.对于没有注解默认的数据源是`master`.
|
||||
- PageHelper只对紧跟着的第一个SQL语句起作用
|
||||
- PageHelper只对紧跟着的第一个SQL语句起作用
|
||||
- 如果向定义n个数据源,在自己项目使用中定义bean即可,但是数据源的名字请不要使用`salve` `master` `masterDataSource` `dataSource` `dynamicDataSource`
|
||||
|
||||
@@ -23,5 +23,6 @@
|
||||
<module>boot-starter-elasticsearch</module>
|
||||
<module>boot-starter-security-oauth</module>
|
||||
<module>boot-starter-ssm</module>
|
||||
<module>boot-starter-ssm-sharding</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
+1
-1
@@ -7,10 +7,10 @@ import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
* 集群间服务调用情况的聚合展示
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
//集群间服务调用情况的聚合展示
|
||||
@EnableZipkinStreamServer
|
||||
public class MsMonitorZipkinApplication {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user