parent
dde026fb50
commit
b882a41e5e
@ -0,0 +1,52 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import com.mashibing.test.entity.ClientTemplate;
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author kezhen
|
||||
* @date 2022/12/28
|
||||
* @description
|
||||
*/
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ClientTemplateMapperTest {
|
||||
|
||||
@Autowired
|
||||
private ClientTemplateMapper clientTemplateMapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@Test
|
||||
public void findBySignId() {
|
||||
List<ClientTemplate> clientTemplateList = clientTemplateMapper.findBySignId(15L);
|
||||
List<ClientTemplate> clientTemplateList2 = clientTemplateMapper.findBySignId(24L);
|
||||
for (ClientTemplate clientTemplate : clientTemplateList) {
|
||||
System.out.println("clientTemplate = " + clientTemplate);
|
||||
}
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<Map> value = clientTemplateList.stream().map(clientTemplate -> {
|
||||
try {
|
||||
return objectMapper.readValue(objectMapper.writeValueAsString(clientTemplate), Map.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
cacheClient.sadd("client_template:15", value.toArray(new Map[]{}));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue