| | |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | |
| | | /** |
| | | * @author hxh |
| | |
| | | @Controller |
| | | public class GeneratorController { |
| | | |
| | | @RequestMapping("service") |
| | | //生成service |
| | | @RequestMapping("createService") |
| | | public void service(String name, String pks, String subpks, PrintWriter out, HttpServletRequest request) { |
| | | if (StringUtil.isNullOrEmpty(name) || StringUtil.isNullOrEmpty(pks) || StringUtil.isNullOrEmpty(subpks)) { |
| | | out.print(JsonUtil.loadFalseResult("项目名称,项目包名,应用包名不能为空")); |
| | |
| | | } |
| | | String rootPath = request.getServletContext().getRealPath("cache"); |
| | | try { |
| | | new ServiceBuilder().setCacheDir(rootPath).setName(name).setPks(pks).setSubpks(subpks).build(); |
| | | |
| | | String path = new ServiceBuilder().setCacheDir(rootPath).setName(name).setPks(pks).setSubpks(subpks).build(); |
| | | out.print(JsonUtil.loadTrueResult(path)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadFalseResult(e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("downloadServiceZIP") |
| | | public void downloadServiceZIP(String name, HttpServletResponse response) throws IOException { |
| | | if (!new File(name).exists()) { |
| | | response.sendError(406, "问价已被删除"); |
| | | return; |
| | | } |
| | | response.setHeader("content-disposition", "attachment;filename=" + new File(name).getName()); |
| | | //4.获取要下载的文件输入流 |
| | | InputStream in = new FileInputStream(new File(name).getAbsolutePath()); |
| | | int len = 0; |
| | | //5.创建数据缓冲区 |
| | | byte[] buffer = new byte[1024]; |
| | | //6.通过response对象获取OutputStream流 |
| | | OutputStream out = response.getOutputStream(); |
| | | //7.将FileInputStream流写入到buffer缓冲区 |
| | | while ((len = in.read(buffer)) > 0) { |
| | | //8.使用OutputStream将缓冲区的数据输出到客户端浏览器 |
| | | out.write(buffer, 0, len); |
| | | } |
| | | in.close(); |
| | | |
| | | } |
| | | |