50 changed files with 581 additions and 534 deletions
@ -0,0 +1,51 @@ |
|||
<?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"> |
|||
<parent> |
|||
<artifactId>epdc-commons</artifactId> |
|||
<groupId>com.esua.epdc</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>epdc-commons-api-version-control</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-autoconfigure</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-log4j2</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>com.vaadin.external.google</groupId> |
|||
<artifactId>android-json</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -0,0 +1,42 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import org.springframework.core.annotation.AnnotationUtils; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.servlet.mvc.condition.RequestCondition; |
|||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|||
|
|||
import java.lang.reflect.Method; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
public class ApiRequestMappingHandlerMapping extends RequestMappingHandlerMapping { |
|||
@Override |
|||
protected RequestCondition<?> getCustomMethodCondition(Method method) { |
|||
return createCondition(method.getClass()); |
|||
} |
|||
|
|||
@Override |
|||
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) { |
|||
return createCondition(handlerType); |
|||
} |
|||
|
|||
private static RequestCondition<ApiVersionCondition> createCondition(Class<?> clazz) { |
|||
RequestMapping classRequestMapping = AnnotationUtils.findAnnotation(clazz, RequestMapping.class); |
|||
if (classRequestMapping == null) { |
|||
return null; |
|||
} |
|||
StringBuilder mappingUrlBuilder = new StringBuilder(); |
|||
if (classRequestMapping.value().length > 0) { |
|||
mappingUrlBuilder.append(classRequestMapping.value()[0]); |
|||
} |
|||
String mappingUrl = mappingUrlBuilder.toString(); |
|||
String mappingUrlVersion = "{version}"; |
|||
if (!mappingUrl.contains(mappingUrlVersion)) { |
|||
return null; |
|||
} |
|||
ApiVersion apiVersion = AnnotationUtils.findAnnotation(clazz, ApiVersion.class); |
|||
return apiVersion == null ? new ApiVersionCondition(1) : new ApiVersionCondition(apiVersion.value()); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
@Target({ElementType.TYPE}) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface ApiVersion { |
|||
|
|||
/** |
|||
* 版本号 |
|||
* |
|||
* @return |
|||
*/ |
|||
int value(); |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
package com.elink.esua.epdc.commons.api.version; |
|||
|
|||
import org.springframework.web.servlet.mvc.condition.RequestCondition; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
public class ApiVersionCondition implements RequestCondition<ApiVersionCondition> { |
|||
private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("/v(\\d+).*"); |
|||
|
|||
private int apiVersion; |
|||
|
|||
ApiVersionCondition(int apiVersion) { |
|||
this.apiVersion = apiVersion; |
|||
} |
|||
|
|||
public int getApiVersion() { |
|||
return apiVersion; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public ApiVersionCondition combine(ApiVersionCondition apiVersionCondition) { |
|||
return new ApiVersionCondition(apiVersionCondition.getApiVersion()); |
|||
} |
|||
|
|||
@Override |
|||
public ApiVersionCondition getMatchingCondition(HttpServletRequest httpServletRequest) { |
|||
Matcher m = VERSION_PREFIX_PATTERN.matcher(httpServletRequest.getRequestURI()); |
|||
if (m.find()) { |
|||
Integer version = Integer.valueOf(m.group(1)); |
|||
if (version >= this.apiVersion) { |
|||
return this; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public int compareTo(ApiVersionCondition apiVersionCondition, HttpServletRequest httpServletRequest) { |
|||
return apiVersionCondition.getApiVersion() - this.apiVersion; |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.elink.esua.epdc.commons.api.version.config; |
|||
|
|||
import com.elink.esua.epdc.commons.api.version.ApiRequestMappingHandlerMapping; |
|||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|||
|
|||
/** |
|||
* @author rongchao |
|||
* @Date 18-11-24 |
|||
*/ |
|||
@Configuration |
|||
public class WebMvcRegistrationsConfig implements WebMvcRegistrations { |
|||
|
|||
@Override |
|||
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { |
|||
return new ApiRequestMappingHandlerMapping(); |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
|||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" |
|||
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" |
|||
xmlns:activiti="http://activiti.org/bpmn" |
|||
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" |
|||
xmlns:tns="http://www.activiti.org/test" |
|||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|||
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
expressionLanguage="http://www.w3.org/1999/XPath" |
|||
id="m1566628843418" |
|||
name="" |
|||
targetNamespace="http://www.activiti.org/test" |
|||
typeLanguage="http://www.w3.org/2001/XMLSchema"> |
|||
<process xmlns="" id="myProcess_1" isClosed="false" isExecutable="true" |
|||
processType="None"> |
|||
<startEvent id="_2" name="开始"/> |
|||
<userTask activiti:exclusive="true" id="_3" name="UserTask"> |
|||
<extensionElements> |
|||
<activiti:taskListener event="create"/> |
|||
</extensionElements> |
|||
</userTask> |
|||
</process> |
|||
<bpmndi:BPMNDiagram xmlns="" |
|||
documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" |
|||
id="Diagram-_1" |
|||
name="New Diagram"> |
|||
<bpmndi:BPMNPlane bpmnElement="myProcess_1"> |
|||
<bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2"> |
|||
<omgdc:Bounds height="32.0" width="32.0" x="245.0" y="100.0"/> |
|||
<bpmndi:BPMNLabel> |
|||
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/> |
|||
</bpmndi:BPMNLabel> |
|||
</bpmndi:BPMNShape> |
|||
<bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3"> |
|||
<omgdc:Bounds height="55.0" width="85.0" x="255.0" y="200.0"/> |
|||
<bpmndi:BPMNLabel> |
|||
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/> |
|||
</bpmndi:BPMNLabel> |
|||
</bpmndi:BPMNShape> |
|||
</bpmndi:BPMNPlane> |
|||
</bpmndi:BPMNDiagram> |
|||
</definitions> |
|||
@ -1,92 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.annotation.LogOperation; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|||
import com.elink.esua.epdc.dto.ModelDTO; |
|||
import com.elink.esua.epdc.service.ActModelService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.activiti.engine.repository.Model; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 模型管理 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("model") |
|||
@Api(tags="模型管理") |
|||
public class ActModelController { |
|||
@Autowired |
|||
private ActModelService actModelService; |
|||
|
|||
@GetMapping("page") |
|||
@ApiOperation("分页") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , |
|||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , |
|||
@ApiImplicitParam(name = "key", value = "key", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "name", value = "name", paramType = "query", dataType="String") |
|||
}) |
|||
public Result<PageData<Model>> page(@ApiIgnore @RequestParam Map<String, Object> params){ |
|||
PageData<Model> page = actModelService.page(params); |
|||
|
|||
return new Result<PageData<Model>>().ok(page); |
|||
} |
|||
|
|||
@PostMapping |
|||
@ApiOperation("新增模型") |
|||
@LogOperation("新增模型") |
|||
public Result save(@RequestBody ModelDTO dto) throws Exception{ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto); |
|||
|
|||
actModelService.save(dto.getName(), dto.getKey(), dto.getDescription()); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
@PostMapping("deploy/{id}") |
|||
@ApiOperation("部署") |
|||
@LogOperation("部署") |
|||
public Result deploy(@PathVariable("id") String id) { |
|||
actModelService.deploy(id); |
|||
return new Result(); |
|||
} |
|||
|
|||
@GetMapping("export/{id}") |
|||
@ApiOperation("导出") |
|||
@LogOperation("导出") |
|||
public void export(@PathVariable("id") String id, @ApiIgnore HttpServletResponse response) { |
|||
actModelService.export(id, response); |
|||
} |
|||
|
|||
@DeleteMapping |
|||
@ApiOperation("删除") |
|||
@LogOperation("删除") |
|||
public Result delete(@RequestBody String[] ids) { |
|||
for(String id : ids) { |
|||
actModelService.delete(id); |
|||
} |
|||
return new Result(); |
|||
} |
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.editor.main; |
|||
|
|||
import org.activiti.engine.ActivitiException; |
|||
import org.apache.commons.io.IOUtils; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.io.InputStream; |
|||
|
|||
/** |
|||
* Stencilset |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("service") |
|||
public class StencilsetRestResource { |
|||
|
|||
@RequestMapping(value="/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8") |
|||
public @ResponseBody String getStencilset() { |
|||
InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json"); |
|||
try { |
|||
return IOUtils.toString(stencilsetStream, "utf-8"); |
|||
} catch (Exception e) { |
|||
throw new ActivitiException("Error while loading stencil set", e); |
|||
} |
|||
} |
|||
} |
|||
@ -1,69 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.editor.model; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import org.activiti.editor.constants.ModelDataJsonConstants; |
|||
import org.activiti.engine.ActivitiException; |
|||
import org.activiti.engine.RepositoryService; |
|||
import org.activiti.engine.repository.Model; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* Model Editor |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("service") |
|||
public class ModelEditorJsonRestResource implements ModelDataJsonConstants { |
|||
|
|||
protected static final Logger LOGGER = LoggerFactory.getLogger(ModelEditorJsonRestResource.class); |
|||
|
|||
@Autowired |
|||
private RepositoryService repositoryService; |
|||
|
|||
@Autowired |
|||
private ObjectMapper objectMapper; |
|||
|
|||
@RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json") |
|||
public ObjectNode getEditorJson(@PathVariable String modelId) { |
|||
ObjectNode modelNode = null; |
|||
|
|||
Model model = repositoryService.getModel(modelId); |
|||
|
|||
if (model != null) { |
|||
try { |
|||
if (StringUtils.isNotEmpty(model.getMetaInfo())) { |
|||
modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); |
|||
} else { |
|||
modelNode = objectMapper.createObjectNode(); |
|||
modelNode.put(MODEL_NAME, model.getName()); |
|||
} |
|||
modelNode.put(MODEL_ID, model.getId()); |
|||
ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( |
|||
new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); |
|||
modelNode.set("model", editorJsonNode); |
|||
|
|||
} catch (Exception e) { |
|||
LOGGER.error("Error creating model JSON", e); |
|||
throw new ActivitiException("Error creating model JSON", e); |
|||
} |
|||
} |
|||
return modelNode; |
|||
} |
|||
} |
|||
@ -1,90 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.editor.model; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import com.elink.esua.epdc.commons.tools.xss.XssHttpServletRequestWrapper; |
|||
import org.activiti.editor.constants.ModelDataJsonConstants; |
|||
import org.activiti.engine.ActivitiException; |
|||
import org.activiti.engine.RepositoryService; |
|||
import org.activiti.engine.repository.Model; |
|||
import org.apache.batik.transcoder.TranscoderInput; |
|||
import org.apache.batik.transcoder.TranscoderOutput; |
|||
import org.apache.batik.transcoder.image.PNGTranscoder; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.InputStream; |
|||
|
|||
/** |
|||
* Model Rest |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("service") |
|||
public class ModelSaveRestResource implements ModelDataJsonConstants { |
|||
protected static final Logger LOGGER = LoggerFactory.getLogger(ModelSaveRestResource.class); |
|||
|
|||
@Autowired |
|||
private RepositoryService repositoryService; |
|||
@Autowired |
|||
private ObjectMapper objectMapper; |
|||
|
|||
@RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT) |
|||
@ResponseStatus(value = HttpStatus.OK) |
|||
public void saveModel(@PathVariable String modelId, HttpServletRequest request) { |
|||
try { |
|||
HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request); |
|||
String name = orgRequest.getParameter("name"); |
|||
String description = orgRequest.getParameter("description"); |
|||
String jsonXml = orgRequest.getParameter("json_xml"); |
|||
String svgXml = orgRequest.getParameter("svg_xml"); |
|||
|
|||
Model model = repositoryService.getModel(modelId); |
|||
|
|||
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); |
|||
|
|||
modelJson.put(MODEL_NAME, name); |
|||
modelJson.put(MODEL_DESCRIPTION, description); |
|||
model.setMetaInfo(modelJson.toString()); |
|||
model.setName(name); |
|||
|
|||
repositoryService.saveModel(model); |
|||
|
|||
repositoryService.addModelEditorSource(model.getId(), jsonXml.getBytes("utf-8")); |
|||
|
|||
InputStream svgStream = new ByteArrayInputStream(svgXml.getBytes("utf-8")); |
|||
TranscoderInput input = new TranscoderInput(svgStream); |
|||
|
|||
PNGTranscoder transcoder = new PNGTranscoder(); |
|||
// Setup output
|
|||
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
|||
TranscoderOutput output = new TranscoderOutput(outStream); |
|||
|
|||
// Do the transformation
|
|||
transcoder.transcode(input, output); |
|||
final byte[] result = outStream.toByteArray(); |
|||
repositoryService.addModelEditorSourceExtra(model.getId(), result); |
|||
outStream.close(); |
|||
|
|||
} catch (Exception e) { |
|||
LOGGER.error("Error saving model", e); |
|||
throw new ActivitiException("Error saving model", e); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,18 @@ |
|||
package com.elink.esua.epdc.rest.v2; |
|||
|
|||
import com.elink.esua.epdc.commons.api.version.ApiVersion; |
|||
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/2 14:29 |
|||
*/ |
|||
@ApiVersion(2) |
|||
@RestController("DemoControllerV2") |
|||
@RequestMapping("/demo" + Constant.VERSION_CONTROL) |
|||
public class DemoV2Controller { |
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.elink.esua.epdc.entity; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/2 13:54 |
|||
*/ |
|||
@Data |
|||
public class TransforDemoEntity { |
|||
|
|||
private Long demoId; |
|||
|
|||
private String demoName; |
|||
|
|||
private int demoAge; |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package com.elink.esua.epdc.transfor; |
|||
|
|||
import com.elink.esua.epdc.entity.DemoEntity; |
|||
import com.elink.esua.epdc.entity.TransforDemoEntity; |
|||
import ma.glasnost.orika.MapperFactory; |
|||
import net.rakugakibox.spring.boot.orika.OrikaMapperFactoryConfigurer; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/2 11:21 |
|||
*/ |
|||
@Component |
|||
public class Demo2DemoTransforEntity implements OrikaMapperFactoryConfigurer { |
|||
|
|||
@Override |
|||
public void configure(MapperFactory orikaMapperFactory) { |
|||
orikaMapperFactory.classMap(DemoEntity.class, TransforDemoEntity.class) |
|||
.field("id", "demoId") |
|||
.field("name", "demoName") |
|||
.field("age", "demoAge") |
|||
.byDefault() |
|||
.register(); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
package com.elink.esua.epdc; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.elink.esua.epdc.entity.DemoEntity; |
|||
import com.elink.esua.epdc.entity.TransforDemoEntity; |
|||
import ma.glasnost.orika.MapperFacade; |
|||
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; |
|||
|
|||
/** |
|||
* 实体映射测试类 |
|||
* |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/2 13:25 |
|||
*/ |
|||
@RunWith(SpringRunner.class) |
|||
@SpringBootTest |
|||
public class OrikaTest { |
|||
|
|||
@Autowired |
|||
private MapperFacade orikaMapper; |
|||
|
|||
@Test |
|||
public void Test() { |
|||
DemoEntity demoEntity = new DemoEntity(); |
|||
demoEntity.setId(1000L); |
|||
demoEntity.setName("name"); |
|||
demoEntity.setAge(19); |
|||
|
|||
TransforDemoEntity transforEntity = orikaMapper.map(demoEntity, TransforDemoEntity.class); |
|||
System.out.println(JSON.toJSONString(transforEntity)); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
registry { |
|||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa |
|||
type = "nacos" |
|||
|
|||
nacos { |
|||
serverAddr = "47.104.224.45" |
|||
namespace = "public" |
|||
cluster = "default" |
|||
} |
|||
} |
|||
|
|||
config { |
|||
# file、nacos 、apollo、zk、consul、etcd3 |
|||
type = "nacos" |
|||
|
|||
nacos { |
|||
serverAddr = "47.104.224.45" |
|||
namespace = "public" |
|||
cluster = "default" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue