代码生成器样例

v1.4.1
Parker 6 years ago
parent 4977b177c2
commit c973bff5ef

@ -0,0 +1,136 @@
/**
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.web.gentest.carinfo;
import org.opsli.api.base.result.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.opsli.api.wrapper.gentest.carinfo.TestCarModel;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.web.gentest.carinfo
* @Author: Parker
* @CreateTime: 2020-12-20 20:12:57
* @Description: 汽车信息
*
* 对外 API 直接 暴露 @GetMapping 或者 @PostMapping
* 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起
*
* 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的
*
*
*/
public interface TestCarRestApi {
/** 标题 */
String TITLE = "汽车信息";
/**
* 汽车信息 查一条
* @param model 模型
* @return ResultVo
*/
@GetMapping("/get")
ResultVo<TestCarModel> get(TestCarModel model);
/**
* 汽车信息 查询分页
* @param pageNo 当前页
* @param pageSize 每页条数
* @param request request
* @return ResultVo
*/
@GetMapping("/findPage")
ResultVo<?> findPage(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request
);
/**
* 汽车信息 新增
* @param model 模型
* @return ResultVo
*/
@PostMapping("/insert")
ResultVo<?> insert(@RequestBody TestCarModel model);
/**
* 汽车信息 修改
* @param model 模型
* @return ResultVo
*/
@PostMapping("/update")
ResultVo<?> update(@RequestBody TestCarModel model);
/**
* 汽车信息 删除
* @param id ID
* @return ResultVo
*/
@PostMapping("/del")
ResultVo<?> del(String id);
/**
* 汽车信息 批量删除
* @param ids ID 数组
* @return ResultVo
*/
@PostMapping("/delAll")
ResultVo<?> delAll(String[] ids);
/**
* 汽车信息 Excel 导出
*
* 导出时,Token认证和方法权限认证 全部都由自定义完成
* 因为在 导出不成功时,需要推送错误信息,
* 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时
* ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死
* 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段
* response 推送 javascript代码 alert 提示报错信息
*
* @param request request
* @param response response
* @return ResultVo
*/
@GetMapping("/exportExcel")
void exportExcel(HttpServletRequest request, HttpServletResponse response);
/**
* 汽车信息 Excel 导入
* @param request 文件流 request
* @return ResultVo
*/
@PostMapping("/importExcel")
ResultVo<?> importExcel(MultipartHttpServletRequest request);
/**
* 汽车信息 Excel 下载导入模版
* @param response response
* @return ResultVo
*/
@GetMapping("/importExcel/template")
void importTemplate(HttpServletResponse response);
}

@ -0,0 +1,88 @@
/**
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.wrapper.gentest.carinfo;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validation.ValidationArgs;
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
import org.opsli.common.enums.ValiArgsType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.wrapper.gentest.carinfo
* @Author: Parker
* @CreateTime: 2020-12-20 20:12:57
* @Description: 汽车信息
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class TestCarModel extends ApiWrapper {
/** 汽车名称 */
@ApiModelProperty(value = "汽车名称")
@ExcelProperty(value = "汽车名称", order = 1)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
@ValidationArgsLenMax(20)
private String carName;
/** 汽车类型 */
@ApiModelProperty(value = "汽车类型")
@ExcelProperty(value = "汽车类型", order = 2)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
@ValidationArgsLenMax(20)
private String carType;
/** 汽车品牌 */
@ApiModelProperty(value = "汽车品牌")
@ExcelProperty(value = "汽车品牌", order = 3)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_GENERAL_WITH_CHINESE})
@ValidationArgsLenMax(50)
private String carBrand;
/** 生产日期 */
@ApiModelProperty(value = "生产日期")
@ExcelProperty(value = "生产日期", order = 4)
@ExcelInfo
// 验证器
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date produceData;
/** 是否启用 */
@ApiModelProperty(value = "是否启用")
@ExcelProperty(value = "是否启用", order = 5)
@ExcelInfo( dictType = "no_yes" )
// 验证器
@ValidationArgsLenMax(1)
private String izUsable;
}

@ -38,6 +38,9 @@ public class DictWrapper {
/** 字典值 */
private String dictValue;
/** 排序 */
private Integer dictSort;
/** 消息 */
private DictDetailModel model;

@ -0,0 +1,88 @@
/**
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.api.wrapper.testt;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validation.ValidationArgs;
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
import org.opsli.common.enums.ValiArgsType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.api.wrapper.testt
* @Author: parker
* @CreateTime: 2020-12-20 18:27:04
* @Description: 测试3
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class Test3Model extends ApiWrapper {
/** 金钱 */
@ApiModelProperty(value = "金钱")
@ExcelProperty(value = "金钱", order = 1)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_MONEY})
@ValidationArgsLenMax(10)
private Double money;
/** 年龄 */
@ApiModelProperty(value = "年龄")
@ExcelProperty(value = "年龄", order = 2)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_NUMBER})
@ValidationArgsLenMax(3)
private Integer age;
/** 名称 */
@ApiModelProperty(value = "名称")
@ExcelProperty(value = "名称", order = 3)
@ExcelInfo
// 验证器
@ValidationArgs({ValiArgsType.IS_CHINESE})
@ValidationArgsLenMax(50)
private String name;
/** 生日 */
@ApiModelProperty(value = "生日")
@ExcelProperty(value = "生日", order = 4)
@ExcelInfo
// 验证器
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date birth;
/** 是否启用 */
@ApiModelProperty(value = "是否启用")
@ExcelProperty(value = "是否启用", order = 5)
@ExcelInfo( dictType = "no_yes" )
// 验证器
@ValidationArgsLenMax(1)
private String izUsable;
}
Loading…
Cancel
Save