feign starter 使用实例
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
@ -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<Demo> {
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -0,0 +1,10 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: db
|
||||
application:
|
||||
name: mall-ebtp-cloud-demo
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
|
@ -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
|
@ -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<Demo>().lambda().eq(Demo::getCol1, "test"));
|
||||
//
|
||||
// Assertions.assertThat(mapper.selectCount(new QueryWrapper<Demo>().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.<Demo>lambdaUpdate().set(Demo::getCol2, "abc").eq(Demo::getCreateBy, "插入填充44"));
|
||||
//
|
||||
// Demo demo = mapper.selectOne(new QueryWrapper<Demo>().lambda().eq(Demo::getCreateBy, "插入填充44"));
|
||||
// Assertions.assertThat(demo.getCol1()).isEqualTo("12313");
|
||||
// Assertions.assertThat(demo.getCol2()).isEqualTo("abc");
|
||||
//
|
||||
// // 仅使用条件修改
|
||||
// mapper.update(null, Wrappers.<Demo>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<Demo>().lambda().eq(Demo::getId, "3"));
|
||||
//
|
||||
// Assertions.assertThat(mapper.selectById("3").getCol2()).isEqualTo("test03");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 测试查询方法
|
||||
// */
|
||||
// @Test
|
||||
// public void find() {
|
||||
//
|
||||
// // 读取指定的属性
|
||||
// mapper.selectList(Wrappers.<Demo>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<Demo>().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<Demo> list = mapper.selectList(Wrappers.<Demo>query().orderByDesc("id"));
|
||||
// Assertions.assertThat(list).isNotEmpty();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 使用map封装实体对象
|
||||
// */
|
||||
// @Test
|
||||
// public void selectMaps() {
|
||||
// List<Map<String, Object>> mapList = mapper.selectMaps(Wrappers.<Demo>query().select());
|
||||
// Assertions.assertThat(mapList).isNotEmpty();
|
||||
//
|
||||
// System.out.println(mapList.get(0));
|
||||
// }
|
||||
|
||||
}
|
Reference in New Issue
Block a user