4个文件已删除
21个文件已修改
21个文件已添加
| | |
| | | str = str.substring(0, str.length() - sperator.length()); |
| | | return str; |
| | | } |
| | | |
| | | //首字母小写 |
| | | public static String firstCharToLower(String st) { |
| | | if (st == null || st.length() < 2) |
| | | return st; |
| | | return st.substring(0, 1).toLowerCase() + st.substring(1); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.yeshi.utils.FreemarkerUtils; |
| | | import org.yeshi.utils.generater.entity.ExceptionData; |
| | | import org.yeshi.utils.generater.entity.MongoDBDaoData; |
| | | import org.yeshi.utils.generater.entity.ServiceData; |
| | | import org.yeshi.utils.generater.vo.ServiceInfoVO; |
| | | |
| | | import java.io.File; |
| | | |
| | |
| | | * @param targetDir |
| | | * @throws Exception |
| | | */ |
| | | public static void createService(ServiceData data, String targetDir) throws Exception { |
| | | public static void createService(ServiceInfoVO data, String targetDir) throws Exception { |
| | | |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/service.template"), new File(targetDir, data.getServiceClassName() + ".java").getAbsolutePath(), data); |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/service/service.template"), new File(targetDir, data.getServiceClassName() + ".java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param targetDir |
| | | * @throws Exception |
| | | */ |
| | | public static void createServiceImpl(ServiceData data, String targetDir) throws Exception { |
| | | public static void createServiceImpl(ServiceInfoVO data, String targetDir) throws Exception { |
| | | |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/serviceImpl.template"), new File(targetDir, data.getServiceClassName() + "Impl.java").getAbsolutePath(), data); |
| | | FreemarkerUtils.renderingTemplateAndGenerateFile(SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/service/serviceImpl.template"), new File(targetDir, data.getServiceClassName() + "Impl.java").getAbsolutePath(), data); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | //图片高度px,默认不设置 |
| | | int height() default -1; |
| | | |
| | | //图片上传的API |
| | | String uploadApi() default ""; |
| | | |
| | | //图片上传API的参数 |
| | | String[] uploadApiParams() default ""; |
| | | |
| | | } |
| | |
| | | String apiPath() default ""; |
| | | |
| | | |
| | | //api的请求参数 |
| | | String[] apiParams() default ""; |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | public class BaseData { |
| | | private String packageName; |
| | | private String entityClass; |
| | | private ClassInfo entity; |
| | | |
| | | public String getPackageName() { |
| | | return packageName; |
| | |
| | | this.packageName = packageName; |
| | | } |
| | | |
| | | public String getEntityClass() { |
| | | return entityClass; |
| | | public ClassInfo getEntity() { |
| | | return entity; |
| | | } |
| | | |
| | | public void setEntityClass(String entityClass) { |
| | | this.entityClass = entityClass; |
| | | public void setEntity(ClassInfo entity) { |
| | | this.entity = entity; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.entity; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: ClassInfo |
| | | * @description: 类信息 |
| | | * @date 2021/9/30 15:53 |
| | | */ |
| | | public class ClassInfo { |
| | | |
| | | private String name; |
| | | private String clazz; |
| | | |
| | | public ClassInfo(String name, String clazz) { |
| | | this.name = name; |
| | | this.clazz = clazz; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getClazz() { |
| | | return clazz; |
| | | } |
| | | |
| | | public void setClazz(String clazz) { |
| | | this.clazz = clazz; |
| | | } |
| | | } |
| | |
| | | //entity类 |
| | | private Class entity; |
| | | //controller注解对象 |
| | | private Map<String, Object> controllerData; |
| | | private AdminController controllerData; |
| | | //修改的表单行数据 |
| | | private List<FormRowData> updateFormRows; |
| | | //添加的表单行数据 |
| | |
| | | this.entity = entity; |
| | | } |
| | | |
| | | public Map<String, Object> getControllerData() { |
| | | public AdminController getControllerData() { |
| | | return controllerData; |
| | | } |
| | | |
| | | public void setControllerData(Map<String, Object> controllerData) { |
| | | public void setControllerData(AdminController controllerData) { |
| | | this.controllerData = controllerData; |
| | | } |
| | | |
| | | |
| | | public List<FormRowData> getUpdateFormRows() { |
| | | return updateFormRows; |
| | |
| | | if (an instanceof AdminController) { |
| | | Class searchFormClass = ((AdminController) an).searchForm(); |
| | | AdminGeneraterInfo info = new AdminGeneraterInfo(); |
| | | info.setControllerData(AnotationUtil.getParamsMap(an)); |
| | | info.setControllerData((AdminController) an); |
| | | info.setSearchFormRows(AnotationUtil.getFormRowData(searchFormClass)); |
| | | info.setAddFormRows(AnotationUtil.getFormRowData(entity)); |
| | | info.setUpdateFormRows(AnotationUtil.getUpdateFormRowData(entity)); |
| | |
| | | if (arrays.length == 1 && StringUtil.isNullOrEmpty(arrays[0])) { |
| | | } else { |
| | | for (String st : (String[]) value) { |
| | | values.add(new KeyValue(st.substring(0, st.indexOf(",")), st.substring(st.indexOf(",") + 1))); |
| | | values.add(new KeyValue(st.substring(0, st.indexOf(":")), st.substring(st.indexOf(":") + 1))); |
| | | } |
| | | } |
| | | params.put(md.getName(), values); |
| | |
| | | } |
| | | |
| | | for (String st : checkBox.values()) { |
| | | if (!st.contains(",")) { |
| | | throw new AnotationException("复选框的内容格式错误,键值对要用逗号分隔"); |
| | | if (!st.contains(":")) { |
| | | throw new AnotationException("复选框的内容格式错误,键值对要用:分隔"); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | for (String st : radioGroup.values()) { |
| | | if (!st.contains(",")) { |
| | | throw new AnotationException("单选框的内容格式错误,键值对要用逗号分隔"); |
| | | if (!st.contains(":")) { |
| | | throw new AnotationException("单选框的内容格式错误,键值对要用:分隔"); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } else { |
| | | for (String st : select.values()) { |
| | | if (!st.contains(",")) { |
| | | throw new AnotationException("下拉框的内容格式错误,键值对要用逗号分隔"); |
| | | if (!st.contains(":")) { |
| | | throw new AnotationException("下拉框的内容格式错误,键值对要用:分隔"); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo; |
| | | |
| | | import org.yeshi.utils.generater.entity.BaseData; |
| | | import org.yeshi.utils.generater.entity.ClassInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | public class ServiceImplInfoVO extends BaseData { |
| | | private ClassInfo service; |
| | | private ClassInfo dao; |
| | | |
| | | //方法列表 |
| | | private List<ServiceMetodInfoVO> metodInfoList; |
| | | |
| | | |
| | | public static class Builder { |
| | | private Class entityClass; |
| | | private String packageName; |
| | | private Class daoClass; |
| | | private Class serviceClass; |
| | | |
| | | public Builder setServiceClass(Class serviceClass) { |
| | | this.serviceClass = serviceClass; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setEntityClass(Class entityClass) { |
| | | this.entityClass = entityClass; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setPackageName(String packageName) { |
| | | this.packageName = packageName; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setDaoClass(Class daoClass) { |
| | | this.daoClass = daoClass; |
| | | return this; |
| | | } |
| | | |
| | | public ServiceImplInfoVO build() { |
| | | ServiceImplInfoVO serviceData = new ServiceImplInfoVO(); |
| | | serviceData.setEntity(entityClass); |
| | | serviceData.setEntity(new ClassInfo(entityClass.getSimpleName(), entityClass.getName())); |
| | | serviceData.setPackageName(packageName); |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public ClassInfo getEntity() { |
| | | return entity; |
| | | } |
| | | |
| | | @Override |
| | | public void setEntity(ClassInfo entity) { |
| | | this.entity = entity; |
| | | } |
| | | |
| | | public List<ServiceMetodInfoVO> getMetodInfoList() { |
| | | return metodInfoList; |
| | | } |
| | | |
| | | public void setMetodInfoList(List<ServiceMetodInfoVO> metodInfoList) { |
| | | this.metodInfoList = metodInfoList; |
| | | } |
| | | } |
| | | |
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 java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class ServiceInfoVO extends BaseData { |
| | | private ClassInfo service; |
| | | private ClassInfo dao; |
| | | //方法列表 |
| | | private List<ServiceMetodInfoVO> metodInfoList; |
| | | |
| | | |
| | | public static class Builder { |
| | | private Class entity; |
| | | private String packageName; |
| | | private ClassInfo dao; |
| | | private ClassInfo service; |
| | | private ClassInfo query; |
| | | |
| | | |
| | | 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 ServiceInfoVO build() throws Exception { |
| | | ServiceInfoVO serviceData = new ServiceInfoVO(); |
| | | serviceData.setDao(dao); |
| | | serviceData.setService(service); |
| | | serviceData.setEntity(new ClassInfo(entity.getSimpleName(), entity.getName())); |
| | | serviceData.setPackageName(packageName); |
| | | //设置接口 |
| | | 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, ",")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //count方法 |
| | | params = new ArrayList<>(); |
| | | params.add(query.getName() + " " + StringUtil.firstCharToLower(query.getName())); |
| | | metodInfo = new ServiceMetodInfoVO("public", "long", "count", StringUtil.concat(params, ",")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //get方法 |
| | | params = new ArrayList<>(); |
| | | params.add("String id"); |
| | | metodInfo = new ServiceMetodInfoVO("public", serviceData.getEntity().getName(), "get", StringUtil.concat(params, ",")); |
| | | 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, ",")); |
| | | 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, ",")); |
| | | metodInfoVOList.add(metodInfo); |
| | | //delete方法 |
| | | params = new ArrayList<>(); |
| | | params.add("List<String> idList"); |
| | | metodInfo = new ServiceMetodInfoVO("public", String.format("void", serviceData.getEntity().getName()), "delete", StringUtil.concat(params, ",")); |
| | | metodInfoVOList.add(metodInfo); |
| | | |
| | | /*******添加方法结束*******/ |
| | | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: ServiceMetodInfo |
| | | * @description: 服务函数的输出信息 |
| | | * @date 2021/9/27 17:12 |
| | | */ |
| | | public class ServiceMetodInfoVO { |
| | | //注释 |
| | | private String note; |
| | | //访问控制 |
| | | private String visiteAccess; |
| | | //返回类型 |
| | | private String returnType; |
| | | //函数名称 |
| | | private String name; |
| | | //参数 |
| | | private String params; |
| | | //方法内容 |
| | | private String content; |
| | | |
| | | public ServiceMetodInfoVO(String visiteAccess, String returnType, String name, String params) { |
| | | this.visiteAccess = visiteAccess; |
| | | this.returnType = returnType; |
| | | this.name = name; |
| | | this.params = params; |
| | | } |
| | | |
| | | public String getVisiteAccess() { |
| | | return visiteAccess; |
| | | } |
| | | |
| | | public void setVisiteAccess(String visiteAccess) { |
| | | this.visiteAccess = visiteAccess; |
| | | } |
| | | |
| | | public String getReturnType() { |
| | | return returnType; |
| | | } |
| | | |
| | | public void setReturnType(String returnType) { |
| | | this.returnType = returnType; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getParams() { |
| | | return params; |
| | | } |
| | | |
| | | public void setParams(String params) { |
| | | this.params = params; |
| | | } |
| | | |
| | | public String getNote() { |
| | | return note; |
| | | } |
| | | |
| | | public void setNote(String note) { |
| | | this.note = note; |
| | | } |
| | | |
| | | public String getContent() { |
| | | return content; |
| | | } |
| | | |
| | | public void setContent(String content) { |
| | | this.content = content; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormAddInfo |
| | | * @description: 构建新增的实体类 |
| | | * @date 2021/9/26 10:07 |
| | | */ |
| | | public class AdminControllerInfoVO { |
| | | |
| | | private String packageName; |
| | | private String mapping; |
| | | private ClassInfo entity; |
| | | private ClassInfo service; |
| | | private ClassInfo query; |
| | | |
| | | |
| | | public static class Builder { |
| | | private AdminGeneraterInfo generaterInfo; |
| | | //包名 |
| | | private String packageName; |
| | | //后台查询DTO |
| | | private ClassInfo query; |
| | | // |
| | | private ClassInfo service; |
| | | |
| | | |
| | | public Builder setAdminInfo(AdminGeneraterInfo generaterInfo) { |
| | | this.generaterInfo = generaterInfo; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setPackageName(String packageName) { |
| | | this.packageName = packageName; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setQueryVO(ClassInfo query) { |
| | | this.query = query; |
| | | return this; |
| | | } |
| | | |
| | | public Builder setService(ClassInfo service) { |
| | | this.service = service; |
| | | return this; |
| | | } |
| | | |
| | | public AdminControllerInfoVO build() throws Exception { |
| | | if (generaterInfo == null) { |
| | | throw new Exception("generaterInfo不能为空"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(packageName)) { |
| | | throw new Exception("包名不能为空"); |
| | | } |
| | | if (query == null) { |
| | | throw new Exception("查询条件不能为空"); |
| | | } |
| | | if (service == null) { |
| | | throw new Exception("服务不能为空"); |
| | | } |
| | | |
| | | AdminControllerInfoVO vo = new AdminControllerInfoVO(); |
| | | vo.setMapping(generaterInfo.getControllerData().mapping()); |
| | | vo.setEntity(new ClassInfo(generaterInfo.getEntity().getSimpleName(), generaterInfo.getEntity().getName())); |
| | | vo.setPackageName(packageName); |
| | | vo.setQueryVO(query); |
| | | vo.setService(service); |
| | | return vo; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public String getPackageName() { |
| | | return packageName; |
| | | } |
| | | |
| | | public void setPackageName(String packageName) { |
| | | this.packageName = packageName; |
| | | } |
| | | |
| | | public String getMapping() { |
| | | return mapping; |
| | | } |
| | | |
| | | public void setMapping(String mapping) { |
| | | this.mapping = mapping; |
| | | } |
| | | |
| | | public ClassInfo getEntity() { |
| | | return entity; |
| | | } |
| | | |
| | | public void setEntity(ClassInfo entity) { |
| | | this.entity = entity; |
| | | } |
| | | |
| | | public ClassInfo getService() { |
| | | return service; |
| | | } |
| | | |
| | | public void setService(ClassInfo service) { |
| | | this.service = service; |
| | | } |
| | | |
| | | public ClassInfo getQuery() { |
| | | return query; |
| | | } |
| | | |
| | | public void setQueryVO(ClassInfo query) { |
| | | this.query = query; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | 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.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; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormAddInfo |
| | | * @description: 构建新增的实体类 |
| | | * @date 2021/9/26 10:07 |
| | | */ |
| | | public class FormAddInfoVO { |
| | | private String title; |
| | | private List<FormRowData> rowsList; |
| | | private List<FormInputRegexVerifyVO> regexVerifyList; |
| | | private String addApi; |
| | | |
| | | //进入页面就需要请求的数据 |
| | | private List<FormHttpRequestInfoVO> preRequestList; |
| | | |
| | | public static class Builder { |
| | | |
| | | private AdminGeneraterInfo generaterInfo; |
| | | |
| | | public Builder setAdminInfo(AdminGeneraterInfo generaterInfo) { |
| | | this.generaterInfo = generaterInfo; |
| | | return this; |
| | | } |
| | | |
| | | public FormAddInfoVO build() { |
| | | FormAddInfoVO vo = new FormAddInfoVO(); |
| | | vo.setAddApi(generaterInfo.getControllerData().mapping() + "/add"); |
| | | vo.setRowsList(generaterInfo.getAddFormRows()); |
| | | vo.setTitle("新增" + generaterInfo.getControllerData().title()); |
| | | //遍历需要正则表达式的Text或者TextArea |
| | | List<FormInputRegexVerifyVO> verifyVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | if (!row.getType().equalsIgnoreCase(Text.class.getSimpleName()) && !row.getType().equalsIgnoreCase(TextArea.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | if ((row.getParams().get("verifyType")) != FormVerifyType.regex) |
| | | continue; |
| | | FormInputRegexVerifyVO verifyVO = new FormInputRegexVerifyVO(); |
| | | verifyVO.setExpression(row.getParams().get("verifyValue") + ""); |
| | | verifyVO.setKey("_" + row.getKey()); |
| | | verifyVO.setMsg(row.getParams().get("verifyNotifyMsg") + ""); |
| | | verifyVOList.add(verifyVO); |
| | | } |
| | | vo.setRegexVerifyList(verifyVOList); |
| | | //提取select中的网络请求 |
| | | List<FormHttpRequestInfoVO> formHttpRequestInfoVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | if (!row.getType().equalsIgnoreCase(Select.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | |
| | | String apiPath = row.getParams().get("apiPath") + ""; |
| | | if (StringUtil.isNullOrEmpty(apiPath)) { |
| | | continue; |
| | | } |
| | | FormHttpRequestInfoVO requestInfoVO = new FormHttpRequestInfoVO(); |
| | | Map<String, String> apiParams = new HashMap<>(); |
| | | if (((List) row.getParams().get("apiParams")).size() > 0) { |
| | | List<KeyValue> apiParamsList = (List<KeyValue>) row.getParams().get("apiParams"); |
| | | for (KeyValue kv : apiParamsList) { |
| | | apiParams.put(kv.getKey(), kv.getValue()); |
| | | } |
| | | } |
| | | requestInfoVO.setParams(apiParams); |
| | | requestInfoVO.setUrl(apiPath); |
| | | //TODO 暂时固定为post,后面再支持其他的功能 |
| | | requestInfoVO.setType("POST"); |
| | | requestInfoVO.setFillTarget("select[name=" + row.getKey() + "]"); |
| | | formHttpRequestInfoVOList.add(requestInfoVO); |
| | | } |
| | | |
| | | |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | //layui更改验证 |
| | | String layVerify = ""; |
| | | if (row.getParams() != null && row.getParams().get("require") != null && (Boolean) row.getParams().get("require")) { |
| | | layVerify += "required|"; |
| | | } |
| | | if (row.getParams() != null && row.getParams().get("verifyType") != null) { |
| | | FormVerifyType verifyType = (FormVerifyType) row.getParams().get("verifyType"); |
| | | if (verifyType == FormVerifyType.regex) { |
| | | //自定义的验证名称为下划线+name |
| | | layVerify += "_" + row.getKey(); |
| | | } else if (verifyType != FormVerifyType.none) { |
| | | layVerify += verifyType.name(); |
| | | } |
| | | } |
| | | if (layVerify.endsWith("|")) |
| | | layVerify = layVerify.substring(0, layVerify.length() - 1); |
| | | //重新赋值,表单中直接取值 |
| | | row.getParams().put("verifyValue", layVerify); |
| | | } |
| | | |
| | | vo.setPreRequestList(formHttpRequestInfoVOList); |
| | | return vo; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public List<FormRowData> getRowsList() { |
| | | return rowsList; |
| | | } |
| | | |
| | | public void setRowsList(List<FormRowData> rowsList) { |
| | | this.rowsList = rowsList; |
| | | } |
| | | |
| | | public List<FormInputRegexVerifyVO> getRegexVerifyList() { |
| | | return regexVerifyList; |
| | | } |
| | | |
| | | public void setRegexVerifyList(List<FormInputRegexVerifyVO> regexVerifyList) { |
| | | this.regexVerifyList = regexVerifyList; |
| | | } |
| | | |
| | | public String getAddApi() { |
| | | return addApi; |
| | | } |
| | | |
| | | public void setAddApi(String addApi) { |
| | | this.addApi = addApi; |
| | | } |
| | | |
| | | public List<FormHttpRequestInfoVO> getPreRequestList() { |
| | | return preRequestList; |
| | | } |
| | | |
| | | public void setPreRequestList(List<FormHttpRequestInfoVO> preRequestList) { |
| | | this.preRequestList = preRequestList; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormHttpRequestInfo |
| | | * @description: 表单中的数据请求 |
| | | * @date 2021/9/26 10:25 |
| | | */ |
| | | public class FormHttpRequestInfoVO { |
| | | |
| | | //post/get |
| | | private String type; |
| | | //请求链接 |
| | | private String url; |
| | | //请求参数 |
| | | private Map<String, String> params; |
| | | //数据需要填充的jquery表达式 |
| | | private String fillTarget; |
| | | |
| | | |
| | | public String getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | |
| | | public Map<String, String> getParams() { |
| | | return params; |
| | | } |
| | | |
| | | public void setParams(Map<String, String> params) { |
| | | this.params = params; |
| | | } |
| | | |
| | | public String getFillTarget() { |
| | | return fillTarget; |
| | | } |
| | | |
| | | public void setFillTarget(String fillTarget) { |
| | | this.fillTarget = fillTarget; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormInputVerifyVO |
| | | * @description: 表单验证的正则实体 |
| | | * @date 2021/9/26 10:12 |
| | | */ |
| | | public class FormInputRegexVerifyVO { |
| | | |
| | | private String key; |
| | | private String expression; |
| | | private String msg; |
| | | |
| | | |
| | | public String getKey() { |
| | | return key; |
| | | } |
| | | |
| | | public void setKey(String key) { |
| | | this.key = key; |
| | | } |
| | | |
| | | public String getExpression() { |
| | | return expression; |
| | | } |
| | | |
| | | public void setExpression(String expression) { |
| | | this.expression = expression; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return msg; |
| | | } |
| | | |
| | | public void setMsg(String msg) { |
| | | this.msg = msg; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | 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.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; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormAddInfo |
| | | * @description: 构建修改的输出类 |
| | | * @date 2021/9/26 10:07 |
| | | */ |
| | | public class FormUpdateInfoVO { |
| | | private String title; |
| | | private List<FormRowData> rowsList; |
| | | private List<FormInputRegexVerifyVO> regexVerifyList; |
| | | private String updateApi; |
| | | private String detailApi; |
| | | |
| | | //进入页面就需要请求的数据 |
| | | private List<FormHttpRequestInfoVO> preRequestList; |
| | | |
| | | public static class Builder { |
| | | |
| | | private AdminGeneraterInfo generaterInfo; |
| | | |
| | | public Builder setAdminInfo(AdminGeneraterInfo generaterInfo) { |
| | | this.generaterInfo = generaterInfo; |
| | | return this; |
| | | } |
| | | |
| | | public FormUpdateInfoVO build() { |
| | | FormUpdateInfoVO vo = new FormUpdateInfoVO(); |
| | | vo.setUpdateApi(generaterInfo.getControllerData().mapping() + "/update"); |
| | | vo.setDetailApi(generaterInfo.getControllerData().mapping() + "/get"); |
| | | vo.setRowsList(generaterInfo.getUpdateFormRows()); |
| | | vo.setTitle("修改" + generaterInfo.getControllerData().title()); |
| | | //遍历需要正则表达式的Text或者TextArea |
| | | List<FormInputRegexVerifyVO> verifyVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | if (!row.getType().equalsIgnoreCase(Text.class.getSimpleName()) && !row.getType().equalsIgnoreCase(TextArea.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | if ((row.getParams().get("verifyType")) != FormVerifyType.regex) |
| | | continue; |
| | | FormInputRegexVerifyVO verifyVO = new FormInputRegexVerifyVO(); |
| | | verifyVO.setExpression(row.getParams().get("verifyValue") + ""); |
| | | verifyVO.setKey("_" + row.getKey()); |
| | | verifyVO.setMsg(row.getParams().get("verifyNotifyMsg") + ""); |
| | | verifyVOList.add(verifyVO); |
| | | } |
| | | vo.setRegexVerifyList(verifyVOList); |
| | | //提取select中的网络请求 |
| | | List<FormHttpRequestInfoVO> formHttpRequestInfoVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | if (!row.getType().equalsIgnoreCase(Select.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | |
| | | String apiPath = row.getParams().get("apiPath") + ""; |
| | | if (StringUtil.isNullOrEmpty(apiPath)) { |
| | | continue; |
| | | } |
| | | FormHttpRequestInfoVO requestInfoVO = new FormHttpRequestInfoVO(); |
| | | Map<String, String> apiParams = new HashMap<>(); |
| | | if (((List) row.getParams().get("apiParams")).size() > 0) { |
| | | List<KeyValue> apiParamsList = (List<KeyValue>) row.getParams().get("apiParams"); |
| | | for (KeyValue kv : apiParamsList) { |
| | | apiParams.put(kv.getKey(), kv.getValue()); |
| | | } |
| | | } |
| | | requestInfoVO.setParams(apiParams); |
| | | requestInfoVO.setUrl(apiPath); |
| | | //TODO 暂时固定为post,后面再支持其他的功能 |
| | | requestInfoVO.setType("POST"); |
| | | requestInfoVO.setFillTarget("select[name=" + row.getKey() + "]"); |
| | | formHttpRequestInfoVOList.add(requestInfoVO); |
| | | } |
| | | |
| | | |
| | | for (FormRowData row : vo.getRowsList()) { |
| | | //layui更改验证 |
| | | String layVerify = ""; |
| | | if (row.getParams() != null && row.getParams().get("require") != null && (Boolean) row.getParams().get("require")) { |
| | | layVerify += "required|"; |
| | | } |
| | | if (row.getParams() != null && row.getParams().get("verifyType") != null) { |
| | | FormVerifyType verifyType = (FormVerifyType) row.getParams().get("verifyType"); |
| | | if (verifyType == FormVerifyType.regex) { |
| | | //自定义的验证名称为下划线+name |
| | | layVerify += "_" + row.getKey(); |
| | | } else if (verifyType != FormVerifyType.none) { |
| | | layVerify += verifyType.name(); |
| | | } |
| | | } |
| | | if (layVerify.endsWith("|")) |
| | | layVerify = layVerify.substring(0, layVerify.length() - 1); |
| | | //重新赋值,表单中直接取值 |
| | | row.getParams().put("verifyValue", layVerify); |
| | | } |
| | | |
| | | vo.setPreRequestList(formHttpRequestInfoVOList); |
| | | return vo; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public List<FormRowData> getRowsList() { |
| | | return rowsList; |
| | | } |
| | | |
| | | public void setRowsList(List<FormRowData> rowsList) { |
| | | this.rowsList = rowsList; |
| | | } |
| | | |
| | | public List<FormInputRegexVerifyVO> getRegexVerifyList() { |
| | | return regexVerifyList; |
| | | } |
| | | |
| | | public void setRegexVerifyList(List<FormInputRegexVerifyVO> regexVerifyList) { |
| | | this.regexVerifyList = regexVerifyList; |
| | | } |
| | | |
| | | public String getUpdateApi() { |
| | | return updateApi; |
| | | } |
| | | |
| | | public void setUpdateApi(String updateApi) { |
| | | this.updateApi = updateApi; |
| | | } |
| | | |
| | | public String getDetailApi() { |
| | | return detailApi; |
| | | } |
| | | |
| | | public void setDetailApi(String detailApi) { |
| | | this.detailApi = detailApi; |
| | | } |
| | | |
| | | public List<FormHttpRequestInfoVO> getPreRequestList() { |
| | | return preRequestList; |
| | | } |
| | | |
| | | public void setPreRequestList(List<FormHttpRequestInfoVO> preRequestList) { |
| | | this.preRequestList = preRequestList; |
| | | } |
| | | } |
New file |
| | |
| | | package org.yeshi.utils.generater.vo.admin; |
| | | |
| | | 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.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; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @title: FormAddInfo |
| | | * @description: 构建修改的输出类 |
| | | * @date 2021/9/26 10:07 |
| | | */ |
| | | public class ListInfoVO { |
| | | private String title; |
| | | private List<FormRowData> searchFormRows; |
| | | //显示的字段 |
| | | private List<Map<String, Object>> showFileds; |
| | | //进入页面就需要请求的数据 |
| | | private List<FormHttpRequestInfoVO> preRequestList; |
| | | private List<FormInputRegexVerifyVO> regexVerifyList; |
| | | //列表接口 |
| | | private String listApi; |
| | | //添加页路径 |
| | | private String addPagePath; |
| | | //更新页路径 |
| | | private String updatePagePath; |
| | | |
| | | |
| | | public static class Builder { |
| | | |
| | | private AdminGeneraterInfo generaterInfo; |
| | | |
| | | public Builder setAdminInfo(AdminGeneraterInfo generaterInfo) { |
| | | this.generaterInfo = generaterInfo; |
| | | return this; |
| | | } |
| | | |
| | | public ListInfoVO build() { |
| | | ListInfoVO vo = new ListInfoVO(); |
| | | vo.setListApi(generaterInfo.getControllerData().mapping() + "/list"); |
| | | vo.setAddPagePath("add.html"); |
| | | vo.setUpdatePagePath("update.html"); |
| | | vo.setSearchFormRows(generaterInfo.getSearchFormRows()); |
| | | vo.setShowFileds(generaterInfo.getShowDataList()); |
| | | vo.setTitle("修改" + generaterInfo.getControllerData().title()); |
| | | //遍历需要正则表达式的Text或者TextArea |
| | | List<FormInputRegexVerifyVO> verifyVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getSearchFormRows()) { |
| | | if (!row.getType().equalsIgnoreCase(Text.class.getSimpleName()) && !row.getType().equalsIgnoreCase(TextArea.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | if ((row.getParams().get("verifyType")) != FormVerifyType.regex) |
| | | continue; |
| | | FormInputRegexVerifyVO verifyVO = new FormInputRegexVerifyVO(); |
| | | verifyVO.setExpression(row.getParams().get("verifyValue") + ""); |
| | | verifyVO.setKey("_" + row.getKey()); |
| | | verifyVO.setMsg(row.getParams().get("verifyNotifyMsg") + ""); |
| | | verifyVOList.add(verifyVO); |
| | | } |
| | | vo.setRegexVerifyList(verifyVOList); |
| | | //提取select中的网络请求 |
| | | List<FormHttpRequestInfoVO> formHttpRequestInfoVOList = new ArrayList<>(); |
| | | for (FormRowData row : vo.getSearchFormRows()) { |
| | | if (!row.getType().equalsIgnoreCase(Select.class.getSimpleName())) { |
| | | continue; |
| | | } |
| | | if (row.getParams() == null) |
| | | continue; |
| | | |
| | | String apiPath = row.getParams().get("apiPath") + ""; |
| | | if (StringUtil.isNullOrEmpty(apiPath)) { |
| | | continue; |
| | | } |
| | | FormHttpRequestInfoVO requestInfoVO = new FormHttpRequestInfoVO(); |
| | | Map<String, String> apiParams = new HashMap<>(); |
| | | if (((List) row.getParams().get("apiParams")).size() > 0) { |
| | | List<KeyValue> apiParamsList = (List<KeyValue>) row.getParams().get("apiParams"); |
| | | for (KeyValue kv : apiParamsList) { |
| | | apiParams.put(kv.getKey(), kv.getValue()); |
| | | } |
| | | } |
| | | requestInfoVO.setParams(apiParams); |
| | | requestInfoVO.setUrl(apiPath); |
| | | //TODO 暂时固定为post,后面再支持其他的功能 |
| | | requestInfoVO.setType("POST"); |
| | | requestInfoVO.setFillTarget("select[name=" + row.getKey() + "]"); |
| | | formHttpRequestInfoVOList.add(requestInfoVO); |
| | | } |
| | | |
| | | |
| | | for (FormRowData row : vo.getSearchFormRows()) { |
| | | //layui更改验证 |
| | | String layVerify = ""; |
| | | if (row.getParams() != null && row.getParams().get("require") != null && (Boolean) row.getParams().get("require")) { |
| | | layVerify += "required|"; |
| | | } |
| | | if (row.getParams() != null && row.getParams().get("verifyType") != null) { |
| | | FormVerifyType verifyType = (FormVerifyType) row.getParams().get("verifyType"); |
| | | if (verifyType == FormVerifyType.regex) { |
| | | //自定义的验证名称为下划线+name |
| | | layVerify += "_" + row.getKey(); |
| | | } else if (verifyType != FormVerifyType.none) { |
| | | layVerify += verifyType.name(); |
| | | } |
| | | } |
| | | if (layVerify.endsWith("|")) |
| | | layVerify = layVerify.substring(0, layVerify.length() - 1); |
| | | //重新赋值,表单中直接取值 |
| | | row.getParams().put("verifyValue", layVerify); |
| | | } |
| | | |
| | | vo.setPreRequestList(formHttpRequestInfoVOList); |
| | | return vo; |
| | | } |
| | | |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public List<FormRowData> getSearchFormRows() { |
| | | return searchFormRows; |
| | | } |
| | | |
| | | public void setSearchFormRows(List<FormRowData> searchFormRows) { |
| | | this.searchFormRows = searchFormRows; |
| | | } |
| | | |
| | | public List<FormHttpRequestInfoVO> getPreRequestList() { |
| | | return preRequestList; |
| | | } |
| | | |
| | | public void setPreRequestList(List<FormHttpRequestInfoVO> preRequestList) { |
| | | this.preRequestList = preRequestList; |
| | | } |
| | | |
| | | public List<FormInputRegexVerifyVO> getRegexVerifyList() { |
| | | return regexVerifyList; |
| | | } |
| | | |
| | | public void setRegexVerifyList(List<FormInputRegexVerifyVO> regexVerifyList) { |
| | | this.regexVerifyList = regexVerifyList; |
| | | } |
| | | |
| | | public String getListApi() { |
| | | return listApi; |
| | | } |
| | | |
| | | public void setListApi(String listApi) { |
| | | this.listApi = listApi; |
| | | } |
| | | |
| | | public String getAddPagePath() { |
| | | return addPagePath; |
| | | } |
| | | |
| | | public void setAddPagePath(String addPagePath) { |
| | | this.addPagePath = addPagePath; |
| | | } |
| | | |
| | | public String getUpdatePagePath() { |
| | | return updatePagePath; |
| | | } |
| | | |
| | | public void setUpdatePagePath(String updatePagePath) { |
| | | this.updatePagePath = updatePagePath; |
| | | } |
| | | |
| | | public List<Map<String, Object>> getShowFileds() { |
| | | return showFileds; |
| | | } |
| | | |
| | | public void setShowFileds(List<Map<String, Object>> showFileds) { |
| | | this.showFileds = showFileds; |
| | | } |
| | | } |
| | |
| | | |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>新增${controllerData.title}</title> |
| | | <title>${title}</title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" |
| | |
| | | <div class="layui-row"> |
| | | <form class="layui-form" lay-filter="add"> |
| | | |
| | | <#list addFormRows as value> |
| | | <#list rowsList as value> |
| | | <div class="layui-form-item"> |
| | | <label for="L_appCode" class="layui-form-label"> |
| | | <#if value.params.require??&&value.params.require> |
| | | <span class="x-red">*</span> |
| | | </#if> |
| | | ${value.params.title}</label> |
| | | |
| | | <div class="layui-input-block"> |
| | | <#switch value.type> |
| | | <#case "CheckBox"><#include "/admin/form/checkBox.ftl" ><#break> |
| | | <#case "Img"> <#include "/admin/form/img.ftl"><#break> |
| | |
| | | <#case "TextArea"> <#include "/admin/form/textArea.ftl"><#break> |
| | | <#default> |
| | | </#switch> |
| | | </div> |
| | | |
| | | <#if (value.desc!"") != ""> |
| | | <div class="layui-form-mid layui-word-aux">${value.desc}</div> |
| | |
| | | </div> |
| | | </div> |
| | | <script> |
| | | //初始化上传控件 |
| | | var uploadTool = { |
| | | callback: null, |
| | | chooseImage: {}, |
| | | uploadArray: new Array(), |
| | | init: function (upload) { |
| | | this.uploadArray = new Array(); |
| | | <#list rowsList as value> |
| | | <#if value.type=='Img'&&value.params.uploadApi??> |
| | | this.uploadArray.push(upload.render({ |
| | | elem: '#upload_${value.key}', //绑定元素 |
| | | url: '${value.params.uploadApi}', //上传接口 |
| | | <#if value.params.uploadApiParams??&&(value.params.uploadApiParams?size>0)> |
| | | data: { |
| | | <#list value.params.uploadApiParams as item> |
| | | "${item.key}": "${item.value}", |
| | | </#list> |
| | | }, |
| | | </#if> |
| | | auto: false, |
| | | accept: 'images', |
| | | acceptMime: 'image/*', |
| | | field: "file_${value.key}", |
| | | choose: function (obj) { |
| | | //将每次选择的文件追加到文件队列 |
| | | var files = obj.pushFile(); |
| | | //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9) |
| | | obj.preview(function (index, file, result) { |
| | | console.log(index); //得到文件索引 |
| | | console.log(file); //得到文件对象 |
| | | console.log(result); //得到文件base64编码,比如图片 |
| | | $("#img_${value.key}").attr("src", result); |
| | | //记录选中的文件 |
| | | uploadTool.chooseImage["${value.key}"] = "1"; |
| | | }); |
| | | }, |
| | | before: function (obj) { |
| | | layer.load(); |
| | | }, |
| | | done: function (res, index, upload) { |
| | | layer.closeAll('loading'); //关闭loading |
| | | //上传完毕后删除 |
| | | if (res.code == 0) { |
| | | //获取链接 |
| | | $("input[name='${value.key}']").val(res.data.url); |
| | | delete chooseImage["${value.key}"]; |
| | | if (Object.keys(chooseImage).length == 0) { |
| | | //全部上传成功 |
| | | callback(); |
| | | } |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | }, |
| | | error: function (index, upload) { |
| | | layer.msg("${value.params.title}上传出错"); |
| | | layer.closeAll('loading'); //关闭loading |
| | | } |
| | | })); |
| | | </#if> |
| | | </#list> |
| | | |
| | | layui.use(['form', 'layer', 'jquery'], function () { |
| | | }, |
| | | upload: function (result) { |
| | | if (this.uploadArray.length > 0) { |
| | | this.callback = result; |
| | | //同时上传 |
| | | for (var i = 0; i < this.uploadArray.length; i++) { |
| | | this.uploadArray[i].upload(); |
| | | } |
| | | } else { |
| | | result(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | </script> |
| | | |
| | | <script> |
| | | layui.use(['form', 'layer', 'jquery', 'upload'], function () { |
| | | $ = layui.jquery; |
| | | var form = layui.form, |
| | | layer = layui.layer; |
| | | layer = layui.layer, |
| | | upload = layui.upload; |
| | | |
| | | var verify = {}; |
| | | <#list regexVerifyList as regex> |
| | | verify["${regex.key}"] = [/${regex.expression}/, '${regex.msg}']; |
| | | </#list> |
| | | //自定义验证规则 |
| | | form.verify({ |
| | | username: function (value) { |
| | | if (value.length < 3) { |
| | | return '名称至少得3个字符'; |
| | | } |
| | | }, |
| | | code: function (value) { |
| | | if (value) { |
| | | if (!(/^([A-Za-z0-9]|\-|_)+$/).test(value)) { |
| | | return '标识只能包含 数字、英文字符、_ 、-'; |
| | | } |
| | | } |
| | | }, |
| | | packageName: [/^([A-Za-z0-9]|\-|_|\.)+$/, '包名只能包含 数字、英文字符、_ 、-、.'], |
| | | desc: function (value) { |
| | | if (value != null && value.length > 128) { |
| | | return '简介最大为128个字符'; |
| | | } |
| | | }, |
| | | remarks: function (value) { |
| | | if (value != null && value.length > 128) { |
| | | return '备注最大为128个字符'; |
| | | } |
| | | }, |
| | | form.verify(verify); |
| | | |
| | | }); |
| | | //渲染上传控件 |
| | | uploadTool.init(upload); |
| | | |
| | | |
| | | //监听提交 |
| | |
| | | data.field[onkeys[0]][onkeys[1]] = value; |
| | | } |
| | | } |
| | | uploadTool.upload(function(){ |
| | | //发异步,把数据提交给php |
| | | ksapp.postJSON('/admin/api/pushplatform-app/add', data.field, function (res) { |
| | | ksapp.postJSON('${addApi}', data.field, function (res) { |
| | | if (res.code == 0) { |
| | | layer.alert("增加成功", { |
| | | icon: 6 |
| | |
| | | |
| | | }, function (res) { |
| | | }); |
| | | }); |
| | | return false; |
| | | }); |
| | | //请求select的数据API |
| | | <#if preRequestList??&&(preRequestList?size>0)> |
| | | <#list preRequestList as request> |
| | | <#assign apiKeys=request.params?keys/> |
| | | var params = {}; |
| | | <#list apiKeys as key> |
| | | params["${key}"]=${request.params["${key}"]} |
| | | </#list> |
| | | |
| | | }); |
| | | |
| | | |
| | | |
| | | var app = new Vue({ |
| | | el: '.layui-form', |
| | | data: { |
| | | appList: [], |
| | | platformList: [ |
| | | {name: "小米", platform: "xm"}, |
| | | {name: "华为", platform: "hw"}, |
| | | {name: "OPPO", platform: "oppo"}, |
| | | {name: "VIVO", platform: "vivo"}, |
| | | {name: "魅族", platform: "mz"} |
| | | ] |
| | | }, |
| | | created: function () { |
| | | this.getAppList(); |
| | | }, |
| | | watch: { |
| | | appList: function () { |
| | | app.render(); |
| | | ksapp.postJSON('${request.url}', params, function (res) { |
| | | if (res.code == 0) { |
| | | //填充数据 |
| | | $("${request.fillTarget}").empty(); |
| | | for (var i = 0; i < res.data.length; i++) { |
| | | var html = "<option value='" + res.data[i].key + "'>"; |
| | | html += res.data[i].value + "</option>"; |
| | | $("${request.fillTarget}").append(html); |
| | | } |
| | | //重新渲染表单 |
| | | form.render(); |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | |
| | | }, |
| | | methods: { |
| | | getAppList: function () { |
| | | ksapp.post("/admin/api/app/list", {page: 1, limit: 100}, function (e) { |
| | | if (e.code == 0) { |
| | | app.appList = e.data.list; |
| | | } else |
| | | layer.msg(e.msg); |
| | | }, function (e) { |
| | | }, function (res) { |
| | | }); |
| | | }, |
| | | render: function () { |
| | | console.log("render") |
| | | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | </#list> |
| | | </#if> |
| | | }) |
| | | ; |
| | | </script> |
| | | </body> |
| | | |
| | |
| | | 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; |
| | | import com.google.gson.*; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | <#list importClasses as value> |
| | | import ${value}; |
| | | </#list> |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.lang.reflect.Type; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import ${entity.clazz}; |
| | | import ${service.clazz}; |
| | | import ${query.clazz}; |
| | | |
| | | @Controller |
| | | @RequestMapping("${mapping}") |
| | | public class AdminAppController { |
| | | |
| | | @Repository |
| | | public class ${daoName} extends ${baseDaoClassName}<${entityClassName}>{ |
| | | <#assign serviceObjName=${service.name?uncap_first}"> |
| | | @Resource |
| | | private ${service.name} ${serviceObjName}; |
| | | |
| | | public void updateSelective(${entityClassName} 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}); |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String list(${query.name} query, int page, int limit) { |
| | | List<${entityName}> 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>() { |
| | | |
| | | @Override |
| | | public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { |
| | | return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm")); |
| | | } |
| | | </#list> |
| | | </#if> |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | }).create(); |
| | | |
| | | data.put("list", gson.toJson(list)); |
| | | data.put("count", count); |
| | | return 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)); |
| | | } |
| | | ${serviceObjName}.delete(idList); |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | |
| | | public List<${entityClassName}> list(DaoQuery daoQuery){ |
| | | Query query=getQuery(daoQuery); |
| | | if(daoQuery.sortList!=null&&daoQuery.sortList.size()>0){ |
| | | query.with(new Sort(daoQuery.sortList)); |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("add") |
| | | public String add(${entity.name} bean, HttpSession session) { |
| | | try{ |
| | | ${serviceObjName}.add(bean); |
| | | return JsonUtil.loadTrueResult(""); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage); |
| | | } |
| | | query.skip(daoQuery.start); |
| | | query.limit(daoQuery.count); |
| | | return findList(query); |
| | | } |
| | | |
| | | public long count(DaoQuery daoQuery){ |
| | | Query query=getQuery(daoQuery); |
| | | return count(query); |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | 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})); |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("update") |
| | | public String update(${entity.name} bean, HttpSession session) { |
| | | if (app.getId() == null) { |
| | | return JsonUtil.loadFalseResult("ID不能为空"); |
| | | } |
| | | if(daoQuery.max${value.columnName?cap_first}!=null){ |
| | | andList.add(Criteria.where("${value.columnName}").lt(daoQuery.max${value.columnName?cap_first})); |
| | | try{ |
| | | ${serviceObjName}.updateSelective(bean); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage); |
| | | } |
| | | <#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; |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | <div class="layui-input-block"> |
| | | <input type="checkbox" name="${value.key}" title="写作"> |
| | | </div> |
| | | <input type="checkbox" name="${value.key}" title="${value.value}"> |
| | |
| | | <div class="layui-input-inline"> |
| | | <select id="L_appCode" name="appCode" lay-verify="required" lay-search=""> |
| | | <option value="">直接选择或搜索应用</option> |
| | | <option v-for="item in appList" :value="item.appCode">{{item.name}}</option> |
| | | </select> |
| | | </div> |
| | | <#if value.params.uploadApi??&&value.params.uploadApi!=""> |
| | | <img id="img_${value.key}" style="display: block;margin-bottom: 10px; <#if value.params.width gt 0 > width:${value.params.width}px;</#if> <#if value.params.height gt 0 > height:${value.params.height}px;</#if> " /> |
| | | <button type="button" class="layui-btn" id="upload_${value.key}" style="margin-bottom: 5px"> |
| | | <i class="layui-icon"></i>上传图片 |
| | | </button> |
| | | </#if> |
| | | <input class="layui-input" type="text" name="${value.key}" placeholder="请输入图片链接"> |
| | |
| | | <div class="layui-input-inline"> |
| | | <input type="password" name="${value.key}" required lay-verify="required" placeholder="请输入密码" autocomplete="off" |
| | | class="layui-input"> |
| | | </div> |
| | |
| | | <div class="layui-input-block"> |
| | | <#list value.params.values as item > |
| | | <input type="radio" name="${value.key}" value="${item.key}" title="${item.value}"> |
| | | <input type="radio" required name="${value.key}" value="${item.key}" title="${item.value}"> |
| | | </#list> |
| | | </div> |
| | |
| | | <div class="layui-input-block"> |
| | | <select name="${value.key}" lay-verify="required"> |
| | | <#if value.params.values??&&(value.params.values?size>0)> |
| | | <#list value.params.values as item> |
| | |
| | | </#list> |
| | | </#if> |
| | | </select> |
| | | </div> |
| | |
| | | <div class="layui-input-block"> |
| | | <input type="checkbox" name="${value.key}" lay-skin="switch"> |
| | | </div> |
| | |
| | | <div class="layui-input-block"> |
| | | <input type="text" name="${value.key}" required lay-verify="required" placeholder="${value.params.placeHolder}" autocomplete="off" |
| | | <input type="text" name="${value.key}" <#if value.params.verifyValue??> lay-verify="${value.params.verifyValue}" </#if> placeholder="${value.params.placeHolder}" autocomplete="off" |
| | | class="layui-input"> |
| | | </div> |
| | |
| | | <div class="layui-input-block"> |
| | | <textarea name="${value.key}" placeholder="${value.params.placeHolder}" class="layui-textarea"></textarea> |
| | | </div> |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html class="x-admin-sm"> |
| | | |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>${title}列表</title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" |
| | | content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/> |
| | | <link rel="stylesheet" href="./css/font.css"> |
| | | <link rel="stylesheet" href="./css/xadmin.css"> |
| | | <script src="./lib/layui/layui.js" charset="utf-8"></script> |
| | | <link rel="stylesheet" href="./css/theme3049.min.css"> |
| | | <script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script> |
| | | <script type="text/javascript" src="./js/xadmin.js"></script> |
| | | <script src="js/http.js" type="text/javascript" charset="utf-8"></script> |
| | | <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> |
| | | <!--[if lt IE 9]> |
| | | <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> |
| | | <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> |
| | | <![endif]--> |
| | | <script src="./js/utils.js"></script> |
| | | </head> |
| | | |
| | | <body> |
| | | <div class="x-nav"> |
| | | <span class="layui-breadcrumb"> |
| | | <a href="">###</a> |
| | | <a> |
| | | <cite>###</cite></a> |
| | | </span> |
| | | <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" |
| | | onclick="location.reload()" title="刷新"> |
| | | <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i> |
| | | </a> |
| | | </div> |
| | | <div class="layui-fluid" id="app"> |
| | | <div class="layui-row layui-col-space15"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body"> |
| | | <form class="layui-form layui-col-space5"> |
| | | <#list rowsList as value> |
| | | <div class="layui-inline layui-show-xs-block"> |
| | | <#switch value.type> |
| | | <#case "CheckBox"><#include "/admin/form/checkBox.ftl" ><#break> |
| | | <#case "Img"> <#include "/admin/form/img.ftl"><#break> |
| | | <#case "Password"> <#include "/admin/form/password.ftl"><#break> |
| | | <#case "RadioGroup"> <#include "/admin/form/radioGroup.ftl"><#break> |
| | | <#case "Select"> <#include "/admin/form/select.ftl"><#break> |
| | | <#case "Switch"> <#include "/admin/form/switch.ftl"><#break> |
| | | <#case "Text"> <#include "/admin/form/text.ftl"><#break> |
| | | <#case "TextArea"> <#include "/admin/form/textArea.ftl"><#break> |
| | | <#default> |
| | | </#switch> |
| | | </div> |
| | | </#list> |
| | | <div class="layui-inline layui-show-xs-block"> |
| | | <button id="search" class="layui-btn" lay-submit="" lay-filter="sreach"> |
| | | <i class="layui-icon"></i></button> |
| | | </div> |
| | | </form> |
| | | </div> |
| | | <div class="layui-card-body "> |
| | | <table class="layui-table" id="table_list" lay-filter="app"> |
| | | </table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </body> |
| | | <script type="text/html" id="toolbar"> |
| | | <div class="layui-btn-container"> |
| | | <button class="layui-btn" onclick="xadmin.open('添加${title}','${addPagePath}',500,580)"><i |
| | | class="layui-icon"></i>添加 |
| | | </button> |
| | | |
| | | <button class="layui-btn layui-btn-danger" lay-event="delete"> |
| | | <i class="layui-icon"></i> |
| | | 删除 |
| | | </button> |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="deleteContainer"> |
| | | <div class="layui-btn-container"> |
| | | <!-- <a title='恢复' onclick='member_resume(this,{{d.LAY_INDEX }}, {{d.id}})' href='javascript:;'> --> |
| | | <!--<i class="layui-icon"></i>--> |
| | | <!--</a>--> |
| | | |
| | | <a title="删除" onclick="member_del(this,{{d.LAY_INDEX }},'{{d.id}}')" href="javascript:;"> |
| | | <i class="layui-icon"></i> |
| | | </a> |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="statusContainer"> |
| | | <div class="layui-btn-container"> |
| | | {{# if(d.status==0){ }} |
| | | <span class="layui-btn layui-btn-mini"> |
| | | 正常 |
| | | </span> |
| | | {{# }else{ }} |
| | | <span class="layui-btn layui-btn-danger layui-btn-mini"> |
| | | 已删除 |
| | | </span> |
| | | {{# } }} |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="switchTpl"> |
| | | <!-- 这里的checked的状态只是演示 --> |
| | | <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="女|男" lay-filter="sexDemo" {{ d.id== |
| | | 10003 ? 'checked': ''}} > |
| | | </script> |
| | | |
| | | <script> |
| | | |
| | | function member_del(obj, index, id) { |
| | | layer.confirm('确认要删除吗?', function (index) { |
| | | //发异步删除数据 |
| | | app.delete(obj, index, id); |
| | | }); |
| | | } |
| | | |
| | | </script> |
| | | |
| | | <script> |
| | | var tableIns = null; |
| | | $(function () { |
| | | |
| | | |
| | | //渲染表格 |
| | | function rederTable() { |
| | | tableIns = table.render({ |
| | | elem: '#table_list', |
| | | url: url, |
| | | toolbar: "#toolbar", |
| | | totalRow: true, |
| | | cols: [{type: 'checkbox', title: "ID"}, |
| | | {field: 'id', width: 120, sort: true, title: "ID"}, |
| | | {fixed: 'right', width: 80, title: "操作", toolbar: '#deleteContainer'}], |
| | | page: true, |
| | | parseData: |
| | | function (res) { //res 即为原始返回的数据 |
| | | if (res.code != 0) |
| | | return; |
| | | if (res.data.list == null) |
| | | return; |
| | | console.log(res.data.list) |
| | | return { |
| | | "code": res.code, //解析接口状态 |
| | | "msg": res.msg, //解析提示文本 |
| | | "count": res.data.count, //解析数据长度 |
| | | "data": res.data.list //解析数据列表 |
| | | }; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | var app = new Vue({ |
| | | el: "#app", |
| | | data: { |
| | | key: '', |
| | | start: '', |
| | | end: '', |
| | | appList: [] |
| | | }, |
| | | watch: {}, |
| | | created: function () { |
| | | |
| | | }, |
| | | methods: { |
| | | init: function () { |
| | | //初始化 |
| | | layui.use(['laydate', 'form', 'table'], function () { |
| | | var laydate = layui.laydate, |
| | | form = layui.form, |
| | | table = layui.table; |
| | | //渲染日期输入框 |
| | | <#list searchForm as row > |
| | | <#if row.type??&&row.type=="Text"&&(row.params.type=="date")> |
| | | laydate.render({ |
| | | elem: "intput[name=${row.key}]" //指定元素 |
| | | }); |
| | | </#if> |
| | | </#list> |
| | | //搜索条件 |
| | | form.on('submit(search)', function (data) { |
| | | app.search(data.field); |
| | | return false; |
| | | }); |
| | | |
| | | tableIns = table.render({ |
| | | elem: '#table_list', |
| | | url: ${listApi}, |
| | | toolbar: "#toolbar", |
| | | totalRow: true, |
| | | cols: [{type: 'checkbox', title: "ID"}, |
| | | {field: 'id', width: 120, sort: true, title: "ID"}, |
| | | {fixed: 'right', width: 80, title: "操作", toolbar: '#deleteContainer'}], |
| | | page: true, |
| | | parseData: function (res) { //res 即为原始返回的数据 |
| | | if (res.code != 0) |
| | | return; |
| | | if (res.data.list == null) |
| | | return; |
| | | console.log(res.data.list) |
| | | return { |
| | | "code": res.code, //解析接口状态 |
| | | "msg": res.msg, //解析提示文本 |
| | | "count": res.data.count, //解析数据长度 |
| | | "data": res.data.list //解析数据列表 |
| | | }; |
| | | } |
| | | //,…… //其他参数 |
| | | }); |
| | | |
| | | //头工具栏事件 |
| | | tableIns.on('toolbar(app)', |
| | | function (obj) { |
| | | var checkStatus = table.checkStatus(obj.config.id); |
| | | switch (obj.event) { |
| | | case 'delete': |
| | | var data = checkStatus.data; |
| | | if (data == null || data.length == 0) { |
| | | layer.msg("未选择选项"); |
| | | return; |
| | | } |
| | | var ids = new Array(); |
| | | for (var i = 0; i < data.length; i++) |
| | | ids.push(data[i].id); |
| | | layer.confirm('确认要删除吗?', function (index) { |
| | | //发异步删除数据 |
| | | app.deleteList(ids, function () { |
| | | layer.msg("删除成功"); |
| | | $("form").submit(); |
| | | }); |
| | | }); |
| | | |
| | | break; |
| | | } |
| | | ; |
| | | }); |
| | | //请求搜索表单中需要的数据 |
| | | <#if preRequestList??&&(preRequestList?size>0)> |
| | | |
| | | var requestCount = 0; |
| | | <#list preRequestList as request> |
| | | requestCount++; |
| | | <#assign apiKeys=request.params?keys/> |
| | | var params = {}; |
| | | <#list apiKeys as key> |
| | | params["${key}"]=${request.params["${key}"]} |
| | | </#list> |
| | | |
| | | ksapp.postJSON('${request.url}', params, function (res) { |
| | | if (res.code == 0) { |
| | | //填充数据 |
| | | $("${request.fillTarget}").empty(); |
| | | for (var i = 0; i < res.data.length; i++) { |
| | | var html = "<option value='" + res.data[i].key + "'>"; |
| | | html += res.data[i].value + "</option>"; |
| | | $("${request.fillTarget}").append(html); |
| | | } |
| | | //重新渲染表单 |
| | | form.render(); |
| | | |
| | | requestCount--; |
| | | if (requestCount <= 0) { |
| | | //搜索 |
| | | $('#search').trigger("click"); |
| | | } |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | |
| | | }, function (res) { |
| | | }); |
| | | </#list> |
| | | <#else> |
| | | $('#search').trigger("click"); |
| | | </#if> |
| | | }); |
| | | |
| | | }, |
| | | delete: function (obj, index, id) { |
| | | var ids = new Array(); |
| | | ids.push(id); |
| | | app.deleteList(ids, function () { |
| | | $(obj).parents("tr").remove(); |
| | | layer.msg('已删除!', {icon: 1, time: 1000}); |
| | | }); |
| | | }, |
| | | deleteList: function (ids, success) { |
| | | ksapp.post("${deleteApi}", {ids: JSON.stringify(ids)}, function (e) { |
| | | if (e.code == 0) { |
| | | success(); |
| | | } else { |
| | | layer.msg(e.msg); |
| | | } |
| | | }, function (e) { |
| | | }); |
| | | }, |
| | | search: function (params) { |
| | | //数据重载 |
| | | tableIns.reload({ |
| | | where: params, |
| | | page: { |
| | | curr: 1 //重新从第 1 页开始 |
| | | } |
| | | }); |
| | | }, |
| | | } |
| | | } |
| | | }) |
| | | ; |
| | | } |
| | | ) |
| | | ; |
| | | |
| | | </script> |
| | | |
| | | <script> |
| | | |
| | | </script> |
| | | </html> |
| | |
| | | package ${packageName}; |
| | | <!DOCTYPE html> |
| | | <html class="x-admin-sm"> |
| | | |
| | | 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; |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title>${title}</title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" |
| | | content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/> |
| | | <link rel="stylesheet" href="./css/font.css"> |
| | | <link rel="stylesheet" href="./css/xadmin.css"> |
| | | <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="./js/xadmin.js"></script> |
| | | <script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script> |
| | | <script src="js/http.js" type="text/javascript" charset="utf-8"></script> |
| | | <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> |
| | | <!-- 让IE8/9支持媒体查询,从而兼容栅格 --> |
| | | <!--[if lt IE 9]> |
| | | <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> |
| | | <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> |
| | | <![endif]--> |
| | | </head> |
| | | <body> |
| | | <div class="layui-fluid"> |
| | | <div class="layui-row"> |
| | | <form class="layui-form" lay-filter="add"> |
| | | |
| | | <#list importClasses as value> |
| | | import ${value}; |
| | | </#list> |
| | | |
| | | |
| | | @Repository |
| | | public class ${daoName} extends ${baseDaoClassName}<${entityClassName}>{ |
| | | |
| | | public void updateSelective(${entityClassName} 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> |
| | | <#list rowsList as value> |
| | | <div class="layui-form-item"> |
| | | <label for="L_appCode" class="layui-form-label"> |
| | | <#if value.params.require??&&value.params.require> |
| | | <span class="x-red">*</span> |
| | | </#if> |
| | | update.set("updateTime", new Date()); |
| | | update(query, update); |
| | | ${value.params.title}</label> |
| | | <div class="layui-input-block"> |
| | | <#switch value.type> |
| | | <#case "CheckBox"><#include "/admin/form/checkBox.ftl" ><#break> |
| | | <#case "Img"> <#include "/admin/form/img.ftl"><#break> |
| | | <#case "Password"> <#include "/admin/form/password.ftl"><#break> |
| | | <#case "RadioGroup"> <#include "/admin/form/radioGroup.ftl"><#break> |
| | | <#case "Select"> <#include "/admin/form/select.ftl"><#break> |
| | | <#case "Switch"> <#include "/admin/form/switch.ftl"><#break> |
| | | <#case "Text"> <#include "/admin/form/text.ftl"><#break> |
| | | <#case "TextArea"> <#include "/admin/form/textArea.ftl"><#break> |
| | | <#default> |
| | | </#switch> |
| | | </div> |
| | | |
| | | <#if (value.desc!"") != ""> |
| | | <div class="layui-form-mid layui-word-aux">${value.desc}</div> |
| | | </#if> |
| | | </div> |
| | | </#list> |
| | | |
| | | <div class="layui-form-item"> |
| | | <label for="L_remarks" class="layui-form-label"></label> |
| | | <button class="layui-btn" lay-filter="add" lay-submit="">确定修改</button> |
| | | </div> |
| | | </form> |
| | | </div> |
| | | </div> |
| | | <script> |
| | | //初始化上传控件 |
| | | var uploadTool = { |
| | | callback: null, |
| | | chooseImage: {}, |
| | | uploadArray: new Array(), |
| | | init: function (upload) { |
| | | this.uploadArray = new Array(); |
| | | <#list rowsList as value> |
| | | <#if value.type=='Img'&&value.params.uploadApi??> |
| | | this.uploadArray.push(upload.render({ |
| | | elem: '#upload_${value.key}', //绑定元素 |
| | | url: '${value.params.uploadApi}', //上传接口 |
| | | <#if value.params.uploadApiParams??&&(value.params.uploadApiParams?size>0)> |
| | | data: { |
| | | <#list value.params.uploadApiParams as item> |
| | | "${item.key}": "${item.value}", |
| | | </#list> |
| | | }, |
| | | </#if> |
| | | auto: false, |
| | | accept: 'images', |
| | | acceptMime: 'image/*', |
| | | field: "file_${value.key}", |
| | | choose: function (obj) { |
| | | //将每次选择的文件追加到文件队列 |
| | | var files = obj.pushFile(); |
| | | //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9) |
| | | obj.preview(function (index, file, result) { |
| | | console.log(index); //得到文件索引 |
| | | console.log(file); //得到文件对象 |
| | | console.log(result); //得到文件base64编码,比如图片 |
| | | $("#img_${value.key}").attr("src", result); |
| | | //记录选中的文件 |
| | | uploadTool.chooseImage["${value.key}"] = "1"; |
| | | }); |
| | | }, |
| | | before: function (obj) { |
| | | layer.load(); |
| | | }, |
| | | done: function (res, index, upload) { |
| | | layer.closeAll('loading'); //关闭loading |
| | | //上传完毕后删除 |
| | | if (res.code == 0) { |
| | | //获取链接 |
| | | $("input[name='${value.key}']").val(res.data.url); |
| | | delete chooseImage["${value.key}"]; |
| | | if (Object.keys(chooseImage).length == 0) { |
| | | //全部上传成功 |
| | | callback(); |
| | | } |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | }, |
| | | error: function (index, upload) { |
| | | layer.msg("${value.params.title}上传出错"); |
| | | layer.closeAll('loading'); //关闭loading |
| | | } |
| | | })); |
| | | </#if> |
| | | </#list> |
| | | |
| | | }, |
| | | upload: function (result) { |
| | | if (this.uploadArray.length > 0) { |
| | | this.callback = result; |
| | | //同时上传 |
| | | for (var i = 0; i < this.uploadArray.length; i++) { |
| | | this.uploadArray[i].upload(); |
| | | } |
| | | } else { |
| | | result(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | public List<${entityClassName}> 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); |
| | | </script> |
| | | |
| | | <script> |
| | | //填充数据 |
| | | function fillData(form) { |
| | | var id = ksapp.getQueryParam("id"); |
| | | if (id) { |
| | | } else { |
| | | layer.msg("id为空"); |
| | | return; |
| | | } |
| | | |
| | | public long count(DaoQuery daoQuery){ |
| | | Query query=getQuery(daoQuery); |
| | | return count(query); |
| | | ksapp.postJSON('${detailApi}', {id: id}, function (res) { |
| | | if (res.code == 0) { |
| | | form.data(res.data); |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | }, function (res) { |
| | | layer.msg("详情获取失败"); |
| | | }); |
| | | } |
| | | </script> |
| | | |
| | | <script> |
| | | layui.use(['form', 'layer', 'jquery', 'upload'], function () { |
| | | $ = layui.jquery; |
| | | var form = layui.form, |
| | | layer = layui.layer, |
| | | upload = layui.upload; |
| | | |
| | | var verify = {}; |
| | | <#list regexVerifyList as regex> |
| | | verify["${regex.key}"] = [/${regex.expression}/, '${regex.msg}']; |
| | | </#list> |
| | | //自定义验证规则 |
| | | form.verify(verify); |
| | | |
| | | //渲染上传控件 |
| | | uploadTool.init(upload); |
| | | |
| | | //填充表单数据 |
| | | //请求数据 |
| | | //form.data(); |
| | | |
| | | |
| | | //监听提交 |
| | | form.on('submit(add)', |
| | | function (data) { |
| | | console.log(data.field); |
| | | //转换json对象 |
| | | for (key in data.field) { |
| | | if (key.indexOf(".") > -1) { |
| | | var value = data.field[key]; |
| | | delete data.field[key]; |
| | | var onkeys = key.split("."); |
| | | //创建对象 |
| | | if (data.field[onkeys[0]] == undefined) { |
| | | data.field[onkeys[0]] = {}; |
| | | } |
| | | data.field[onkeys[0]][onkeys[1]] = value; |
| | | } |
| | | } |
| | | uploadTool.upload(function () { |
| | | //发异步,把数据提交给php |
| | | var params = data.field; |
| | | params.id = ksapp.getQueryParam("id"); |
| | | |
| | | ksapp.postJSON('${updateApi}', data.field, function (res) { |
| | | if (res.code == 0) { |
| | | layer.alert("增加成功", { |
| | | icon: 6 |
| | | }, |
| | | function () { |
| | | //关闭当前frame |
| | | xadmin.close(); |
| | | // 可以对父窗口进行刷新 |
| | | // xadmin.father_reload(); |
| | | }); |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | |
| | | 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})); |
| | | }, function (res) { |
| | | }); |
| | | }); |
| | | return false; |
| | | }); |
| | | //请求select的数据API |
| | | |
| | | <#if preRequestList??&&(preRequestList?size>0)> |
| | | var preRequestCount = ${preRequestList?size} |
| | | <#list preRequestList as request> |
| | | <#assign apiKeys=request.params?keys/> |
| | | var params = {}; |
| | | <#list apiKeys as key> |
| | | params["${key}"]=${request.params["${key}"]} |
| | | </#list> |
| | | |
| | | ksapp.postJSON('${request.url}', params, function (res) { |
| | | if (res.code == 0) { |
| | | //填充数据 |
| | | $("${request.fillTarget}").empty(); |
| | | for (var i = 0; i < res.data.length; i++) { |
| | | var html = "<option value='" + res.data[i].key + "'>"; |
| | | html += res.data[i].value + "</option>"; |
| | | $("${request.fillTarget}").append(html); |
| | | } |
| | | if(daoQuery.max${value.columnName?cap_first}!=null){ |
| | | andList.add(Criteria.where("${value.columnName}").lt(daoQuery.max${value.columnName?cap_first})); |
| | | //重新渲染表单 |
| | | form.render(); |
| | | preRequestCount--; |
| | | if (preRequestCount <= 0) { |
| | | //开始填充数据 |
| | | fillData(form) |
| | | } |
| | | |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | |
| | | }, function (res) { |
| | | }); |
| | | </#list> |
| | | <#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})); |
| | | fillData(form) |
| | | </#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; |
| | | } |
| | | }) |
| | | ; |
| | | </script> |
| | | </body> |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | </html> |
New file |
| | |
| | | //查询主键ID是否存在 |
| | | dao.find(if(${entity.name}.getId())) |
| | | |
| | | |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${entityClass}; |
| | | |
| | | |
| | | public interface ${serviceClassName} { |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}); |
| | | |
| | | </#list> |
| | | |
| | | } |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${entityClass}; |
| | | |
| | | |
| | | public interface ${serviceClassName} { |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}); |
| | | |
| | | </#list> |
| | | |
| | | } |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${entityClass}; |
| | | |
| | | |
| | | public interface ${serviceClassName} { |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}); |
| | | |
| | | </#list> |
| | | |
| | | } |
New file |
| | |
| | | if(entity.getUpdateTime()==null){ |
| | | entity.setUpdateTime(new Date()); |
| | | } |
| | | dao.save(entity); |
| | | |
| | | |
New file |
| | |
| | | return dao.selectByPrimaryKey(id); |
| | | |
| | | |
| | | |
New file |
| | |
| | | entity.setUpdateTime(new Date()); |
| | | dao.updateSelective(entity); |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | public class ${className} { |
| | | |
| | | //搜索关键词 |
| | | private String kw; |
| | | |
| | | private String getKw(){ |
| | | return kw; |
| | | } |
| | | |
| | | private void setKw(String kw){ |
| | | this.kw=kw; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${service.clazz}; |
| | | |
| | | |
| | | public interface ${service.name} { |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}); |
| | | |
| | | </#list> |
| | | |
| | | } |
New file |
| | |
| | | package ${packageName}; |
| | | |
| | | import ${entity.clazz}; |
| | | import ${dao.clazz}; |
| | | import ${service.clazz}; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import java.util.Date; |
| | | |
| | | @Service |
| | | public class ${service.name}Impl implements ${service.name}{ |
| | | |
| | | @Resource |
| | | private ${dao.name} ${dao.name?uncap_first}; |
| | | |
| | | <#list metodInfoList as method> |
| | | ${method.note} |
| | | ${method.visiteAccess} ${method.returnType} ${method.name}(${method.params}){ |
| | | ${method.content} |
| | | } |
| | | </#list> |
| | | |
| | | } |
| | |
| | | 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.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 java.io.File; |
| | | import java.io.InputStream; |
| | |
| | | "admin/form/switch.ftl", |
| | | "admin/form/text.ftl", |
| | | "admin/form/textArea.ftl", |
| | | "admin/add.ftl" |
| | | "admin/add.ftl", |
| | | "admin/update.ftl", |
| | | "admin/list.ftl" |
| | | }; |
| | | |
| | | Map<String, InputStream> map = new HashMap<>(); |
| | | for (String st : template) { |
| | | map.put(st, SpringComponentGenerater.class.getClassLoader().getResourceAsStream("generater/" + st)); |
| | | } |
| | | |
| | | String result = FreemarkerUtils.generateInputStream(info, "admin/add.ftl", map); |
| | | 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); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @DaoQueryCondition(queryType = DaoQueryCondition.QueryType.contains) |
| | | @Show(order = 0, title = "昵称") |
| | | @Text(title = "昵称", maxLength = 50, require = true, placeHolder = "请输入昵称", desc = "昵称不能包含特殊字符", verifyType = FormVerifyType.regex, verifyValue = "^.{0-100}$", verifyNotifyMsg = "请输入正确的昵称") |
| | | @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 = "类型") |
| | | @Select(values = {"1:男", "2:女"}, title = "类型") |
| | | private int type; |
| | | |
| | | @DaoQueryCondition |
| | | @Show(order = 2, title = "性别") |
| | | @RadioGroup(values = {"1,男", "2,女"}, title = "性别") |
| | | @RadioGroup(values = {"1:男", "2:女"}, title = "性别") |
| | | private int sex; |
| | | |
| | | @Show(order = 3, title = "头像", showType = Show.ShowType.IMG, imgWidth = 50, imgHeight = 50) |
| | | @Img(width = 50, height = 50, title = "头像") |
| | | @Img(height = 50, title = "头像", uploadApi = "/admin/uploadimg", uploadApiParams = {"id:123123","type:2"}) |
| | | private String portrait; |
| | | |
| | | @DaoQueryCondition |
| | | @Show(order = 4, title = "省") |
| | | @Select(apiPath = "/admin/api/getProvince", title = "省") |
| | | @Select(values = {"cq:重庆","js:江苏"}, title = "省", apiParams = {"page:1", "pageSize:10", "id:\"test\""}) |
| | | private String province; |
| | | |
| | | |