diff --git a/examples/feign-example/pom.xml b/examples/feign-example/pom.xml new file mode 100644 index 0000000..6ac13fe --- /dev/null +++ b/examples/feign-example/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + + + com.chinaunicom.mall.ebtp.cloud + feign-example + 0.0.1-SNAPSHOT + jar + + feign-example + + + + com.chinaunicom.ebtp + mall-ebtp-cloud-feign-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleApplication.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleApplication.java new file mode 100644 index 0000000..99c592b --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleApplication.java @@ -0,0 +1,13 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@EnableFeignClients +@SpringBootApplication +public class FeignExampleApplication { + public static void main(String[] args) { + SpringApplication.run(FeignExampleApplication.class, args); + } +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/client/JSONPlaceHolderClient.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/client/JSONPlaceHolderClient.java new file mode 100644 index 0000000..1fc9128 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/client/JSONPlaceHolderClient.java @@ -0,0 +1,23 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.client; + +import java.util.List; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.config.ClientConfiguration; +import com.chinaunicom.mall.ebtp.cloud.feign.example.hystrix.JSONPlaceHolderFallback; +import com.chinaunicom.mall.ebtp.cloud.feign.example.model.Post; + +@FeignClient(value = "jplaceholder", url = "https://jsonplaceholder.typicode.com/", configuration = ClientConfiguration.class, fallback = JSONPlaceHolderFallback.class) +public interface JSONPlaceHolderClient { + + @RequestMapping(method = RequestMethod.GET, value = "/posts") + List getPosts(); + + @RequestMapping(method = RequestMethod.GET, value = "/posts/{postId}", produces = "application/json") + Post getPostById(@PathVariable("postId") Long postId); + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/ClientConfiguration.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/ClientConfiguration.java new file mode 100644 index 0000000..4f47799 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/ClientConfiguration.java @@ -0,0 +1,22 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import feign.Logger; +import feign.codec.ErrorDecoder; + +@Configuration +public class ClientConfiguration { + + @Bean + public Logger.Level feignLoggerLevel() { + return Logger.Level.FULL; + } + + @Bean + public ErrorDecoder errorDecoder() { + return new CustomErrorDecoder(); + } + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/CustomErrorDecoder.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/CustomErrorDecoder.java new file mode 100644 index 0000000..9b97bd2 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/config/CustomErrorDecoder.java @@ -0,0 +1,23 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.config; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.exception.BadRequestException; +import com.chinaunicom.mall.ebtp.cloud.feign.example.exception.NotFoundException; + +import feign.Response; +import feign.codec.ErrorDecoder; + +public class CustomErrorDecoder implements ErrorDecoder { + + @Override + public Exception decode(String methodKey, Response response) { + switch (response.status()) { + case 400: + return new BadRequestException(); + case 404: + return new NotFoundException(); + default: + return new Exception("Generic error"); + } + } + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/BadRequestException.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/BadRequestException.java new file mode 100644 index 0000000..ba9ec8c --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/BadRequestException.java @@ -0,0 +1,22 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.exception; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class BadRequestException extends Exception { + private static final long serialVersionUID = 1L; + + public BadRequestException(String message) { + super(message); + } + + public BadRequestException(Throwable cause) { + super(cause); + } + + @Override + public String toString() { + return "BadRequestException: " + getMessage(); + } + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/NotFoundException.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/NotFoundException.java new file mode 100644 index 0000000..b9ff7d2 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/exception/NotFoundException.java @@ -0,0 +1,23 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.exception; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class NotFoundException extends Exception { + + private static final long serialVersionUID = 1L; + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + @Override + public String toString() { + return "NotFoundException: " + getMessage(); + } + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/hystrix/JSONPlaceHolderFallback.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/hystrix/JSONPlaceHolderFallback.java new file mode 100644 index 0000000..784edc1 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/hystrix/JSONPlaceHolderFallback.java @@ -0,0 +1,24 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.hystrix; + +import java.util.Collections; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.client.JSONPlaceHolderClient; +import com.chinaunicom.mall.ebtp.cloud.feign.example.model.Post; + +@Component +public class JSONPlaceHolderFallback implements JSONPlaceHolderClient { + + @Override + public List getPosts() { + return Collections.emptyList(); + } + + @Override + public Post getPostById(Long postId) { + return null; + } + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/model/Post.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/model/Post.java new file mode 100644 index 0000000..bbc212c --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/model/Post.java @@ -0,0 +1,13 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.model; + +import lombok.Data; + +@Data +public class Post { + + private String userId; + private Long id; + private String title; + private String body; + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/JSONPlaceHolderService.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/JSONPlaceHolderService.java new file mode 100644 index 0000000..a60ea9d --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/JSONPlaceHolderService.java @@ -0,0 +1,13 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.service; + +import java.util.List; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.model.Post; + +public interface JSONPlaceHolderService { + + List getPosts(); + + Post getPostById(Long id); + +} diff --git a/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/impl/JSONPlaceHolderServiceImpl.java b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/impl/JSONPlaceHolderServiceImpl.java new file mode 100644 index 0000000..908cd20 --- /dev/null +++ b/examples/feign-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/feign/example/service/impl/JSONPlaceHolderServiceImpl.java @@ -0,0 +1,27 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example.service.impl; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.client.JSONPlaceHolderClient; +import com.chinaunicom.mall.ebtp.cloud.feign.example.model.Post; +import com.chinaunicom.mall.ebtp.cloud.feign.example.service.JSONPlaceHolderService; + +@Service +public class JSONPlaceHolderServiceImpl implements JSONPlaceHolderService { + + private @Autowired JSONPlaceHolderClient jsonPlaceHolderClient; + + @Override + public List getPosts() { + return jsonPlaceHolderClient.getPosts(); + } + + @Override + public Post getPostById(Long id) { + return jsonPlaceHolderClient.getPostById(id); + } + +} diff --git a/examples/feign-example/src/main/resources/application-feign.yml b/examples/feign-example/src/main/resources/application-feign.yml new file mode 100644 index 0000000..b39d7e0 --- /dev/null +++ b/examples/feign-example/src/main/resources/application-feign.yml @@ -0,0 +1,6 @@ +server: + port: 8762 + max-http-header-size: 1000000 + +app: + id: mall-ebtp-cloud-demo diff --git a/examples/feign-example/src/main/resources/application.yml b/examples/feign-example/src/main/resources/application.yml new file mode 100644 index 0000000..1a2bbf8 --- /dev/null +++ b/examples/feign-example/src/main/resources/application.yml @@ -0,0 +1,10 @@ +spring: + profiles: + active: feign + application: + name: mall-ebtp-cloud-demo + +logging: + level: + root: info + \ No newline at end of file diff --git a/examples/feign-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleTest.java b/examples/feign-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleTest.java new file mode 100644 index 0000000..fefaaeb --- /dev/null +++ b/examples/feign-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/feign/example/FeignExampleTest.java @@ -0,0 +1,39 @@ +package com.chinaunicom.mall.ebtp.cloud.feign.example; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.chinaunicom.mall.ebtp.cloud.feign.example.model.Post; +import com.chinaunicom.mall.ebtp.cloud.feign.example.service.JSONPlaceHolderService; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class FeignExampleTest { + private @Autowired JSONPlaceHolderService jsonPlaceHolderService; + + @Test + public void whenGetPosts_thenListPostSizeGreaterThanZero() { + List posts = jsonPlaceHolderService.getPosts(); + + System.out.println(posts.size()); + + assertFalse(posts.isEmpty()); + } + + @Test + public void whenGetPostWithId_thenPostExist() { + Post post = jsonPlaceHolderService.getPostById(1L); + + System.out.println(post); + + assertNotNull(post); + } +} diff --git a/examples/mybatis-plus-example/pom.xml b/examples/mybatis-plus-example/pom.xml new file mode 100644 index 0000000..a1dcae1 --- /dev/null +++ b/examples/mybatis-plus-example/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + + + com.chinaunicom.mall.ebtp.cloud + mybatis-plus-example + 0.0.1-SNAPSHOT + jar + + mybatis-plus-example + + + + com.chinaunicom.ebtp + mall-ebtp-cloud-jpa-starter + + + p6spy + p6spy + + + mysql + mysql-connector-java + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleApplication.java b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleApplication.java new file mode 100644 index 0000000..d4cf4fa --- /dev/null +++ b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleApplication.java @@ -0,0 +1,15 @@ +package com.chinaunicom.mall.ebtp.cloud.mybatis.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; + +import com.chinaunicom.mall.ebtp.cloud.jpa.starter.JpaStarterConfiguration; + +@SpringBootApplication +@Import(JpaStarterConfiguration.class) +public class MybatisPlusExampleApplication { + public static void main(String[] args) { + SpringApplication.run(MybatisPlusExampleApplication.class, args); + } +} diff --git a/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/mapper/DemoMapper.java b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/mapper/DemoMapper.java new file mode 100644 index 0000000..8a441ab --- /dev/null +++ b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/mapper/DemoMapper.java @@ -0,0 +1,11 @@ +package com.chinaunicom.mall.ebtp.cloud.mybatis.example.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.chinaunicom.mall.ebtp.cloud.mybatis.example.model.Demo; + +@Mapper +public interface DemoMapper extends BaseMapper { + +} diff --git a/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/model/Demo.java b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/model/Demo.java new file mode 100644 index 0000000..c54ef48 --- /dev/null +++ b/examples/mybatis-plus-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/model/Demo.java @@ -0,0 +1,21 @@ +package com.chinaunicom.mall.ebtp.cloud.mybatis.example.model; + +import java.sql.Date; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class Demo { + + private String id; + private String col1; + private String col2; + private String createBy; + private Date createTime; + private String updateBy; + private Date updateTime; + private int delFlag; + +} diff --git a/examples/mybatis-plus-example/src/main/resources/application-db.yml b/examples/mybatis-plus-example/src/main/resources/application-db.yml new file mode 100644 index 0000000..0780924 --- /dev/null +++ b/examples/mybatis-plus-example/src/main/resources/application-db.yml @@ -0,0 +1,27 @@ +logging: + level: + com.chinaunicom.mall.ebtp.cloud.mybatis.example: debug + +# database +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + url: jdbc:mysql://125.32.114.204:13306/ebtp-cloud?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + username: mall3-ebtp-dev + password: mall3-ebtp-dev + filters: stat,wall,log4j + maxActive: 20 + initialSize: 1 + maxWait: 60000 + minIdle: 1 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=50000000 + \ No newline at end of file diff --git a/examples/mybatis-plus-example/src/main/resources/application.yml b/examples/mybatis-plus-example/src/main/resources/application.yml new file mode 100644 index 0000000..8fa83af --- /dev/null +++ b/examples/mybatis-plus-example/src/main/resources/application.yml @@ -0,0 +1,10 @@ +spring: + profiles: + active: db + application: + name: mall-ebtp-cloud-demo + +logging: + level: + root: info + \ No newline at end of file diff --git a/examples/mybatis-plus-example/src/main/resources/spy.properties b/examples/mybatis-plus-example/src/main/resources/spy.properties new file mode 100644 index 0000000..0fbe28d --- /dev/null +++ b/examples/mybatis-plus-example/src/main/resources/spy.properties @@ -0,0 +1,21 @@ +modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory +# 自定义日志打印 +logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger +#日志输出到控制台 +appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger +# 使用日志系统记录 sql +#appender=com.p6spy.engine.spy.appender.Slf4JLogger +# 设置 p6spy driver 代理 +deregisterdrivers=true +# 取消JDBC URL前缀 +useprefix=true +# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset. +excludecategories=info,debug,result,commit,resultset +# 日期格式 +dateformat=yyyy-MM-dd HH:mm:ss +# 实际驱动可多个 +#driverlist=org.h2.Driver +# 是否开启慢SQL记录 +outagedetection=true +# 慢SQL记录标准 2 秒 +outagedetectioninterval=2 diff --git a/examples/mybatis-plus-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleTest.java b/examples/mybatis-plus-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleTest.java new file mode 100644 index 0000000..cdc3ca6 --- /dev/null +++ b/examples/mybatis-plus-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/mybatis/example/MybatisPlusExampleTest.java @@ -0,0 +1,116 @@ +package com.chinaunicom.mall.ebtp.cloud.mybatis.example; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.chinaunicom.mall.ebtp.cloud.mybatis.example.mapper.DemoMapper; +import com.chinaunicom.mall.ebtp.cloud.mybatis.example.model.Demo; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class MybatisPlusExampleTest { + + private @Autowired DemoMapper mapper; + + /** + * 测试插入函数 + */ + @Test + public void testInsert() { + Demo demo = new Demo(); + demo.setId("10"); + demo.setCol1("test"); + demo.setCol2("test01"); + + Assertions.assertThat(mapper.insert(demo)).isGreaterThan(0); + } +// +// /** +// * 测试删除函数 +// */ +// @Test +// public void delete() { +// // 根据属性删除记录 +// mapper.delete(new QueryWrapper().lambda().eq(Demo::getCol1, "test")); +// +// Assertions.assertThat(mapper.selectCount(new QueryWrapper().lambda().eq(Demo::getCol1, "test"))) +// .isEqualTo(0); +// } +// +// /** +// * 测试修改函数 +// */ +// @Test +// public void update() { +// // 通过id修改对象信息 +// mapper.updateById(new Demo().setId("1").setCol1("abc")); +// +// Assertions.assertThat(mapper.selectById("1").getCol1()).isEqualTo("abc"); +// +// // 使用条件修改和模板修改 +// mapper.update(new Demo().setCol1("12313"), +// Wrappers.lambdaUpdate().set(Demo::getCol2, "abc").eq(Demo::getCreateBy, "插入填充44")); +// +// Demo demo = mapper.selectOne(new QueryWrapper().lambda().eq(Demo::getCreateBy, "插入填充44")); +// Assertions.assertThat(demo.getCol1()).isEqualTo("12313"); +// Assertions.assertThat(demo.getCol2()).isEqualTo("abc"); +// +// // 仅使用条件修改 +// mapper.update(null, Wrappers.lambdaUpdate().set(Demo::getCol2, "col2").eq(Demo::getId, "2")); +// +// Assertions.assertThat(mapper.selectById("2").getCol2()).isEqualTo("col2"); +// +// // 使用自定义查询器就行修改 +// mapper.update(new Demo().setCol2("test03"), new QueryWrapper().lambda().eq(Demo::getId, "3")); +// +// Assertions.assertThat(mapper.selectById("3").getCol2()).isEqualTo("test03"); +// } +// +// /** +// * 测试查询方法 +// */ +// @Test +// public void find() { +// +// // 读取指定的属性 +// mapper.selectList(Wrappers.lambdaQuery().select(Demo::getId)).forEach(bean -> { +// Assertions.assertThat(bean.getId()).isNotNull(); +// Assertions.assertThat(bean.getCol1()).isNull(); +// Assertions.assertThat(bean.getCol2()).isNull(); +// Assertions.assertThat(bean.getCreateBy()).isNull(); +// }); +// +// // 另一种写法 +// mapper.selectList(new QueryWrapper().select("id", "createBy")).forEach(bean -> { +// Assertions.assertThat(bean.getId()).isNotNull(); +// Assertions.assertThat(bean.getCol1()).isNull(); +// Assertions.assertThat(bean.getCol2()).isNull(); +// Assertions.assertThat(bean.getCreateBy()).isNotNull(); +// }); +// } +// +// /** +// * 测试排序 +// */ +// @Test +// public void orderBy() { +// List list = mapper.selectList(Wrappers.query().orderByDesc("id")); +// Assertions.assertThat(list).isNotEmpty(); +// } +// +// /** +// * 使用map封装实体对象 +// */ +// @Test +// public void selectMaps() { +// List> mapList = mapper.selectMaps(Wrappers.query().select()); +// Assertions.assertThat(mapList).isNotEmpty(); +// +// System.out.println(mapList.get(0)); +// } + +} diff --git a/examples/redis-example/pom.xml b/examples/redis-example/pom.xml new file mode 100644 index 0000000..928d86c --- /dev/null +++ b/examples/redis-example/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + + + com.chinaunicom.mall.ebtp.cloud + redis-example + 0.0.1-SNAPSHOT + jar + + redis-example + + + + com.chinaunicom.ebtp + mall-ebtp-cloud-redis-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleApplication.java b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleApplication.java new file mode 100644 index 0000000..663c1b2 --- /dev/null +++ b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleApplication.java @@ -0,0 +1,11 @@ +package com.chinaunicom.mall.ebtp.cloud.redis.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RedisExampleApplication { + public static void main(String[] args) { + SpringApplication.run(RedisExampleApplication.class, args); + } +} diff --git a/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/RedisExampleService.java b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/RedisExampleService.java new file mode 100644 index 0000000..02839d6 --- /dev/null +++ b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/RedisExampleService.java @@ -0,0 +1,8 @@ +package com.chinaunicom.mall.ebtp.cloud.redis.example.service; + +public interface RedisExampleService { + + public void readAndWrite(); + public void transactionHandle(); + +} diff --git a/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/impl/RedisExampleServiceImpl.java b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/impl/RedisExampleServiceImpl.java new file mode 100644 index 0000000..216e610 --- /dev/null +++ b/examples/redis-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/redis/example/service/impl/RedisExampleServiceImpl.java @@ -0,0 +1,55 @@ +package com.chinaunicom.mall.ebtp.cloud.redis.example.service.impl; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.chinaunicom.mall.ebtp.cloud.redis.example.service.RedisExampleService; +import com.chinaunicom.mall.ebtp.cloud.redis.starter.handler.NumberHandler; +import com.chinaunicom.mall.ebtp.cloud.redis.starter.handler.StringHandler; +import com.chinaunicom.mall.ebtp.cloud.redis.starter.util.RedisUtil; + +@Service +public class RedisExampleServiceImpl implements RedisExampleService { + /** + * 演示工具类的基本使用方法 + */ + @Override + public void readAndWrite() { + StringHandler sh = RedisUtil.getStringHandler(); + sh.set("example-key", "example-value"); + + System.out.println(sh.get("example-key")); + } + + /** + * 演示事务的使用方式 + */ + @Override + public void transactionHandle() { + List execute = RedisUtil.getTransactionHandler(2).execute(handler -> { + handler.watch("redis-string-handler-key", "redis-number-handler-key");// 监控这些key + + // 开启事务 + handler.beginTransaction(); + + StringHandler stringHandler = handler.getStringHandler(); + stringHandler.set("redis-string-handler-key", "hello"); + stringHandler.append("redis-string-handler-key", "redis"); + stringHandler.append("redis-string-handler-key", "!"); + + // 获取对应事务数字助手 + NumberHandler numberHandler = handler.getNumberHandler(); + numberHandler.addLong("redis-number-handler-key", 100); + numberHandler.incrementLong("redis-number-handler-key"); + numberHandler.incrementLong("redis-number-handler-key"); + numberHandler.incrementLong("redis-number-handler-key"); + + // 提交事务返回结果 + return handler.commit(); + }); + System.out.println(Arrays.toString(execute.toArray())); + } + +} diff --git a/examples/redis-example/src/main/resources/application-redis.yml b/examples/redis-example/src/main/resources/application-redis.yml new file mode 100644 index 0000000..cb77b35 --- /dev/null +++ b/examples/redis-example/src/main/resources/application-redis.yml @@ -0,0 +1,18 @@ +server: + port: 8762 + max-http-header-size: 1000000 + +spring: + redis: + database: 0 + host: 125.32.114.204 + password: redis@CC1234 + port: 16379 + timeout: 6000 + ssl: false + lettuce: + pool: + max-wait: -1ms + max-active: 8 + max-idle: 8 + min-idle: 0 \ No newline at end of file diff --git a/examples/redis-example/src/main/resources/application.yml b/examples/redis-example/src/main/resources/application.yml new file mode 100644 index 0000000..71e65d1 --- /dev/null +++ b/examples/redis-example/src/main/resources/application.yml @@ -0,0 +1,10 @@ +spring: + profiles: + active: redis + application: + name: mall-ebtp-cloud-demo + +logging: + level: + root: info + \ No newline at end of file diff --git a/examples/redis-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleTest.java b/examples/redis-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleTest.java new file mode 100644 index 0000000..e2d0e3e --- /dev/null +++ b/examples/redis-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/redis/example/RedisExampleTest.java @@ -0,0 +1,27 @@ +package com.chinaunicom.mall.ebtp.cloud.redis.example; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.chinaunicom.mall.ebtp.cloud.redis.example.service.RedisExampleService; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class RedisExampleTest { + + private @Autowired RedisExampleService redisExampleService; + + @Test + public void testReadAndWrite() { + redisExampleService.readAndWrite(); + } + + @Test + public void testTransaction() { + redisExampleService.transactionHandle(); + } + +} diff --git a/examples/sharding-jdbc-example/pom.xml b/examples/sharding-jdbc-example/pom.xml new file mode 100644 index 0000000..72ac4aa --- /dev/null +++ b/examples/sharding-jdbc-example/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + com.chinaunicom.mall.ebtp.cloud + sharding-jdbc-example + 0.0.1-SNAPSHOT + jar + + sharding-jdbc-example + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/examples/sharding-jdbc-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/App.java b/examples/sharding-jdbc-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/App.java new file mode 100644 index 0000000..f2fa58d --- /dev/null +++ b/examples/sharding-jdbc-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/App.java @@ -0,0 +1,13 @@ +package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/examples/sharding-jdbc-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/AppTest.java b/examples/sharding-jdbc-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/AppTest.java new file mode 100644 index 0000000..9ecb54c --- /dev/null +++ b/examples/sharding-jdbc-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/shardingjdbc/example/AppTest.java @@ -0,0 +1,38 @@ +package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/examples/swagger-example/pom.xml b/examples/swagger-example/pom.xml new file mode 100644 index 0000000..f49a52b --- /dev/null +++ b/examples/swagger-example/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + + + com.chinaunicom.mall.ebtp.cloud + swagger-example + 0.0.1-SNAPSHOT + jar + + swagger-example + + + + com.chinaunicom.ebtp + mall-ebtp-cloud-mvc-starter + + + com.chinaunicom.ebtp + mall-ebtp-cloud-swagger-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/SwaggerExampleApplication.java b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/SwaggerExampleApplication.java new file mode 100644 index 0000000..6ae5a6a --- /dev/null +++ b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/SwaggerExampleApplication.java @@ -0,0 +1,15 @@ +package com.chinaunicom.mall.ebtp.cloud.swagger.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; + +import com.chinaunicom.mall.ebtp.cloud.swagger.starter.SwaggerStarterConfiguration; + +@SpringBootApplication +@Import(SwaggerStarterConfiguration.class) +public class SwaggerExampleApplication { + public static void main(String[] args) { + SpringApplication.run(SwaggerExampleApplication.class, args); + } +} diff --git a/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/controller/SwaggerExampleController.java b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/controller/SwaggerExampleController.java new file mode 100644 index 0000000..8c5c44f --- /dev/null +++ b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/controller/SwaggerExampleController.java @@ -0,0 +1,60 @@ +package com.chinaunicom.mall.ebtp.cloud.swagger.example.controller; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.chinaunicom.mall.ebtp.cloud.swagger.example.model.User; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import springfox.documentation.annotations.ApiIgnore; + +@RestController +@RequestMapping("/swagger") +@Api(value = "试Controller") +public class SwaggerExampleController { + + @ApiIgnore + @GetMapping("/hello") + public String hello() { + return "hello"; + } + + @ApiOperation(value = "回声服务", notes = "服务直接将客户消息返回") + @ApiImplicitParam(name = "message", value = "用户消息", required = true, dataType = "String", paramType = "path") + @GetMapping("/echo/{message}") + public String echo(@PathVariable("message") String message) { + return message; + } + + @ApiOperation(value = "创建用户", notes = "创建新的用户信息, 服务器创建成功后返回结果") + @ApiImplicitParam(name = "user", value = "用户基本信息", required = true, dataType = "User") + @PostMapping("/createUser") + public ResponseEntity createUser(@RequestBody User user) { + return ResponseEntity.ok(user); + } + + @ApiOperation(value = "修改用户", notes = "修改用户信息, 服务器返回执行结果") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path"), + @ApiImplicitParam(name = "user", value = "要修改的用户信息", required = true, dataType = "User") }) + @PutMapping("/updateUser/{id}") + public ResponseEntity> updateUser(@PathVariable("id") Long id, @RequestBody User user) { + Map result = new HashMap<>(); + result.put("result", "success"); + + return ResponseEntity.ok(result); + } + +} diff --git a/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/model/User.java b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/model/User.java new file mode 100644 index 0000000..fb3b8a6 --- /dev/null +++ b/examples/swagger-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/model/User.java @@ -0,0 +1,11 @@ +package com.chinaunicom.mall.ebtp.cloud.swagger.example.model; + +import lombok.Data; + +@Data +public class User { + + private String username; + private Integer age; + +} diff --git a/examples/swagger-example/src/main/resources/application-swagger.yml b/examples/swagger-example/src/main/resources/application-swagger.yml new file mode 100644 index 0000000..fcf6982 --- /dev/null +++ b/examples/swagger-example/src/main/resources/application-swagger.yml @@ -0,0 +1,15 @@ +server: + port: 8762 + max-http-header-size: 1000000 + +unifast: + swagger: + basePackage: com.chinaunicom.mall.ebtp.cloud.swagger.example + +# swagger 的基本配置信息(已经在starter中配置好) +#unifast.swagger.title=\u6d4b\u8bd5\u63a5\u53e3\u6587\u6863 +#unifast.swagger.contactName=\u5409\u6797\u9879\u76ee\u7ec4 +#unifast.swagger.contactUrl=http://chinaunicom.com +#unifast.swagger.contactEmail=chinaunicom@chinaunicom.com +#unifast.swagger.version=0.0.1 +#unifast.swagger.description=\u7840\u540e\u53f0\u529f\u80fd\u6846\u67b6 \ No newline at end of file diff --git a/examples/swagger-example/src/main/resources/application.yml b/examples/swagger-example/src/main/resources/application.yml new file mode 100644 index 0000000..b104620 --- /dev/null +++ b/examples/swagger-example/src/main/resources/application.yml @@ -0,0 +1,5 @@ +spring: + profiles: + active: swagger + application: + name: mall-ebtp-cloud-demo diff --git a/examples/swagger-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/AppTest.java b/examples/swagger-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/AppTest.java new file mode 100644 index 0000000..beb84cb --- /dev/null +++ b/examples/swagger-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/swagger/example/AppTest.java @@ -0,0 +1,38 @@ +package com.chinaunicom.mall.ebtp.cloud.swagger.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/mall-ebtp-cloud-parent/pom.xml b/mall-ebtp-cloud-parent/pom.xml index 2d6ec54..3ce3561 100644 --- a/mall-ebtp-cloud-parent/pom.xml +++ b/mall-ebtp-cloud-parent/pom.xml @@ -49,6 +49,11 @@ unifast-storage 1.0.0 + + p6spy + p6spy + 3.8.5 + commons-fileupload commons-fileupload