提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.gen.core.util; |
懒 |
2 |
|
|
3 |
|
|
4 |
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
5 |
import com.baomidou.mybatisplus.generator.config.po.TableField; |
|
6 |
import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
|
7 |
|
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
/** |
|
11 |
* 表信息生成工具 |
|
12 |
* |
|
13 |
* @author fengshuonan |
|
14 |
* @date 2019-01-10-10:54 AM |
|
15 |
*/ |
|
16 |
public class TableInfoUtil { |
|
17 |
|
|
18 |
/** |
|
19 |
* 获取字段拼接在mapping.xml中的最终内容 |
|
20 |
* |
|
21 |
* @author fengshuonan |
|
22 |
* @Date 2019/1/10 10:54 AM |
|
23 |
*/ |
|
24 |
public static String getFieldNames(TableInfo tableInfo) { |
|
25 |
|
|
26 |
String fieldNames; |
|
27 |
List<TableField> fields = tableInfo.getFields(); |
|
28 |
|
|
29 |
StringBuilder names = new StringBuilder(); |
|
30 |
for (int i = 0; i < fields.size(); i++) { |
|
31 |
TableField fd = fields.get(i); |
|
32 |
if (i == fields.size() - 1) { |
|
33 |
names.append(cov2col(fd)); |
|
34 |
} else { |
|
35 |
names.append(cov2col(fd)).append(", "); |
|
36 |
} |
|
37 |
} |
|
38 |
fieldNames = names.toString(); |
|
39 |
|
|
40 |
return fieldNames; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* mapper xml中的字字段添加as |
|
45 |
* |
|
46 |
* @param field 字段实体 |
|
47 |
* @return 转换后的信息 |
|
48 |
*/ |
|
49 |
private static String cov2col(TableField field) { |
|
50 |
|
|
51 |
if (null != field) { |
|
52 |
return field.isConvert() ? field.getName() + " AS \"" + field.getPropertyName() + "\"" : field.getName(); |
|
53 |
} |
|
54 |
|
|
55 |
return StringUtils.EMPTY; |
|
56 |
} |
|
57 |
|
|
58 |
} |