| | |
| | | package com.generater; |
| | | |
| | | import freemarker.cache.StringTemplateLoader; |
| | | import freemarker.template.Template; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.yeshi.utils.FileUtil; |
| | | import org.yeshi.utils.FreemarkerUtils; |
| | | import org.yeshi.utils.generater.SpringComponentGenerater; |
| | | import org.yeshi.utils.generater.annotation.admin.form.CheckBox; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Text; |
| | | import org.yeshi.utils.generater.entity.KeyValue; |
| | | import org.yeshi.utils.generater.entity.MongoDBDaoData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | import org.yeshi.utils.generater.entity.admin.AdminGeneraterInfo; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.MyBatisMapperUtil; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | import org.yeshi.utils.generater.vo.admin.FormAddInfoVO; |
| | | import org.yeshi.utils.generater.vo.admin.FormUpdateInfoVO; |
| | | import org.yeshi.utils.generater.vo.ExceptionVO; |
| | | import org.yeshi.utils.generater.vo.dao.MongoDBDaoVO; |
| | | import org.yeshi.utils.generater.vo.dao.MyBatisDBDaoVO; |
| | | import org.yeshi.utils.generater.vo.service.ServiceImplInfoVO; |
| | | import org.yeshi.utils.generater.vo.service.ServiceInfoVO; |
| | | import org.yeshi.utils.generater.vo.admin.controller.AdminControllerInfoVO; |
| | | import org.yeshi.utils.generater.vo.admin.page.FormUpdateInfoVO; |
| | | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.StringWriter; |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class GeneratorTest { |
| | | |
| | |
| | | // } |
| | | |
| | | |
| | | AdminGeneraterInfo info = new AdminGeneraterInfo.Builder().setEntityClass(TestEntity.class).build(); |
| | | // |
| | | // boolean match = Pattern.matches("^(https://){1}.*(\\.m3u8)$", "https://n1.szjal.cn/20210805/qnDXhXBa/index.m3u8123"); |
| | | // System.out.println(match); |
| | | generateMybatisDao(); |
| | | } |
| | | |
| | | private static void generateAdminPage() throws Exception { |
| | | AdminGeneraterInfo info = new AdminGeneraterInfo.Builder().setEntityClass(TestEntity.class).build(); |
| | | //将所有的控件模板加载进去 |
| | | String[] template = new String[]{ |
| | | "admin/form/checkBox.ftl", |
| | |
| | | } |
| | | String result = FreemarkerUtils.generateInputStream(new FormUpdateInfoVO.Builder().setAdminInfo(info).build(), "admin/update.ftl", map); |
| | | FileUtil.saveAsFileByte(result.getBytes("UTF-8"), "C:\\Users\\Administrator\\Documents\\HBuilderProjects\\LayuiTest\\form.html"); |
| | | |
| | | |
| | | System.out.println(result); |
| | | // |
| | | // boolean match = Pattern.matches("^(https://){1}.*(\\.m3u8)$", "https://n1.szjal.cn/20210805/qnDXhXBa/index.m3u8123"); |
| | | // System.out.println(match); |
| | | } |
| | | |
| | | |
| | | private static void generateService() throws Exception { |
| | | ClassInfo dao = new ClassInfo("TestDao", "com.test.dao.TestDao"); |
| | | ClassInfo query = new ClassInfo("TestQuery", "com.test.query.TestQuery"); |
| | | ClassInfo service = new ClassInfo("TestService", "com.test.service.TestService"); |
| | | ServiceInfoVO serviceInfoVO = new ServiceInfoVO.Builder().setDao(dao).setEntity(Entity.class).setPackageName("com.test.service").setQuery(query).setService(service).build(); |
| | | String result = FreemarkerUtils.generateInputStream(serviceInfoVO, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\service\\service.template")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | private static void generateServiceImpl() throws Exception { |
| | | ClassInfo dao = new ClassInfo("TestMapper", "com.test.dao.TestMapper"); |
| | | ClassInfo query = new ClassInfo("TestQuery", "com.test.query.TestQuery"); |
| | | ClassInfo service = new ClassInfo("TestService", "com.test.service.TestService"); |
| | | ClassInfo daoQuery = new ClassInfo("DaoQuery", "com.test.dao.query.DaoQuery"); |
| | | ServiceImplInfoVO serviceInfoVO = new ServiceImplInfoVO.Builder() |
| | | .setDao(dao) |
| | | .setEntity(Entity.class) |
| | | .setPackageName("com.test.service.impl") |
| | | .setQuery(query) |
| | | .setService(service) |
| | | .setDaoQuery(daoQuery) |
| | | .build(); |
| | | String result = FreemarkerUtils.generateInputStream(serviceInfoVO, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\service\\serviceImpl.template")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | |
| | | private static void generateAdminController() throws Exception { |
| | | AdminGeneraterInfo adminGeneraterInfo = new AdminGeneraterInfo.Builder().setEntityClass(TestEntity.class).build(); |
| | | ClassInfo query = new ClassInfo("TestQuery", "com.test.query.TestQuery"); |
| | | ClassInfo service = new ClassInfo("TestService", "com.test.service.TestService"); |
| | | AdminControllerInfoVO vo = new AdminControllerInfoVO.Builder().setAdminInfo(adminGeneraterInfo).setPackageName("com.test.controller.admin").setQueryVO(query).setService(service).build(); |
| | | String result = FreemarkerUtils.generateInputStream(vo, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\admin\\adminController.template")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | |
| | | private static void generateMongoDBDao() throws Exception { |
| | | MongoDBDaoVO vo = new MongoDBDaoVO.Builder().setBaseDao(new ClassInfo(BaseDao.class.getSimpleName(), BaseDao.class.getName())).setDao(new ClassInfo("TestDao", "com.test.dao.TestDao")).setEntity(TestEntity.class).build(); |
| | | String result = FreemarkerUtils.generateInputStream(vo, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\dao\\mongoDBDao.template")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | |
| | | private static void generateMybatisDao() throws Exception { |
| | | |
| | | MyBatisDBDaoVO vo = new MyBatisDBDaoVO |
| | | .Builder() |
| | | .setEntity(TestEntity2.class) |
| | | .setBaseMapper(new ClassInfo("BaseMapper", "com.test.mapper.BaseMapper")) |
| | | .setMapper(new ClassInfo("TestEntity2Mapper", "com.test.mapper.TestEntity2Mapper")) |
| | | .build(); |
| | | |
| | | |
| | | // String result = FreemarkerUtils.generateInputStream(vo, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\dao\\mybatisDBDao.template")); |
| | | String result = FreemarkerUtils.generateInputStream(vo, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\dao\\mybatisDBXML.ftl")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | private static void generateException() throws Exception { |
| | | ExceptionVO vo = new ExceptionVO.Builder() |
| | | .setEntity(Entity.class) |
| | | .setPackageName("com.test.exception").build(); |
| | | String result = FreemarkerUtils.generateInputStream(vo, GeneratorTest.class.getClassLoader().getResourceAsStream("generater\\exception.template")); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | |