前言
因为工作时间,所以进度会比较慢。
今天晚上抽时间写了一些东西:
首先,优化了我之前写的plus最新代码生成器的工具类,加上了自定义模板。把实体类的Lombok注解从@Setter@Getter变为@Data。
然后,通过代码生成,生成好了用户、菜单、角色的代码。
构建了XpStart的统一响应体以及Http状态码的常量类。
加上了plus的自动填充字段。
新加了一个xpstart-generator模块,用于以后的前后端代码生成(虽然现在还不会)
明天就可以把角色、菜单、部分用户的接口写通了。因为其实大的流程我还没确定好,所以基础的菜单、角色和部分用户接口可以先写。
XpStart:2022.4.7
响应体:
public class ResponseData<T> {
private String msg;
private int code;
private T data;
public ResponseData(String msg) {
this.msg = msg;
}
public ResponseData(String msg, int code) {
this.msg = msg;
this.code = code;
}
public ResponseData(String msg, int code, T data) {
this.msg = msg;
this.code = code;
this.data = data;
}
public ResponseData(int code, T data) {
this.code = code;
this.data = data;
}
public static ResponseData success() {
return new ResponseData("操作成功");
}
public static ResponseData success(String msg, Object data) {
return new ResponseData(msg, HttpStatusConstant.SUCCESS, data);
}
public static ResponseData success(String msg) {
return new ResponseData(msg, HttpStatusConstant.SUCCESS);
}
public static ResponseData success(Object data) {
return new ResponseData(HttpStatusConstant.SUCCESS, data);
}
public static ResponseData error(String msg) {
return new ResponseData(msg, HttpStatusConstant.ERROR);
}
public static ResponseData error(String msg, int code) {
return new ResponseData(msg, code);
}
public static ResponseData error(String msg, Object data) {
return new ResponseData(msg, HttpStatusConstant.ERROR, data);
}
public static ResponseData error(String msg, int code, Object data) {
return new ResponseData(msg, code, data);
}
}
代码生成:
public class GenUtil {
public static void main(String[] args) {
List<String> tables = new ArrayList<>();
tables.add("sys_role");
tables.add("sys_menu");
System.out.println(System.getProperty("user.dir"));
FastAutoGenerator.create("jdbc:mysql://localhost:3306/start","root","111111")
.globalConfig(builder -> {
builder.author("向培")
.outputDir(System.getProperty("user.dir")+"\\xpstart-generator\\src\\main\\java")
.enableSwagger()
.commentDate("yyyy-MM-dd")
.fileOverride();
})
.packageConfig(builder -> {
builder.parent("com.monkeylessey")
.entity("domain.entity")
.service("service")
.serviceImpl("service.impl")
.controller("controller")
.mapper("mapper")
.xml("mapper")
.pathInfo(Collections.singletonMap(OutputFile.xml,System.getProperty("user.dir")+"\\xpstart-generator\\src\\main\\resources\\mapper"));
})
.strategyConfig(builder -> {
builder.addInclude(tables)
.serviceBuilder()
.formatServiceFileName("%sService")
.formatServiceImplFileName("%sServiceImpl")
.entityBuilder()
.enableLombok()
.logicDeleteColumnName("is_deleted")
.enableTableFieldAnnotation()
.controllerBuilder()
.formatFileName("%sController")
.enableRestStyle()
.mapperBuilder()
.enableBaseResultMap()
.superClass(BaseMapper.class)
.formatMapperFileName("%sMapper")
.enableMapperAnnotation()
.formatXmlFileName("%sMapper");
})
.templateConfig(new Consumer<TemplateConfig.Builder>() {
@Override
public void accept(TemplateConfig.Builder builder) {
builder.entity("templates/myentity.java");
}
})
.templateEngine(new FreemarkerTemplateEngine())
.execute();
}
}
字段填充:
@Component
public class XpMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("gmtCreate", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("gmtUpdate", new Date(), metaObject);
}
}
想起来了,我还要把代码生成的实体类的模板改一下,它默认的时间字段的类型是LocalDateTime。好像字段填充时类型不一样填充不了。不知道能不能改。。。
|