mirror of
https://gitee.com/jamen/slife.git
synced 2026-10-29 13:33:41 +00:00
加入规则引擎和代码生成模块
This commit is contained in:
@@ -12,5 +12,12 @@
|
||||
<name>slife-code</name>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.slife.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/12/28.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
public class CodeBaseController {
|
||||
|
||||
/**
|
||||
* 设置response 头部信息
|
||||
* @param response
|
||||
* @param data
|
||||
* @param zipName
|
||||
*/
|
||||
public void setResponseHead(HttpServletResponse response, byte[] data ,String zipName){
|
||||
response.reset();
|
||||
response.setHeader("Content-Disposition", "attachment; filename="+zipName);
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.slife.controller;
|
||||
|
||||
import com.slife.service.IPomService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
/**
|
||||
* Created by chen on 2017/12/28.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/code/pom")
|
||||
public class PomController extends CodeBaseController{
|
||||
|
||||
@Autowired
|
||||
private IPomService pomService;
|
||||
|
||||
/**
|
||||
* 创建一个 pom项目
|
||||
* @param response
|
||||
* @param parentVersion
|
||||
* @param artifactId
|
||||
* @param pomName
|
||||
* @param packageName
|
||||
* @param description
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public void create( HttpServletResponse response,
|
||||
@RequestParam("parentVersion") String parentVersion,
|
||||
@RequestParam("artifactId") String artifactId,
|
||||
@RequestParam("pomName") String pomName,
|
||||
@RequestParam("packageName") String packageName,
|
||||
@RequestParam(value = "description",required = false) String description) throws IOException {
|
||||
|
||||
byte[] data = pomService.createMavenCode(parentVersion,artifactId,pomName,packageName,description);
|
||||
setResponseHead(response,data,artifactId);
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.slife.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/12/28.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Service
|
||||
public interface IPomService {
|
||||
|
||||
|
||||
/**
|
||||
* 生成 maven 项目
|
||||
* @param parentVersion
|
||||
* @param artifactId
|
||||
* @param pomName
|
||||
* @param packageName
|
||||
* @param description
|
||||
* @return
|
||||
*/
|
||||
byte[] createMavenCode(String parentVersion, String artifactId, String pomName,String packageName, String description) ;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.slife.service.impl;
|
||||
|
||||
import com.slife.service.IPomService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* Created by chen on 2017/12/28.
|
||||
* <p>
|
||||
* Email 122741482@qq.com
|
||||
* <p>
|
||||
* Describe:
|
||||
*/
|
||||
@Service
|
||||
public class PomService implements IPomService {
|
||||
|
||||
/**
|
||||
* 生成 maven 项目
|
||||
* @param parentVersion
|
||||
* @param artifactId
|
||||
* @param pomName
|
||||
* @param packageName
|
||||
* @param description
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public byte[] createMavenCode(String parentVersion, String artifactId, String pomName,String packageName, String
|
||||
description) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
createPomFile(parentVersion,artifactId,pomName,description);
|
||||
createSrcFile(packageName);
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
private void createPomFile(String parentVersion, String artifactId,
|
||||
String pomName, String description) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void createSrcFile(String packageName) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
<artifactId>slife-sys</artifactId>
|
||||
|
||||
<name>slife-sys</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.slife</groupId>
|
||||
|
||||
Reference in New Issue
Block a user