提交 85bbf1a4 编写于 作者: Z zyyang

change and test

上级 4e461ac2
...@@ -25,8 +25,8 @@ public class MybatisPlusConfig { ...@@ -25,8 +25,8 @@ public class MybatisPlusConfig {
public PaginationInterceptor paginationInterceptor() { public PaginationInterceptor paginationInterceptor() {
// return new PaginationInterceptor(); // return new PaginationInterceptor();
PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//TODO: mybatis-plus do not support TDengine, use mysql Dialect //TODO: mybatis-plus do not support TDengine, use postgresql Dialect
paginationInterceptor.setDialectType("mysql"); paginationInterceptor.setDialectType("postgresql");
return paginationInterceptor; return paginationInterceptor;
} }
......
...@@ -17,6 +17,7 @@ public interface TemperatureMapper extends BaseMapper<Temperature> { ...@@ -17,6 +17,7 @@ public interface TemperatureMapper extends BaseMapper<Temperature> {
@Update("drop table if exists temperature") @Update("drop table if exists temperature")
void dropSuperTable(); void dropSuperTable();
@Insert("insert into t${tbIndex}(ts, temperature) values(ts, temperature)") @Insert("insert into t${tbIndex}(ts, temperature) values(#{ts}, #{temperature})")
int insertOne(Temperature one); int insertOne(Temperature one);
} }
...@@ -20,6 +20,10 @@ spring: ...@@ -20,6 +20,10 @@ spring:
locale: en_US.UTF-8 locale: en_US.UTF-8
timezone: UTC-8 timezone: UTC-8
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
logging: logging:
level: level:
com: com:
......
...@@ -33,7 +33,7 @@ public class TemperatureMapperTest { ...@@ -33,7 +33,7 @@ public class TemperatureMapperTest {
mapper.createSuperTable(); mapper.createSuperTable();
// create table t_X using temperature // create table t_X using temperature
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
mapper.createTable("t_" + i, locations[random.nextInt(locations.length)], i); mapper.createTable("t" + i, locations[random.nextInt(locations.length)], i);
} }
// insert into table // insert into table
int affectRows = 0; int affectRows = 0;
...@@ -60,12 +60,18 @@ public class TemperatureMapperTest { ...@@ -60,12 +60,18 @@ public class TemperatureMapperTest {
@Autowired @Autowired
private TemperatureMapper mapper; private TemperatureMapper mapper;
/***
* test SelectList
* **/
@Test @Test
public void testSelectList() { public void testSelectList() {
List<Temperature> temperatureList = mapper.selectList(null); List<Temperature> temperatureList = mapper.selectList(null);
temperatureList.forEach(System.out::println); temperatureList.forEach(System.out::println);
} }
/***
* test InsertOne which is a custom metheod
* ***/
@Test @Test
public void testInsert() { public void testInsert() {
Temperature one = new Temperature(); Temperature one = new Temperature();
...@@ -76,16 +82,21 @@ public class TemperatureMapperTest { ...@@ -76,16 +82,21 @@ public class TemperatureMapperTest {
Assert.assertEquals(1, affectRows); Assert.assertEquals(1, affectRows);
} }
/***
* test SelectOne
* **/
@Test @Test
public void testSelectOne() { public void testSelectOne() {
QueryWrapper<Temperature> wrapper = new QueryWrapper<>(); QueryWrapper<Temperature> wrapper = new QueryWrapper<>();
wrapper.eq("location", "beijing"); wrapper.eq("location", "beijing");
Temperature one = mapper.selectOne(wrapper); Temperature one = mapper.selectOne(wrapper);
System.out.println(one); System.out.println(one);
Assert.assertEquals(12.22f, one.getTemperature(), 0.00f); Assert.assertNotNull(one);
Assert.assertEquals("beijing", one.getLocation());
} }
/***
* test select By map
* ***/
@Test @Test
public void testSelectByMap() { public void testSelectByMap() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
...@@ -94,18 +105,27 @@ public class TemperatureMapperTest { ...@@ -94,18 +105,27 @@ public class TemperatureMapperTest {
Assert.assertEquals(1, temperatures.size()); Assert.assertEquals(1, temperatures.size());
} }
/***
* test selectObjs
* **/
@Test @Test
public void testSelectObjs() { public void testSelectObjs() {
List<Object> ts = mapper.selectObjs(null); List<Object> ts = mapper.selectObjs(null);
System.out.println(ts); System.out.println(ts);
} }
/**
* test selectC ount
* **/
@Test @Test
public void testSelectCount() { public void testSelectCount() {
int count = mapper.selectCount(null); int count = mapper.selectCount(null);
Assert.assertEquals(5, count); Assert.assertEquals(5, count);
} }
/****
* 分页
*/
@Test @Test
public void testSelectPage() { public void testSelectPage() {
IPage page = new Page(1, 2); IPage page = new Page(1, 2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册