mall Day04
mall-learning
mybatis-plus的自动生成配置。
个人配置出来最适合个人的设置
public class Generator {
public static void main(String[] args) {
FastAutoGenerator.create("jdbc:mysql://xxxxx:3306/xxxx",
"用户名", "密码")
.globalConfig(builder -> {
builder.author("zwy") // 设置作者
.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("C:/code/motorman/motorman/src/main/java"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("cn.heypad.motorman.module") // 设置父包名
.moduleName("personnalinformation") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "C:/code/motorman/motorman/src/main/resources/cn.heypad.motorman.module.mapper")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("heypad_motorman_personnal_information") // 设置需要生成的表名
.addTablePrefix(); // 设置过滤表前缀
}).strategyConfig(builder -> {
builder.controllerBuilder()
.enableRestStyle()//开启生成@RestController 控制器
;
}).strategyConfig(builder -> {
builder.serviceBuilder();
}).strategyConfig(builder -> {
builder.mapperBuilder()
.enableMapperAnnotation()//开启 @Mapper 注解
.enableBaseResultMap();// 启用 BaseResultMap 生成
}).strategyConfig(builder -> {
builder.entityBuilder()
.disableSerialVersionUID()//生成 serialVersionUID
.enableChainModel()//开启链式模型
.enableLombok()//开启 lombok 模型
.enableTableFieldAnnotation()// 开启生成实体时生成字段注解
.idType(IdType.ASSIGN_ID)//全局主键雪花算法
;
})
/* .templateConfig(builder -> {
builder.disable(TemplateType.ENTITY)
.entity("/templates/entity.java")
.service("/templates/service.java")
.serviceImpl("/templates/serviceImpl.java")
.mapper("/templates/mapper.java")
.mapperXml("/templates/mapper.xml")
.controller("/templates/controller.java.ftl")
.build();
})*/
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}
###前端回显类
package cn.heypad.motorman.common.utils.api;
import cn.heypad.motorman.common.enums.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @Description: TODO
* @author: zwy
* @date: 2022年01月08日 17:20
*/
@Data
@ApiModel(value="接口返回对象", description="接口返回对象")
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 成功标志
*/
@ApiModelProperty(value = "成功标志")
private boolean success = true;
/**
* 返回处理消息
*/
@ApiModelProperty(value = "返回处理消息")
private String message = "操作成功!";
/**
* 返回代码
*/
@ApiModelProperty(value = "返回代码")
private Integer code = 0;
/**
* 返回数据对象 data
*/
@ApiModelProperty(value = "返回数据对象")
private T result;
/**
* 时间戳
*/
@ApiModelProperty(value = "时间戳")
private long timestamp = System.currentTimeMillis();
public Result() {
}
public Result<T> success(String message) {
this.message = message;
this.code = CommonConstant.SC_OK_200;
this.success = true;
return this;
}
@Deprecated
public static Result<Object> ok() {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage("成功");
return r;
}
@Deprecated
public static Result<Object> ok(String msg) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg);
return r;
}
@Deprecated
public static Result<Object> ok(Object data) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setResult(data);
return r;
}
public static<T> Result<T> OK() {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage("成功");
return r;
}
public static<T> Result<T> OK(T data) {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setResult(data);
return r;
}
public static<T> Result<T> OK(String msg, T data) {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg);
r.setResult(data);
return r;
}
public static Result<Object> error(String msg) {
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
}
public static Result<Object> error(int code, String msg) {
Result<Object> r = new Result<Object>();
r.setCode(code);
r.setMessage(msg);
r.setSuccess(false);
return r;
}
public Result<T> error500(String message) {
this.message = message;
this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
this.success = false;
return this;
}
}