11个文件已删除
9 文件已重命名
12个文件已修改
26个文件已添加
New file |
| | |
| | | package org.yeshi.utils.bean; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: BeanUtil |
| | | * @description: TODO |
| | | * @date 2021/10/11 14:01 |
| | | */ |
| | | public class BeanUtil { |
| | | |
| | | //复制属性 |
| | | public static Object copyProperties(Object source, Object target) throws IllegalAccessException { |
| | | Map<String, Field> targetFieldMap = new HashMap<>(); |
| | | Field[] fs = target.getClass().getDeclaredFields(); |
| | | for (Field field : fs) { |
| | | targetFieldMap.put(field.getName(), field); |
| | | } |
| | | fs = source.getClass().getDeclaredFields(); |
| | | for (Field field : fs) { |
| | | if (targetFieldMap.get(field.getName()) == null) |
| | | continue; |
| | | //获取对象的属性值 |
| | | field.setAccessible(true); |
| | | Object resultValue = field.get(source); |
| | | targetFieldMap.get(field.getName()).setAccessible(true); |
| | | targetFieldMap.get(field.getName()).set(target, resultValue); |
| | | } |
| | | return target; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package org.yeshi.utils.generater; |
| | | |
| | | import org.yeshi.utils.FreemarkerUtils; |
| | | import org.yeshi.utils.generater.entity.ExceptionData; |
| | | import org.yeshi.utils.generater.entity.MongoDBDaoData; |
| | | import org.yeshi.utils.generater.vo.ServiceInfoVO; |
| | | |
| | | import java.io.File; |
| | | |
| | | public class SpringComponentGenerater { |
| | | |
| | | /** |
| | | * 创建mongodb的dao |
| | | * |
| | | * @param data |
| | | * @param targetDir |
| | | * @throws Exception |
| | | */ |
| | | public static void createMongoDao(MongoDBDaoData data, String targetDir) throws Exception { |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/mongoDBDao.template"), new File(targetDir, data.getDaoName() + ".java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | /** |
| | | * 创建服务 |
| | | * |
| | | * @param data |
| | | * @param targetDir |
| | | * @throws Exception |
| | | */ |
| | | public static void createService(ServiceInfoVO data, String targetDir) throws Exception { |
| | | |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/service/service.template"), new File(targetDir, data.getServiceClassName() + ".java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | /** |
| | | * 创建服务实现 |
| | | * |
| | | * @param data |
| | | * @param targetDir |
| | | * @throws Exception |
| | | */ |
| | | public static void createServiceImpl(ServiceInfoVO data, String targetDir) throws Exception { |
| | | |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/service/serviceImpl.template"), new File(targetDir, data.getServiceClassName() + "Impl.java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void createException(ExceptionData data, String targetDir) throws Exception { |
| | | |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("exception.template"), new File(targetDir, data.getEntityClassName() + "Exception.java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | //默认开启分页 |
| | | boolean page() default true; |
| | | |
| | | boolean jsonp() default false; |
| | | |
| | | Class searchForm() default Void.class; |
| | | |
| | | } |
| | |
| | | |
| | | public ClassInfo(String name, String clazz) { |
| | | this.name = name; |
| | | this.clazz = clazz; |
| | | this.clazz = clazz.replace("$","."); |
| | | } |
| | | |
| | | public String getName() { |
| | |
| | | } |
| | | |
| | | public void setClazz(String clazz) { |
| | | this.clazz = clazz; |
| | | this.clazz = clazz.replace("$","."); |
| | | } |
| | | } |
| | |
| | | //查询方式 |
| | | private DaoQueryCondition.QueryType queryType; |
| | | |
| | | public DaoQueryColumnData(String columnName, String type, DaoQueryCondition.QueryType queryType) { |
| | | super(columnName, type); |
| | | //针对的列 |
| | | private MybatisColumnData columnData; |
| | | |
| | | |
| | | public DaoQueryColumnData(String property, String type, DaoQueryCondition.QueryType queryType) { |
| | | super(property, type); |
| | | this.queryType = queryType; |
| | | } |
| | | |
| | | public DaoQueryColumnData(String property, MybatisColumnData columnData, String type, DaoQueryCondition.QueryType queryType) { |
| | | super(property, type); |
| | | this.queryType = queryType; |
| | | this.columnData = columnData; |
| | | } |
| | | |
| | | |
| | |
| | | public void setQueryType(DaoQueryCondition.QueryType queryType) { |
| | | this.queryType = queryType; |
| | | } |
| | | |
| | | public MybatisColumnData getColumnData() { |
| | | return columnData; |
| | | } |
| | | |
| | | public void setColumnData(MybatisColumnData columnData) { |
| | | this.columnData = columnData; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.entity; |
| | | |
| | | import org.yeshi.utils.generater.annotation.admin.DaoQueryCondition; |
| | | |
| | | public class MapperQueryColumnData { |
| | | |
| | | //查询方式 |
| | | private DaoQueryCondition.QueryType queryType; |
| | | private String property; |
| | | private MybatisColumnData column; |
| | | |
| | | |
| | | public DaoQueryCondition.QueryType getQueryType() { |
| | | return queryType; |
| | | } |
| | | |
| | | public void setQueryType(DaoQueryCondition.QueryType queryType) { |
| | | this.queryType = queryType; |
| | | } |
| | | |
| | | public String getProperty() { |
| | | return property; |
| | | } |
| | | |
| | | public void setProperty(String property) { |
| | | this.property = property; |
| | | } |
| | | |
| | | public MybatisColumnData getColumn() { |
| | | return column; |
| | | } |
| | | |
| | | public void setColumn(MybatisColumnData column) { |
| | | this.column = column; |
| | | } |
| | | } |
| | |
| | | |
| | | private String column; |
| | | private String property; |
| | | //jdbcType |
| | | private String type; |
| | | |
| | | public MybatisColumnData(String column, String property, String type) { |
| | | private String jdbcType; |
| | | |
| | | public MybatisColumnData(String column, String property, String type, String jdbcType) { |
| | | this.column = column; |
| | | this.property = property; |
| | | this.type = type; |
| | | this.jdbcType = jdbcType; |
| | | } |
| | | |
| | | public String getColumn() { |
| | |
| | | public void setType(String type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getJdbcType() { |
| | | return jdbcType; |
| | | } |
| | | |
| | | public void setJdbcType(String jdbcType) { |
| | | this.jdbcType = jdbcType; |
| | | } |
| | | } |
| | |
| | | if (an instanceof AdminController) { |
| | | Class searchFormClass = ((AdminController) an).searchForm(); |
| | | AdminGeneraterInfo info = new AdminGeneraterInfo(); |
| | | info.setEntity(entity); |
| | | info.setControllerData((AdminController) an); |
| | | info.setSearchFormRows(AnotationUtil.getFormRowData(searchFormClass)); |
| | | info.setAddFormRows(AnotationUtil.getFormRowData(entity)); |
| | |
| | | if (type.equalsIgnoreCase("Date")) { |
| | | String tempProperty = "min" + property.substring(0, 1).toUpperCase() + property.substring(1); |
| | | buffer.append(String.format("\tpublic %s %s;", type, tempProperty)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, tempProperty, type)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, tempProperty, type,ColumnParseUtil.getJDBCType(genericType))); |
| | | buffer.append("\n\t"); |
| | | tempProperty = "max" + property.substring(0, 1).toUpperCase() + property.substring(1); |
| | | buffer.append(String.format("\tpublic %s %s;", type, tempProperty)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, tempProperty, type)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, tempProperty, type,ColumnParseUtil.getJDBCType(genericType))); |
| | | buffer.append("\n\t"); |
| | | } else { |
| | | buffer.append(String.format("\tpublic %s %s;", type, property)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, property, type)); |
| | | queryColumnData.add(new MybatisColumnData(columnName, property, type,ColumnParseUtil.getJDBCType(genericType))); |
| | | buffer.append("\n\t"); |
| | | } |
| | | } |
| | |
| | | return queryColumnData; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void createMapper(Class<?> clz) { |
| | | // 生成mapper java文件 |
| | | String pks = getDaoPackageName(clz); |
New file |
| | |
| | | package org.yeshi.utils.generater.util; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.Field; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: EntityUtil |
| | | * @description: 实体帮助类 |
| | | * @date 2021/10/11 12:13 |
| | | */ |
| | | public class EntityUtil { |
| | | |
| | | //获取主键ID |
| | | public static Field getIdentifyId(Class clazz) { |
| | | Field[] fs = clazz.getDeclaredFields(); |
| | | for (Field fd : fs) { |
| | | Annotation[] as = fd.getAnnotations(); |
| | | if (as != null) |
| | | for (Annotation a : as) { |
| | | if (a instanceof Id) { |
| | | return fd; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.entity.BaseData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | |
| | | import javax.annotation.Nullable; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: ExceptionVO |
| | | * @description: 自定义异常输出 |
| | | * @date 2021/10/12 10:30 |
| | | */ |
| | | public class ExceptionVO extends BaseData { |
| | | |
| | | private ClassInfo base; |
| | | |
| | | public static class Builder { |
| | | private ClassInfo base; |
| | | private Class entity; |
| | | private String packageName; |
| | | |
| | | |
| | | public Builder setBase(@Nullable ClassInfo base) { |
| | | this.base = base; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setEntity(Class entity) { |
| | | this.entity = entity; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setPackageName(String packageName) { |
| | | this.packageName = packageName; |
| | | return this; |
| | | } |
| | | |
| | | public ExceptionVO build() throws Exception { |
| | | if (entity == null) { |
| | | throw new Exception("entity不能为空"); |
| | | } |
| | | |
| | | if (this.base == null) { |
| | | this.base = new ClassInfo(Exception.class.getSimpleName(), Exception.class.getName()); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(packageName)) { |
| | | throw new Exception("packageName不能为空"); |
| | | } |
| | | |
| | | ExceptionVO vo = new ExceptionVO(); |
| | | vo.setBase(base); |
| | | vo.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | vo.setPackageName(packageName); |
| | | return vo; |
| | | } |
| | | } |
| | | |
| | | |
| | | public ClassInfo getBase() { |
| | | return base; |
| | | } |
| | | |
| | | public void setBase(ClassInfo base) { |
| | | this.base = base; |
| | | } |
| | | } |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/AdminControllerInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.controller; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Text; |
| | | import org.yeshi.utils.generater.annotation.admin.form.TextArea; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | import org.yeshi.utils.generater.entity.KeyValue; |
| | | import org.yeshi.utils.generater.entity.admin.AdminGeneraterInfo; |
| | | import org.yeshi.utils.generater.entity.admin.FormRowData; |
| | | import org.yeshi.utils.generater.entity.admin.FormVerifyType; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.yeshi.utils.generater.util.EntityUtil; |
| | | |
| | | /** |
| | | * @author Administrator |
| | |
| | | private ClassInfo entity; |
| | | private ClassInfo service; |
| | | private ClassInfo query; |
| | | private boolean jsonp; |
| | | //主键类型 |
| | | private String identifyIdType; |
| | | |
| | | |
| | | public static class Builder { |
| | |
| | | AdminControllerInfoVO vo = new AdminControllerInfoVO(); |
| | | vo.setMapping(generaterInfo.getControllerData().mapping()); |
| | | vo.setEntity(new ClassInfo(generaterInfo.getEntity().getSimpleName(), generaterInfo.getEntity().getName())); |
| | | vo.setJsonp(generaterInfo.getControllerData().jsonp()); |
| | | vo.setPackageName(packageName); |
| | | vo.setQueryVO(query); |
| | | vo.setService(service); |
| | | vo.setIdentifyIdType(EntityUtil.getIdentifyId(generaterInfo.getEntity()).getType().getSimpleName()); |
| | | return vo; |
| | | } |
| | | |
| | |
| | | public void setQueryVO(ClassInfo query) { |
| | | this.query = query; |
| | | } |
| | | |
| | | public void setQuery(ClassInfo query) { |
| | | this.query = query; |
| | | } |
| | | |
| | | public boolean isJsonp() { |
| | | return jsonp; |
| | | } |
| | | |
| | | public void setJsonp(boolean jsonp) { |
| | | this.jsonp = jsonp; |
| | | } |
| | | |
| | | public String getIdentifyIdType() { |
| | | return identifyIdType; |
| | | } |
| | | |
| | | public void setIdentifyIdType(String identifyIdType) { |
| | | this.identifyIdType = identifyIdType; |
| | | } |
| | | } |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/FormAddInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.page; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/FormHttpRequestInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.page; |
| | | |
| | | |
| | | import java.util.Map; |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/FormInputRegexVerifyVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.page; |
| | | |
| | | /** |
| | | * @author Administrator |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/FormUpdateInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.page; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/admin/ListInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | package org.yeshi.utils.generater.vo.admin.page; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
File was renamed from src/main/java/org/yeshi/utils/generater/entity/MongoDBDaoData.java |
| | |
| | | package org.yeshi.utils.generater.entity; |
| | | package org.yeshi.utils.generater.vo.dao; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.yeshi.utils.generater.annotation.admin.DaoQueryCondition; |
| | | import org.yeshi.utils.generater.entity.BaseData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | import org.yeshi.utils.generater.entity.ColumnData; |
| | | import org.yeshi.utils.generater.entity.DaoQueryColumnData; |
| | | |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.Field; |
| | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | public class MongoDBDaoData extends BaseData { |
| | | public class MongoDBDaoVO extends BaseData { |
| | | |
| | | private String daoName; |
| | | private String baseDaoClassName; |
| | | private String entityClassName; |
| | | private ClassInfo baseDao; |
| | | private ClassInfo entity; |
| | | private Set<String> importClasses; |
| | | |
| | | private ColumnData identityColumn; |
| | |
| | | |
| | | public static class Builder { |
| | | |
| | | private Class baseDaoClass; |
| | | private ClassInfo baseDao; |
| | | private Class entity; |
| | | private ClassInfo dao; |
| | | |
| | | private Class entityClass; |
| | | |
| | | private String daoPackageName; |
| | | |
| | | private String daoName; |
| | | |
| | | |
| | | public Builder setBaseDaoClass(Class clazz) { |
| | | this.baseDaoClass = clazz; |
| | | public Builder setBaseDao(ClassInfo baseDao) { |
| | | this.baseDao = baseDao; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setEntityClass(Class clazz) { |
| | | this.entityClass = clazz; |
| | | public Builder setEntity(Class entity) { |
| | | this.entity = entity; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setDaoPackageName(String daoPackageName) { |
| | | this.daoPackageName = daoPackageName; |
| | | public Builder setDao(ClassInfo dao) { |
| | | this.dao = dao; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setDaoName(String daoName) { |
| | | this.daoName = daoName; |
| | | return this; |
| | | public MongoDBDaoVO build() throws Exception { |
| | | |
| | | if (entity == null) { |
| | | throw new Exception("entity不能为空"); |
| | | } |
| | | |
| | | if (baseDao == null) { |
| | | throw new Exception("baseDao不能为空"); |
| | | } |
| | | |
| | | if (dao == null) { |
| | | throw new Exception("dao不能为空"); |
| | | } |
| | | |
| | | |
| | | public MongoDBDaoData create() { |
| | | |
| | | if (daoName == null) { |
| | | daoName = entityClass.getSimpleName() + "Dao"; |
| | | } |
| | | |
| | | Field[] fields = entityClass.getDeclaredFields(); |
| | | Field[] fields = entity.getDeclaredFields(); |
| | | String identityColumnName = null; |
| | | String identityColumnType = null; |
| | | List<ColumnData> columlist = new ArrayList<>(); |
| | |
| | | if (fd.getModifiers() != 1 && fd.getModifiers() != 2) { |
| | | continue; |
| | | } |
| | | |
| | | String columName = fd.getName(); |
| | | String columnDataType = fd.getGenericType().getTypeName(); |
| | | Annotation[] as = fd.getAnnotations(); |
| | | |
| | | |
| | | if (columName != null) { |
| | | for (Annotation a : as) { |
| | | //主键 |
| | |
| | | importClasses.add("java.util.ArrayList"); |
| | | |
| | | |
| | | MongoDBDaoData data = new MongoDBDaoData(); |
| | | data.setBaseDaoClassName(baseDaoClass.getSimpleName()); |
| | | MongoDBDaoVO data = new MongoDBDaoVO(); |
| | | data.setBaseDao(baseDao); |
| | | data.setColumnDataList(columnDataList); |
| | | data.setDaoQueryColumnDataList(daoQueryColumnList); |
| | | data.setDaoName(daoName); |
| | | data.setEntityClass(entityClass.getName()); |
| | | data.setEntityClassName(entityClass.getSimpleName()); |
| | | data.setDaoName(dao.getName()); |
| | | data.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | data.setIdentityColumn(new ColumnData(identityColumnName, identityColumnType)); |
| | | data.setPackageName(daoPackageName); |
| | | data.setPackageName(dao.getClazz().replace("." + dao.getName(), "")); |
| | | |
| | | importClasses.add(baseDaoClass.getName()); |
| | | importClasses.add(entityClass.getName()); |
| | | importClasses.add(baseDao.getClazz()); |
| | | importClasses.add(entity.getName()); |
| | | data.setImportClasses(importClasses); |
| | | |
| | | return data; |
| | |
| | | this.daoName = daoName; |
| | | } |
| | | |
| | | public String getBaseDaoClassName() { |
| | | return baseDaoClassName; |
| | | public ClassInfo getBaseDao() { |
| | | return baseDao; |
| | | } |
| | | |
| | | public void setBaseDaoClassName(String baseDaoClassName) { |
| | | this.baseDaoClassName = baseDaoClassName; |
| | | public void setBaseDao(ClassInfo baseDao) { |
| | | this.baseDao = baseDao; |
| | | } |
| | | |
| | | public String getEntityClassName() { |
| | | return entityClassName; |
| | | @Override |
| | | public ClassInfo getEntity() { |
| | | return entity; |
| | | } |
| | | |
| | | public void setEntityClassName(String entityClassName) { |
| | | this.entityClassName = entityClassName; |
| | | @Override |
| | | public void setEntity(ClassInfo entity) { |
| | | this.entity = entity; |
| | | } |
| | | |
| | | |
| | | public ColumnData getIdentityColumn() { |
| | | return identityColumn; |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.dao; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.yeshi.utils.generater.annotation.admin.DaoQueryCondition; |
| | | import org.yeshi.utils.generater.entity.*; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.ColumnParseUtil; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | import org.yeshi.utils.generater.vo.ExceptionVO; |
| | | |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | public class MyBatisDBDaoVO extends BaseData { |
| | | |
| | | private ClassInfo mapper; |
| | | private ClassInfo baseMapper; |
| | | //主键 |
| | | private MybatisColumnData identify; |
| | | //属性 |
| | | private List<MybatisColumnData> columnList; |
| | | private List<DaoQueryColumnData> queryList; |
| | | private String table; |
| | | |
| | | public static class Builder { |
| | | |
| | | private ClassInfo baseMapper; |
| | | private Class entity; |
| | | private ClassInfo mapper; |
| | | |
| | | public Builder setBaseMapper(ClassInfo baseMapper) { |
| | | this.baseMapper = baseMapper; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setEntity(Class entity) { |
| | | this.entity = entity; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setMapper(ClassInfo mapper) { |
| | | this.mapper = mapper; |
| | | return this; |
| | | } |
| | | |
| | | //获取table |
| | | |
| | | private String getTableName(Class clz) throws Exception { |
| | | Annotation[] as = clz.getAnnotations(); |
| | | for (Annotation a : as) { |
| | | if (a instanceof Table) { |
| | | Table t = (Table) a; |
| | | return t.value(); |
| | | } |
| | | } |
| | | throw new Exception("未获取到表名称"); |
| | | } |
| | | |
| | | public MyBatisDBDaoVO build() throws Exception { |
| | | |
| | | if (entity == null) { |
| | | throw new Exception("entity不能为空"); |
| | | } |
| | | |
| | | if (baseMapper == null) { |
| | | throw new Exception("baseMapper不能为空"); |
| | | } |
| | | |
| | | if (mapper == null) { |
| | | throw new Exception("mapper不能为空"); |
| | | } |
| | | |
| | | //获取table名称 |
| | | String table = getTableName(entity); |
| | | |
| | | Field[] fields = entity.getDeclaredFields(); |
| | | MybatisColumnData identity = null; |
| | | List<MybatisColumnData> columlist = new ArrayList<>(); |
| | | List<DaoQueryColumnData> daoQueryColumnList = new ArrayList<>(); |
| | | for (Field fd : fields) { |
| | | //private/public 非final,static属性才会参与解析 |
| | | if (fd.getModifiers() != 1 && fd.getModifiers() != 2) { |
| | | continue; |
| | | } |
| | | boolean valid = true; |
| | | |
| | | Annotation[] as = fd.getAnnotations(); |
| | | for (Annotation a : as) { |
| | | //不参与解析 |
| | | if (a instanceof Transient || a instanceof java.beans.Transient) { |
| | | valid = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!valid) { |
| | | continue; |
| | | } |
| | | |
| | | String property = fd.getName(); |
| | | String column = fd.getName(); |
| | | for (Annotation a : as) { |
| | | //不参与解析 |
| | | if (a instanceof Column) { |
| | | column = ((Column) a).name(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | MybatisColumnData columData = new MybatisColumnData(column, property, fd.getType().getSimpleName(), ColumnParseUtil.getJDBCType(fd.getType().getName())); |
| | | |
| | | |
| | | for (Annotation a : as) { |
| | | //主键 |
| | | if (a instanceof Id) { |
| | | identity = columData; |
| | | valid = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!valid) { |
| | | continue; |
| | | } |
| | | |
| | | columlist.add(columData); |
| | | |
| | | |
| | | //获取查询条件 |
| | | for (Annotation a : as) { |
| | | if (a instanceof DaoQueryCondition) { |
| | | daoQueryColumnList.add(new DaoQueryColumnData(columData.getProperty(), columData, fd.getType().getSimpleName(), ((DaoQueryCondition) a).queryType())); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (identity == null) |
| | | throw new Exception("尚未指定主键"); |
| | | |
| | | |
| | | MyBatisDBDaoVO vo = new MyBatisDBDaoVO(); |
| | | vo.setBaseMapper(baseMapper); |
| | | vo.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | vo.setIdentify(identity); |
| | | vo.setTable(table); |
| | | vo.setQueryList(daoQueryColumnList); |
| | | vo.setPackageName(mapper.getClazz().replace("." + mapper.getName(), "")); |
| | | vo.setMapper(mapper); |
| | | vo.setColumnList(columlist); |
| | | return vo; |
| | | } |
| | | } |
| | | |
| | | public ClassInfo getMapper() { |
| | | return mapper; |
| | | } |
| | | |
| | | public void setMapper(ClassInfo mapper) { |
| | | this.mapper = mapper; |
| | | } |
| | | |
| | | public ClassInfo getBaseMapper() { |
| | | return baseMapper; |
| | | } |
| | | |
| | | public void setBaseMapper(ClassInfo baseMapper) { |
| | | this.baseMapper = baseMapper; |
| | | } |
| | | |
| | | |
| | | public MybatisColumnData getIdentify() { |
| | | return identify; |
| | | } |
| | | |
| | | public void setIdentify(MybatisColumnData identify) { |
| | | this.identify = identify; |
| | | } |
| | | |
| | | public List<MybatisColumnData> getColumnList() { |
| | | return columnList; |
| | | } |
| | | |
| | | public void setColumnList(List<MybatisColumnData> columnList) { |
| | | this.columnList = columnList; |
| | | } |
| | | |
| | | public List<DaoQueryColumnData> getQueryList() { |
| | | return queryList; |
| | | } |
| | | |
| | | public void setQueryList(List<DaoQueryColumnData> queryList) { |
| | | this.queryList = queryList; |
| | | } |
| | | |
| | | public String getTable() { |
| | | return table; |
| | | } |
| | | |
| | | public void setTable(String table) { |
| | | this.table = table; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.service; |
| | | |
| | | import org.yeshi.utils.FreemarkerUtils; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.entity.BaseData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | import org.yeshi.utils.generater.util.EntityUtil; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class ServiceImplInfoVO extends BaseData { |
| | | private ClassInfo service; |
| | | private ClassInfo dao; |
| | | //方法列表 |
| | | private List<ServiceMetodInfoVO> metodInfoList; |
| | | private ClassInfo daoQuery; |
| | | private ClassInfo query; |
| | | |
| | | |
| | | public static class Builder { |
| | | private Class entity; |
| | | private String packageName; |
| | | private ClassInfo dao; |
| | | private ClassInfo service; |
| | | private ClassInfo query; |
| | | private ClassInfo daoQuery; |
| | | |
| | | public Builder setEntity(Class entity) { |
| | | this.entity = entity; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setPackageName(String packageName) { |
| | | this.packageName = packageName; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setDao(ClassInfo dao) { |
| | | this.dao = dao; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setService(ClassInfo service) { |
| | | this.service = service; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setQuery(ClassInfo query) { |
| | | this.query = query; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setDaoQuery(ClassInfo daoQuery) { |
| | | this.daoQuery = daoQuery; |
| | | return this; |
| | | } |
| | | |
| | | private void validParams() throws Exception { |
| | | if (entity == null) { |
| | | throw new Exception("entity不能为空"); |
| | | } |
| | | if (packageName == null) { |
| | | throw new Exception("packageName不能为空"); |
| | | } |
| | | if (dao == null) { |
| | | throw new Exception("dao不能为空"); |
| | | } |
| | | if (service == null) { |
| | | throw new Exception("service不能为空"); |
| | | } |
| | | if (query == null) { |
| | | throw new Exception("query不能为空"); |
| | | } |
| | | if (daoQuery == null) { |
| | | throw new Exception("daoQuery不能为空"); |
| | | } |
| | | } |
| | | |
| | | private String getMethodContentTemplatePath(String type) { |
| | | String basePath = "generater/service/method/impl/"; |
| | | if (dao.getName().endsWith("Mapper")) { |
| | | basePath += "mybatis/"; |
| | | } else { |
| | | basePath += "mongo/"; |
| | | } |
| | | |
| | | switch (type) { |
| | | case "list": |
| | | return basePath + "list.ftl"; |
| | | case "count": |
| | | return basePath + "count.ftl"; |
| | | case "add": |
| | | return basePath + "add.ftl"; |
| | | case "save": |
| | | return basePath + "save.ftl"; |
| | | case "get": |
| | | return basePath + "selectByPrimaryKey.ftl"; |
| | | case "update": |
| | | return basePath + "updateSlective.ftl"; |
| | | case "delete": |
| | | return basePath + "delete.ftl"; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public ServiceImplInfoVO build() throws Exception { |
| | | validParams(); |
| | | Field identifyId = EntityUtil.getIdentifyId(entity); |
| | | if (identifyId == null) { |
| | | throw new Exception("尚未找到主键属性"); |
| | | } |
| | | |
| | | ServiceImplInfoVO serviceData = new ServiceImplInfoVO(); |
| | | serviceData.setDao(dao); |
| | | serviceData.setService(service); |
| | | serviceData.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | serviceData.setPackageName(packageName); |
| | | serviceData.setDaoQuery(daoQuery); |
| | | serviceData.setQuery(query); |
| | | |
| | | //设置接口 |
| | | List<ServiceMetodInfoVO> metodInfoVOList = new ArrayList<>(); |
| | | /*******添加方法开始*******/ |
| | | List<String> params = null; |
| | | ServiceMetodInfoVO metodInfo = null; |
| | | //list方法 |
| | | params = new ArrayList<>(); |
| | | params.add(query.getName() + " " + StringUtil.firstCharToLower(query.getName())); |
| | | params.add(" int page"); |
| | | params.add(" int pageSize"); |
| | | metodInfo = new ServiceMetodInfoVO("public", String.format("List<%s>", serviceData.getEntity().getName()), "list", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("list")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | //count方法 |
| | | params = new ArrayList<>(); |
| | | params.add(query.getName() + " " + StringUtil.firstCharToLower(query.getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "long", "count", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("count")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | //get方法 |
| | | params = new ArrayList<>(); |
| | | params.add(identifyId.getType().getSimpleName() + " id"); |
| | | metodInfo = new ServiceMetodInfoVO("public", serviceData.getEntity().getName(), "get", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("get")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | //add方法 |
| | | params = new ArrayList<>(); |
| | | params.add(serviceData.getEntity().getName() + " " + StringUtil.firstCharToLower(serviceData.getEntity().getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "void", "add", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("add")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | //update方法 |
| | | params = new ArrayList<>(); |
| | | params.add(serviceData.getEntity().getName() + " " + StringUtil.firstCharToLower(serviceData.getEntity().getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "void", "update", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("update")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | //delete方法 |
| | | params = new ArrayList<>(); |
| | | params.add(String.format("List<%s> idList", identifyId.getType().getSimpleName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", String.format("void", serviceData.getEntity().getName()), "delete", StringUtil.concat(params, ",")); |
| | | metodInfo.setContent(FreemarkerUtils.generateInputStream(serviceData, getClass().getClassLoader().getResourceAsStream(getMethodContentTemplatePath("delete")))); |
| | | metodInfoVOList.add(metodInfo); |
| | | |
| | | /*******添加方法结束*******/ |
| | | serviceData.setMetodInfoList(metodInfoVOList); |
| | | return serviceData; |
| | | } |
| | | |
| | | } |
| | | |
| | | public ClassInfo getService() { |
| | | return service; |
| | | } |
| | | |
| | | public void setService(ClassInfo service) { |
| | | this.service = service; |
| | | } |
| | | |
| | | public ClassInfo getDao() { |
| | | return dao; |
| | | } |
| | | |
| | | public void setDao(ClassInfo dao) { |
| | | this.dao = dao; |
| | | } |
| | | |
| | | public List<ServiceMetodInfoVO> getMetodInfoList() { |
| | | return metodInfoList; |
| | | } |
| | | |
| | | public void setMetodInfoList(List<ServiceMetodInfoVO> metodInfoList) { |
| | | this.metodInfoList = metodInfoList; |
| | | } |
| | | |
| | | public ClassInfo getDaoQuery() { |
| | | return daoQuery; |
| | | } |
| | | |
| | | public void setDaoQuery(ClassInfo daoQuery) { |
| | | this.daoQuery = daoQuery; |
| | | } |
| | | |
| | | public ClassInfo getQuery() { |
| | | return query; |
| | | } |
| | | |
| | | public void setQuery(ClassInfo query) { |
| | | this.query = query; |
| | | } |
| | | } |
| | | |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/ServiceInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo; |
| | | package org.yeshi.utils.generater.vo.service; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.generater.entity.BaseData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | import org.yeshi.utils.generater.util.EntityUtil; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | private ClassInfo dao; |
| | | //方法列表 |
| | | private List<ServiceMetodInfoVO> metodInfoList; |
| | | private ClassInfo query; |
| | | |
| | | |
| | | public static class Builder { |
| | |
| | | } |
| | | |
| | | |
| | | private String getRemarksLine(String content) { |
| | | return "\t * " + content + "\n"; |
| | | } |
| | | |
| | | //获取方法的注释 |
| | | private String getMethodRemarks(String type) { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("/**\n"); |
| | | switch (type) { |
| | | case "list": |
| | | builder.append(getRemarksLine("获取列表")); |
| | | builder.append(getRemarksLine("@param " + StringUtil.firstCharToLower(query.getName()))); |
| | | builder.append(getRemarksLine("@param page")); |
| | | builder.append(getRemarksLine("@param pageSize")); |
| | | builder.append(getRemarksLine("@return")); |
| | | break; |
| | | default: |
| | | builder.append(getRemarksLine("")); |
| | | } |
| | | |
| | | builder.append("\t */"); |
| | | return builder.toString(); |
| | | } |
| | | |
| | | private void validParams() throws Exception { |
| | | if (entity == null) { |
| | | throw new Exception("entity不能为空"); |
| | | } |
| | | if (packageName == null) { |
| | | throw new Exception("packageName不能为空"); |
| | | } |
| | | if (dao == null) { |
| | | throw new Exception("dao不能为空"); |
| | | } |
| | | if (service == null) { |
| | | throw new Exception("service不能为空"); |
| | | } |
| | | if (query == null) { |
| | | throw new Exception("query不能为空"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public ServiceInfoVO build() throws Exception { |
| | | validParams(); |
| | | Field identifyId = EntityUtil.getIdentifyId(entity); |
| | | if (identifyId == null) { |
| | | throw new Exception("尚未找到主键属性"); |
| | | } |
| | | ServiceInfoVO serviceData = new ServiceInfoVO(); |
| | | serviceData.setDao(dao); |
| | | serviceData.setService(service); |
| | | serviceData.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | serviceData.setPackageName(packageName); |
| | | serviceData.setQuery(query); |
| | | //设置接口 |
| | | List<ServiceMetodInfoVO> metodInfoVOList = new ArrayList<>(); |
| | | /*******添加方法开始*******/ |
| | |
| | | params.add("int page"); |
| | | params.add("int pageSize"); |
| | | metodInfo = new ServiceMetodInfoVO("public", String.format("List<%s>", serviceData.getEntity().getName()), "list", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("list")); |
| | | |
| | | metodInfoVOList.add(metodInfo); |
| | | //count方法 |
| | | params = new ArrayList<>(); |
| | | params.add(query.getName() + " " + StringUtil.firstCharToLower(query.getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "long", "count", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("count")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //get方法 |
| | | params = new ArrayList<>(); |
| | | params.add("String id"); |
| | | params.add(identifyId.getType().getSimpleName() + " id"); |
| | | metodInfo = new ServiceMetodInfoVO("public", serviceData.getEntity().getName(), "get", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("get")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //add方法 |
| | | params = new ArrayList<>(); |
| | | params.add(serviceData.getEntity().getName() + " " + StringUtil.firstCharToLower(serviceData.getEntity().getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "void", "add", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("add")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //update方法 |
| | | params = new ArrayList<>(); |
| | | params.add(serviceData.getEntity().getName() + " " + StringUtil.firstCharToLower(serviceData.getEntity().getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "void", "update", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("update")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //delete方法 |
| | | params = new ArrayList<>(); |
| | | params.add("List<String> idList"); |
| | | params.add(String.format("List<%s> idList", identifyId.getType().getSimpleName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", String.format("void", serviceData.getEntity().getName()), "delete", StringUtil.concat(params, ",")); |
| | | metodInfo.setNote(getMethodRemarks("delete")); |
| | | metodInfoVOList.add(metodInfo); |
| | | |
| | | /*******添加方法结束*******/ |
| | | |
| | | serviceData.setMetodInfoList(metodInfoVOList); |
| | | |
| | | return serviceData; |
| | | } |
| | |
| | | this.metodInfoList = metodInfoList; |
| | | } |
| | | |
| | | public ClassInfo getQuery() { |
| | | return query; |
| | | } |
| | | |
| | | public void setQuery(ClassInfo query) { |
| | | this.query = query; |
| | | } |
| | | } |
File was renamed from src/main/java/org/yeshi/utils/generater/vo/ServiceMetodInfoVO.java |
| | |
| | | package org.yeshi.utils.generater.vo; |
| | | package org.yeshi.utils.generater.vo.service; |
| | | |
| | | /** |
| | | * @author Administrator |
| | |
| | | @RequestMapping("${mapping}") |
| | | public class AdminAppController { |
| | | |
| | | <#assign serviceObjName=${service.name?uncap_first}"> |
| | | <#assign serviceObjName="${service.name?uncap_first}"> |
| | | <#assign entityObjName="${entity.name?uncap_first}"> |
| | | @Resource |
| | | private ${service.name} ${serviceObjName}; |
| | | |
| | | |
| | | private String loadPrint(String callback, String root){ |
| | | <#if jsonp> |
| | | return JsonUtil.loadJSONP(callback,root); |
| | | <#else> |
| | | return root; |
| | | </#if> |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String list(${query.name} query, int page, int limit) { |
| | | List<${entityName}> list = ${serviceObjName}.list(query,page,limit); |
| | | public String list(${query.name} query, int page, int limit, String callback) { |
| | | List<${entity.name}> list = ${serviceObjName}.list(query,page,limit); |
| | | long count = ${serviceObjName}.count(query); |
| | | JSONObject data = new JSONObject(); |
| | | Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | |
| | | |
| | | data.put("list", gson.toJson(list)); |
| | | data.put("count", count); |
| | | return JsonUtil.loadTrueResult(data); |
| | | return loadPrint(callback,JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("delete") |
| | | public String delete(String ids) { |
| | | JSONArray array = JSONArray.fromObject(ids); |
| | | List<String> idList=new ArrayList<>(); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | idList.add(array.optString(i)); |
| | | } |
| | | public String delete(String ids, String callback) { |
| | | Type type = new TypeToken<List<${identifyIdType}>>(){}.get(); |
| | | List<${identifyIdType}> idList=new Gson().from(ids,type); |
| | | ${serviceObjName}.delete(idList); |
| | | return JsonUtil.loadTrueResult(""); |
| | | return loadPrint(callback, JsonUtil.loadTrueResult("")); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("add") |
| | | public String add(${entity.name} bean, HttpSession session) { |
| | | public String add(${entity.name} bean, HttpSession session, String callback) { |
| | | try{ |
| | | ${serviceObjName}.add(bean); |
| | | return JsonUtil.loadTrueResult(""); |
| | | return loadPrint(callback, JsonUtil.loadTrueResult("")); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage); |
| | | return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage)); |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("get") |
| | | public String add(String id, HttpSession session) { |
| | | try{ |
| | | ${serviceObjName}.get(id); |
| | | return JsonUtil.loadTrueResult(""); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage); |
| | | public String get(${identifyIdType} id, HttpSession session, String callback) { |
| | | ${entity.name} entity = ${serviceObjName}.get(id); |
| | | if (entity !=null){ |
| | | return loadPrint(callback,JsonUtil.loadTrueResult(entity)); |
| | | } else { |
| | | return loadPrint(callback,JsonUtil.loadFalseResult("ID不存在")); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("update") |
| | | public String update(${entity.name} bean, HttpSession session) { |
| | | if (app.getId() == null) { |
| | | return JsonUtil.loadFalseResult("ID不能为空"); |
| | | public String update(${entity.name} bean, HttpSession session,String callback) { |
| | | if (bean.getId() == null) { |
| | | return loadPrint(callback, JsonUtil.loadFalseResult("ID不能为空")); |
| | | } |
| | | try{ |
| | | ${serviceObjName}.updateSelective(bean); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage); |
| | | return loadPrint(callback,JsonUtil.loadFalseResult(e.getMessage)); |
| | | } |
| | | return JsonUtil.loadTrueResult(""); |
| | | return loadPrint(callback,JsonUtil.loadTrueResult("")); |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | <#list importClasses as value> |
| | | import ${value}; |
| | | </#list> |
| | | |
| | | |
| | | @Repository |
| | | public class ${daoName} extends ${baseDao.name}<${entity.name}>{ |
| | | |
| | | public void updateSelective(${entity.name} bean) { |
| | | Query query = new Query(); |
| | | Update update=new Update(); |
| | | query.addCriteria(Criteria.where("${identityColumn.columnName}").is(bean.${identityColumn.columnMehtod})); |
| | | <#if columnDataList??> |
| | | <#list columnDataList as value> |
| | | if(bean.${value.columnMehtod} != null) { |
| | | update.set("${value.columnName}", bean.${value.columnMehtod}); |
| | | } |
| | | </#list> |
| | | </#if> |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | } |
| | | |
| | | |
| | | public List<${entity.name}> list(DaoQuery daoQuery){ |
| | | Query query = getQuery(daoQuery); |
| | | if (daoQuery.sortList!=null && daoQuery.sortList.size()>0){ |
| | | query.with(new Sort(daoQuery.sortList)); |
| | | } |
| | | query.skip(daoQuery.start); |
| | | query.limit(daoQuery.count); |
| | | return findList(query); |
| | | } |
| | | |
| | | public long count(DaoQuery daoQuery){ |
| | | Query query=getQuery(daoQuery); |
| | | return count(query); |
| | | } |
| | | |
| | | private Query getQuery(DaoQuery daoQuery){ |
| | | List<Criteria> andList=new ArrayList<>(); |
| | | <#list daoQueryColumnDataList as value> |
| | | <#if (value.type!"") == "Date"> |
| | | if(daoQuery.min${value.columnName?cap_first}!=null){ |
| | | andList.add(Criteria.where("${value.columnName}").gte(daoQuery.min${value.columnName?cap_first})); |
| | | } |
| | | if(daoQuery.max${value.columnName?cap_first}!=null){ |
| | | andList.add(Criteria.where("${value.columnName}").lt(daoQuery.max${value.columnName?cap_first})); |
| | | } |
| | | <#else> |
| | | if(daoQuery.${value.columnName}!=null){ |
| | | <#if (value.queryType!"") == "equal"> |
| | | andList.add(Criteria.where("${value.columnName}").is(daoQuery.${value.columnName})); |
| | | <#else> |
| | | andList.add(Criteria.where("${value.columnName}").regex(daoQuery.${value.columnName})); |
| | | </#if> |
| | | } |
| | | </#if> |
| | | </#list> |
| | | Query query=new Query(); |
| | | Criteria[] ands=new Criteria[andList.size()]; |
| | | andList.toArray(ands); |
| | | if(ands.length>0){ |
| | | query.addCriteria(new Criteria().andOperator(ands)); |
| | | } |
| | | return query; |
| | | } |
| | | |
| | | public static class DaoQuery{ |
| | | <#if daoQueryColumnDataList??> |
| | | <#list daoQueryColumnDataList as value> |
| | | <#if (value.type!"") == "Date"> |
| | | public ${value.type} min${value.columnName?cap_first}; |
| | | public ${value.type} max${value.columnName?cap_first}; |
| | | <#else> |
| | | public ${value.type} ${value.columnName}; |
| | | </#if> |
| | | </#list> |
| | | </#if> |
| | | public int start; |
| | | public int count; |
| | | public List<Sort.Order> sortList; |
| | | } |
| | | } |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import ${baseMapper.clazz}; |
| | | import ${entity.clazz}; |
| | | |
| | | public interface ${mapper.name} extends ${baseMapper.name}<${entity.name}> { |
| | | |
| | | ${entity.name} selectByPrimaryKeyForUpdate(@Param("id") ${identify.type} id); |
| | | |
| | | List<${entity.name}> list(@Param("query") DaoQuery query); |
| | | |
| | | long count(@Param("query") DaoQuery query); |
| | | |
| | | public static class DaoQuery{ |
| | | <#if queryList??> |
| | | <#list queryList as value> |
| | | <#if (value.type!"") == "Date"> |
| | | public ${value.type} min${value.columnName?cap_first}; |
| | | public ${value.type} max${value.columnName?cap_first}; |
| | | <#else> |
| | | public ${value.type} ${value.columnName}; |
| | | </#if> |
| | | </#list> |
| | | </#if> |
| | | public long start; |
| | | public int count; |
| | | public List<String> sortList; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | |
| | | <mapper namespace="${mapper.clazz}"> |
| | | <resultMap id="BaseResultMap" |
| | | type="${entity.clazz}"> |
| | | <id column="${identify.column}" property="${identify.property}" jdbcType="${identify.jdbcType}"/> |
| | | <#list columnList as column> |
| | | <result column="${column.column}" property="${column.property}" jdbcType="${column.jdbcType}"/> |
| | | </#list> |
| | | </resultMap> |
| | | |
| | | <sql id="Base_Column_List"> |
| | | <trim suffixOverrides=","> |
| | | <#list columnList as column>${column.column},</#list> |
| | | </trim> |
| | | </sql> |
| | | |
| | | <select id="selectByPrimaryKey" resultMap="BaseResultMap" |
| | | parameterType="java.lang.Long"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from ${table} where ${identify.column} = <#noparse>#{</#noparse>id, jdbcType=${identify.jdbcType}} |
| | | </select> |
| | | |
| | | <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap" |
| | | parameterType="java.lang.Long"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | from ${table} where ${identify.column} = <#noparse>#{</#noparse>id,jdbcType=${identify.jdbcType}} for update |
| | | </select> |
| | | |
| | | |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
| | | delete from |
| | | ${table} where ${identify.column} = <#noparse>#{</#noparse>id,jdbcType=${identify.jdbcType}} |
| | | </delete> |
| | | <insert id="insert" |
| | | parameterType="${entity.class}" |
| | | useGeneratedKeys="true" keyProperty="${identify.property}"> |
| | | insert into |
| | | ${table} |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <#list columnList as column> |
| | | ${column.column}}, |
| | | </#list> |
| | | |
| | | </trim> |
| | | values |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <#list columnList as column> |
| | | <#noparse>#{</#noparse>${column.property}},jdbcType=${column.jdbcType}}, |
| | | </#list> |
| | | |
| | | </trim> |
| | | |
| | | </insert> |
| | | <insert id="insertSelective" |
| | | parameterType="${entity.class}" |
| | | useGeneratedKeys="true" keyProperty="${identify.property}"> |
| | | insert into ${table} |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="${identify.property} != null">${identify.column},</if> |
| | | <#list columnList as column> |
| | | <if test="${column.property} != null">${column.column},</if> |
| | | </#list> |
| | | </trim> |
| | | values |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="${identify.property} != null"><#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}},</if> |
| | | <#list columnList as column> |
| | | <if test="${column.property} != null"><#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if> |
| | | </#list> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKey" |
| | | parameterType="${entity.class}"> |
| | | update ${table} |
| | | <set> |
| | | <if test="${identify.property} != null">${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}},</if> |
| | | <#list columnList as column> |
| | | <if test="${column.property} != null">${column.column} = <#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if> |
| | | </#list> |
| | | </set> |
| | | where ${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}} |
| | | </update> |
| | | <update id="updateByPrimaryKeySelective" |
| | | parameterType="${entity.class}"> |
| | | update ${table} |
| | | <set> |
| | | <#list columnList as column> |
| | | <if test="${column.property} != null">${column.column} = <#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if> |
| | | </#list> |
| | | </set> |
| | | where ${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}} |
| | | </update> |
| | | |
| | | <sql id="listWhere"> |
| | | <#list queryList as query> |
| | | <if test="query.${query.columnName}!=null"> |
| | | <#if query.queryType=="equal"> |
| | | and ${query.columnData.column} = <#noparse>#{</#noparse>query.${query.columnName}} |
| | | </#if> |
| | | <#if query.queryType=="start"> |
| | | and ${query.columnData.column} like '<#noparse>#{</#noparse>query.${query.columnName}}%' |
| | | </#if> |
| | | <#if query.queryType=="end"> |
| | | and ${query.columnData.column} like '%<#noparse>#{</#noparse>query.${query.columnName}}' |
| | | </#if> |
| | | <#if query.queryType=="contains"> |
| | | and ${query.columnData.column} = '%<#noparse>#{</#noparse>query.${query.columnName}}%' |
| | | </#if> |
| | | </if> |
| | | </#list> |
| | | </sql> |
| | | |
| | | <select id="list" |
| | | resultMap="BaseResultMap"> |
| | | SELECT * FROM ${table} |
| | | <where> |
| | | <include refid="listWhere"> |
| | | </include> |
| | | </where> |
| | | <if test="query.sortList!=null"> |
| | | <foreach collection="query.sortList" open=" order by " separator="," item="item"> |
| | | <#noparse>#{</#noparse>item} |
| | | </foreach> |
| | | </if> |
| | | limit <#noparse>#{</#noparse>query.start},<#noparse>#{</#noparse>query.count} |
| | | </select> |
| | | |
| | | |
| | | <select id="count" |
| | | resultType="java.lang.Long"> |
| | | SELECT count(*) FROM ${table} |
| | | <where> |
| | | <include refid="listWhere"> |
| | | </include> |
| | | </where> |
| | | </select> |
| | | |
| | | |
| | | </mapper> |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${base.clazz}; |
| | | |
| | | public class ${entity.name}Exception extends ${base.name}{ |
| | | |
| | | public ${entity.name}Exception(int code, String msg) { |
| | | super(code, msg); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | //查询主键ID是否存在 |
| | | if(${daoObjName}.get(${entityObjName}.getId())!=null){ |
| | | throw Exception("已存在"); |
| | | } |
| | | |
| | | if(${entityObjName}.getCreateTime()==null){ |
| | | ${entityObjName}.setCreateTime(new Date()); |
| | | } |
| | | //保存 |
| | | ${daoObjName}.save(bean); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign queryObjName="${query.name?uncap_first}" > |
| | | ${daoQuery.name} daoQuery = new ${daoQuery.name}(); |
| | | BeanUtil.copyProperties(${queryObjName}, daoQuery); |
| | | ${daoObjName}.count(daoQuery); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | for (String id : idList){ |
| | | ${daoObjName}.delete(id); |
| | | } |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign queryObjName="${query.name?uncap_first}" > |
| | | ${daoQuery.name} daoQuery = new ${daoQuery.name}(); |
| | | BeanUtil.copyProperties(${queryObjName}, daoQuery); |
| | | daoQuery.start=(page-1)*pageSize; |
| | | daoQuery.count=pageSize; |
| | | ${daoObjName}.list(daoQuery); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | if(${entityObjName}.getCreateTime()==null){ |
| | | ${entityObjName}.setCreateTime(new Date()); |
| | | } |
| | | ${daoObjName}.save(${entityObjName}); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | Query query=new Query(); |
| | | query.addCriteria(Criteria.where("_id").is(id)); |
| | | return ${daoObjName}.findOne(query); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | if(${entityObjName}.getUpdateTime()==null){ |
| | | ${entityObjName}.setUpdateTime(new Date()); |
| | | } |
| | | //更新 |
| | | ${daoObjName}.updateSelective(${entityObjName}); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | if(bean.getCreateTime()==null){ |
| | | bean.setCreateTime(new Date()); |
| | | } |
| | | //保存 |
| | | ${daoObjName}.insertSelective(bean); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign queryObjName="${query.name?uncap_first}" > |
| | | ${daoQuery.name} daoQuery = new ${daoQuery.name}(); |
| | | BeanUtil.copyProperties(${queryObjName}, daoQuery); |
| | | ${daoObjName}.count(daoQuery); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | for (String id : idList){ |
| | | ${daoObjName}.deleteByPrimaryKey(id); |
| | | } |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign queryObjName="${query.name?uncap_first}" > |
| | | ${daoQuery.name} daoQuery = new ${daoQuery.name}(); |
| | | BeanUtil.copyProperties(${queryObjName}, daoQuery); |
| | | daoQuery.start=(page-1)*pageSize; |
| | | daoQuery.count=pageSize; |
| | | ${daoObjName}.list(daoQuery); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | if(${entityObjName}.getId()!=null){ |
| | | //更新 |
| | | if(${entityObjName}.getUpdateTime()==null){ |
| | | ${entityObjName}.setUpdateTime(new Date()); |
| | | } |
| | | ${daoObjName}.updateByPrimaryKey( ${entityObjName}); |
| | | }else{ |
| | | //保存 |
| | | add(${entityObjName}); |
| | | } |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | return ${daoObjName}.selectByPrimaryKey(id); |
New file |
| | |
| | | <#assign daoObjName="${dao.name?uncap_first}" > |
| | | <#assign entityObjName="${entity.name?uncap_first}" > |
| | | if(${entityObjName}.getUpdateTime()==null){ |
| | | ${entityObjName}.setUpdateTime(new Date()); |
| | | } |
| | | //保存 |
| | | ${daoObjName}.updateByPrimaryKey(${entityObjName}); |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${service.clazz}; |
| | | import ${query.clazz}; |
| | | import ${entity.clazz}; |
| | | |
| | | |
| | | public interface ${service.name} { |
| | |
| | | import ${entity.clazz}; |
| | | import ${dao.clazz}; |
| | | import ${service.clazz}; |
| | | import ${query.clazz}; |
| | | import ${daoQuery.clazz}; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import java.util.Date; |
| | | import org.yeshi.utils.bean.BeanUtil; |
| | | |
| | | @Service |
| | | public class ${service.name}Impl implements ${service.name}{ |
| | |
| | | private ${dao.name} ${dao.name?uncap_first}; |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}){ |
| | | ${method.content} |
| | | } |
| | | |
| | | </#list> |
| | | |
| | | } |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | * @description: 测试entity |
| | | * @date 2021/9/23 14:22 |
| | | */ |
| | | @AdminController(mapping = "admin/api/test", title = "测试", searchForm = TestEntity.SearchForm.class) |
| | | @AdminController(mapping = "admin/api/test", title = "测试", searchForm = TestEntity.SearchForm.class,jsonp = true) |
| | | public class TestEntity { |
| | | @Id |
| | | private String id; |
New file |
| | |
| | | package com.generater; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.yeshi.utils.generater.annotation.admin.AdminController; |
| | | import org.yeshi.utils.generater.annotation.admin.DaoQueryCondition; |
| | | import org.yeshi.utils.generater.annotation.admin.Show; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Img; |
| | | import org.yeshi.utils.generater.annotation.admin.form.RadioGroup; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Select; |
| | | import org.yeshi.utils.generater.annotation.admin.form.Text; |
| | | import org.yeshi.utils.generater.entity.admin.FormVerifyType; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: TestEntity |
| | | * @description: 测试entity |
| | | * @date 2021/9/23 14:22 |
| | | */ |
| | | @AdminController(mapping = "admin/api/test", title = "测试", searchForm = TestEntity2.SearchForm.class,jsonp = true) |
| | | @Table("table_test") |
| | | public class TestEntity2 { |
| | | @Id |
| | | private String id; |
| | | |
| | | @Column(name="nick_name") |
| | | @DaoQueryCondition(queryType = DaoQueryCondition.QueryType.contains) |
| | | @Show(order = 0, title = "昵称") |
| | | @Text(title = "昵称", maxLength = 50, require = true, placeHolder = "请输入昵称", desc = "昵称不能包含特殊字符", verifyType = FormVerifyType.none, verifyValue = "^.{0-100}$", verifyNotifyMsg = "请输入正确的昵称") |
| | | private String nickName; |
| | | |
| | | @DaoQueryCondition |
| | | @Show(order = 1, title = "类型") |
| | | @Select(values = {"1:男", "2:女"}, title = "类型") |
| | | private Integer type; |
| | | |
| | | @DaoQueryCondition |
| | | @Show(order = 2, title = "性别") |
| | | @RadioGroup(values = {"1:男", "2:女"}, title = "性别") |
| | | private Integer sex; |
| | | |
| | | @Show(order = 3, title = "头像", showType = Show.ShowType.IMG, imgWidth = 50, imgHeight = 50) |
| | | @Img(height = 50, title = "头像", uploadApi = "/admin/uploadimg", uploadApiParams = {"id:123123","type:2"}) |
| | | private String portrait; |
| | | |
| | | @Transient |
| | | @DaoQueryCondition |
| | | @Show(order = 4, title = "省") |
| | | @Select(values = {"cq:重庆","js:江苏"}, title = "省", apiParams = {"page:1", "pageSize:10", "id:\"test\""}) |
| | | private String province; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getNickName() { |
| | | return nickName; |
| | | } |
| | | |
| | | public void setNickName(String nickName) { |
| | | this.nickName = nickName; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public Integer getSex() { |
| | | return sex; |
| | | } |
| | | |
| | | public void setSex(Integer sex) { |
| | | this.sex = sex; |
| | | } |
| | | |
| | | public String getPortrait() { |
| | | return portrait; |
| | | } |
| | | |
| | | public void setPortrait(String portrait) { |
| | | this.portrait = portrait; |
| | | } |
| | | |
| | | public String getProvince() { |
| | | return province; |
| | | } |
| | | |
| | | public void setProvince(String province) { |
| | | this.province = province; |
| | | } |
| | | |
| | | public class SearchForm { |
| | | |
| | | @Text(title = "开始日期", inputType = Text.Type.DATE) |
| | | private String startDate; |
| | | @Text(title = "结束日期", inputType = Text.Type.DATE) |
| | | private String endDate; |
| | | @Text(title = "请输入关键词", inputType = Text.Type.TEXT) |
| | | private String key; |
| | | |
| | | |
| | | public String getStartDate() { |
| | | return startDate; |
| | | } |
| | | |
| | | public void setStartDate(String startDate) { |
| | | this.startDate = startDate; |
| | | } |
| | | |
| | | public String getEndDate() { |
| | | return endDate; |
| | | } |
| | | |
| | | public void setEndDate(String endDate) { |
| | | this.endDate = endDate; |
| | | } |
| | | |
| | | public String getKey() { |
| | | return key; |
| | | } |
| | | |
| | | public void setKey(String key) { |
| | | this.key = key; |
| | | } |
| | | } |
| | | } |