use of com.baomidou.mybatisplus.generator.config.po.TableField in project heifer by galaxy-sea.
the class GeneratorCode method injectionConfig.
private static InjectionConfig injectionConfig(PackageConfig packageInfo, DataSourceConfig dataSourceConfig) {
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
this.setMap(map);
// to do nothing
}
@Override
public void initTableMap(TableInfo tableInfo) {
super.initTableMap(tableInfo);
tableInfo.setComment(pattern.matcher(tableInfo.getComment()).replaceAll(""));
for (TableField field : tableInfo.getFields()) {
if (StringUtils.isNotEmpty(field.getComment())) {
field.setComment(pattern.matcher(field.getComment()).replaceAll(""));
}
}
}
};
String projectPath = System.getProperty("user.dir");
// 如果模板引擎是 freemarker
String templatePath = "generator/templates/mapper.xml.ftl";
// 如果模板引擎是 velocity
// String templatePath = "/templates/mapper.xml.vm";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
if (moduleName == null) {
return projectPath + "/src/main/resources/mapper/" + "" + tableInfo.getXmlName() + "Mapper" + ConstVal.XML_SUFFIX;
}
moduleName = moduleName.replace(".", "/");
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getXmlName() + ConstVal.XML_SUFFIX;
}
});
cfg.setFileOutConfigList(focList);
return cfg;
}
use of com.baomidou.mybatisplus.generator.config.po.TableField in project chao-cloud by chaojunzi.
the class ZipVelocityTemplateEngine method appendTableInfo.
/**
* 添加
* @param tableInfo 表信息
* @param objectMap 模板对象
*/
private void appendTableInfo(TableInfo tableInfo, Map<String, Object> objectMap) {
// 请求路径前缀
objectMap.put("controllerMappingPrefix", tableInfo.getName().replaceFirst("_", "/"));
// shiroPermissionsPrefix
objectMap.put("shiroPermissionsPrefix", tableInfo.getName().replaceFirst("_", ":"));
// 是否存在date 数据类型
boolean hasDate = tableInfo.getFields().stream().anyMatch(f -> DbColumnType.DATE.getType().equals(f.getPropertyType()));
if (hasDate) {
tableInfo.getImportPackages().add("org.springframework.format.annotation.DateTimeFormat");
tableInfo.getImportPackages().add("cn.hutool.core.date.DatePattern");
}
// 版本
objectMap.put("version", EnableMybatisGenerator.VERSION);
// 主键名称类型
TableField pk = tableInfo.getFields().stream().filter(f -> f.isKeyFlag()).findFirst().orElse(null);
objectMap.put("pk", pk);
// 弹窗大小
long i = tableInfo.getFields().stream().filter(f -> !(f.isKeyFlag() || f.getName().equals(getConfigBuilder().getStrategyConfig().getVersionFieldName()))).count();
// 比率
long rate = 30 + (i - 1) * 8;
objectMap.put("openHeight", rate > 100 ? 100 : rate);
// 模糊查询 tableInfo
String comment = tableInfo.getComment();
Map<String, String> map = this.commentToMap(comment);
TableCommentParse parse = BeanUtil.mapToBean(map, TableCommentParse.class, true);
objectMap.put("likeFields", parse.parseLike(tableInfo.getFields()));
// 标题
objectMap.put("menuTitle", parse.getTitle());
// 关键字-保留字处理
Map<String, String> kws = tableInfo.getFields().stream().collect(Collectors.toMap(TableField::getName, t -> KeyWordConstant.contains(t.getName()) ? "`" : ""));
objectMap.put("kws", kws);
if (kws.values().contains("`")) {
tableInfo.getImportPackages().add("com.baomidou.mybatisplus.annotation.TableField");
}
}
use of com.baomidou.mybatisplus.generator.config.po.TableField in project code-generator-maven-plugin by mengweijin.
the class DefaultAutoGenerator method getIdField.
private static IdField getIdField(TableInfo tableInfo) {
TableField tableField = tableInfo.getFields().stream().filter(TableField::isKeyFlag).findFirst().orElse(null);
IdField idField = new IdField();
if (tableField != null) {
idField.setColumnName(tableField.getName());
idField.setPropertyName(tableField.getPropertyName());
idField.setPropertyType(tableField.getColumnType().getType());
}
return idField;
}
Aggregations