├── .gitignore
├── .idea
├── compiler.xml
├── emacs.xml
├── kotlinc.xml
├── libraries
│ ├── KotlinJavaRuntime.xml
│ └── commons_lang3_3_6.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── MybatisGenerator.iml
├── MybatisGenerator.zip
├── README.md
├── _config.yml
├── lib
├── commons-lang3-3.6.jar
├── kotlin-reflect.jar
├── kotlin-stdlib-jre7-sources.jar
├── kotlin-stdlib-jre7.jar
├── kotlin-stdlib-jre8-sources.jar
├── kotlin-stdlib-jre8.jar
├── kotlin-stdlib-sources.jar
├── kotlin-stdlib.jar
├── kotlin-test.jar
└── mysql-connector-java-5.1.41.jar
└── src
└── main
├── java
└── com
│ └── yangyang
│ └── mybatis
│ └── generator
│ ├── MyConstant.kt
│ ├── actions
│ ├── ActionConfigPath.kt
│ ├── ActionConfigureDB.kt
│ ├── ActionGenerate.kt
│ └── ActionGroupMybatis.kt
│ └── utils
│ ├── NotificationUtil.kt
│ ├── PlatformUtil.kt
│ ├── UIUtil.kt
│ └── mybatis
│ ├── MyBatisGenConst.kt
│ └── MybatisCore.kt
└── resources
├── META-INF
└── plugin.xml
├── icons
├── ic_mybatis.png
└── ic_mybatis@2x.png
└── template
├── base
├── baseCriteria.txt
├── baseQuery.txt
├── criteria.txt
└── pageResult.txt
├── do.txt
├── manager.txt
├── managerImpl.txt
├── mapper-ext.txt
├── mapper.txt
├── query.txt
├── sqlmap-ext.txt
└── sqlmap.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings/
4 | .git/
5 |
6 | # Mac
7 | .DS_Store
8 | # Maven
9 | log/
10 | target/
11 |
12 | #Intellij
13 | out/
14 | .idea/workspace.xml
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/emacs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/libraries/KotlinJavaRuntime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/libraries/commons_lang3_3_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | sIsMHCStaff
77 | 卖好车
78 | MHC_STAFF
79 | baseQuery.txt
80 | sqlmapOutFile
81 | doOutFilePath
82 | doResult
83 | doOutFile
84 | className
85 | sqlmapResult
86 | .do
87 | /do
88 | 不替换旧文件
89 | cri
90 | BaseCriteria
91 | Criterion
92 | b2b
93 | pref
94 | getClassName
95 | managerPackagePath
96 | getclass
97 | do..
98 | do
99 | getColInfoList
100 | pks
101 | getSqlmapParamList
102 | doTemplate
103 | doresult
104 | merge
105 | VP_LIST
106 |
107 |
108 | 152
109 | param
110 | )
111 | sDaoPackageDir
112 | baseCriteria
113 | baseQuery
114 |
115 |
116 |
117 |
118 |
119 |
120 |
123 |
124 |
125 |
160 |
161 |
162 |
163 |
164 | true
165 |
166 | false
167 | true
168 | true
169 |
170 |
171 | true
172 | DEFINITION_ORDER
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 | ActionScript specificJavaScript
195 |
196 |
197 | Android > Lint > Lint
198 |
199 |
200 | Batch Applications Issues
201 |
202 |
203 | Flow type checkerJavaScript
204 |
205 |
206 | GeneralJavaScript
207 |
208 |
209 | Groovy
210 |
211 |
212 | HTML
213 |
214 |
215 | J2ME issuesJava
216 |
217 |
218 | Java
219 |
220 |
221 | JavaFX
222 |
223 |
224 | JavaScript
225 |
226 |
227 | OtherGroovy
228 |
229 |
230 | Portability issuesJava
231 |
232 |
233 | Spring
234 |
235 |
236 | Spring CoreSpring
237 |
238 |
239 | Struts
240 |
241 |
242 | Struts 1Struts
243 |
244 |
245 | TypeScript
246 |
247 |
248 | Web Services
249 |
250 |
251 | XML
252 |
253 |
254 | XMLSpring CoreSpring
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 | project
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 | 1505272011117
823 |
824 |
825 | 1505272011117
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 | file://$PROJECT_DIR$/src/main/java/com/yangyang/mybatis/generator/actions/ActionGenerate.kt
1016 | 34
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 |
1038 |
1039 |
1040 |
1041 |
1042 |
1043 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 |
1074 |
1075 |
1076 |
1077 |
1078 |
1079 |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 |
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 |
1171 |
1172 |
1173 |
1174 |
1175 |
1176 |
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
1194 |
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 |
1203 |
1204 |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 |
1211 |
1212 |
1213 |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1221 |
1222 |
1223 |
1224 |
1225 |
1226 |
1227 |
1228 |
1229 |
1230 |
1231 |
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 |
1239 |
1240 |
1241 |
1242 |
1243 |
1244 |
1245 |
1246 |
1247 |
1248 |
1249 |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 |
1266 |
1267 |
1268 |
1269 |
1270 |
1271 |
1272 |
1273 |
1274 |
1275 |
1276 |
1277 |
1278 |
1279 |
1280 |
1281 |
1282 |
1283 |
1284 |
1285 |
1286 |
1287 |
1288 |
1289 |
1290 |
1291 |
1292 |
1293 |
1294 |
1295 |
1296 |
1297 |
1298 |
1299 |
1300 |
1301 |
1302 |
1303 |
1304 |
1305 |
1306 |
1307 |
1308 |
1309 |
1310 |
1311 |
1312 |
1313 |
1314 |
1315 |
1316 |
1317 |
1318 |
1319 |
1320 |
1321 |
1322 |
1323 |
1324 |
1325 |
1326 |
1327 |
1328 |
1329 |
1330 |
1331 |
1332 |
1333 |
1334 |
1335 |
1336 |
1337 |
1338 |
1339 | Detection
1340 |
1341 |
1342 |
1343 |
1344 |
1345 |
1346 |
1347 |
1348 |
1349 |
1350 |
1351 |
1352 |
1353 |
1354 |
1355 |
1356 |
1357 |
1358 |
1359 |
1360 |
1361 |
1362 | IntelliJ IDEA IU-171.4694.23
1363 |
1364 |
1365 |
1366 |
1367 |
1368 |
1369 |
1370 |
1371 |
1372 |
1373 |
1374 | MybatisGenerator
1375 |
1376 |
1377 |
1378 |
1379 |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 |
1386 |
1387 | commons-lang3-3.6
1388 |
1389 |
1390 |
1391 |
1392 |
1393 |
1394 |
1395 |
1396 |
1397 |
1398 |
1399 |
--------------------------------------------------------------------------------
/MybatisGenerator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/MybatisGenerator.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/MybatisGenerator.zip
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MyBatisGeneratorPlugin
2 | #### *MaiHaoChe*
3 | 
4 |
5 | ### 需求
6 | 现在团队内部有一套代码,能够根据数据库表结构直接生成一系列对象,实现基本的增删改查API,便于直接在业务逻辑中使用。这套代码目前处于游离状态(哪里需要复制粘贴到哪里),又不便于组织成jar包,作为各个项目的依赖(因为这是一套工具代码,与项目无关),这样非常不便于维护升级。
7 | Intellij Idea 插件是最适合实现这种工具需求。既便于团队内共享,又便于统一管理并维护升级。
8 |
9 | ### 使用
10 | * 安装:在IntelliJ 的插件安装页面点击"Browse reposities...",在弹窗中搜索"mybatisgenerator"
11 |
12 |
13 |
14 |
15 | * 入口:安装并重启后,在菜单栏Tools下可以看到插件的功能入口
16 |
17 |
18 |
19 |
20 | * 配置:需要配置用于连接到目标数据库的链接,用户名和密码以及生成的各个java类和xml文件的路径。卖好车内部使用,请在"是否用于卖好车内部代码"出选择"是。
21 |
22 | * 生成mybatis代码:输入表名,点击确定,生成该表的mybatis代码。
23 |
24 | ### 实现
25 | ##### 配置流程
26 |
27 | 1. 配置数据库连接链接,用户名,密码,配置生成代码的目录路径;
28 |
29 | 2. 插件连接到数据库,获取表结构信息(不获取表内容信息);
30 |
31 | 3. 通过Velocity ,将预先定义好的模板于数据库信息结合,生成类文件,写入目标路径中。
32 |
33 | ##### API
34 | * 实体
35 | DO,Query,Mapper,Manager, Mapper.xml。前缀为:表名(驼峰),比如表table_user,生成的实体分别为:TableUserDO,TableUserQuery,TableUserMapper,TableUserManager 和 TableUserMapper.xml。
36 | > * DO 表对象,每个字段代表一个列
37 | > * Query 查询对象,用于添加各类查询条件
38 | > * Mapper mybatis 需要的mapper的接口
39 | > * Manager 对外输出的API,包含了基本的增删改查
40 | > * Mapper.xml mybatis的mapper文件,sql的具体实现
41 |
42 | * 拓展
43 | 每个对象都可以创建一个子对象,包含在同级目录的ext子目录下。具体的实现可以自定义。
44 |
45 | * CodeExample
46 | ```
47 | public class example {
48 |
49 | @Autowired
50 | private UserManager userManager;
51 |
52 | public void findUser() {
53 | //select DO by id
54 | long userId = 1;
55 | UserDO userDOById = userManager.selectByPrimaryKey(userId);
56 |
57 | //select DO by query
58 | UserQuery userQuery = new UserQuery();
59 | userQuery.createCriteria()
60 | .andUserNameLike("JonSnow%");
61 | List userListResult = userManager.selectByQuery(userQuery);
62 |
63 | //select DO by page
64 | UserQuery pageQuery = new UserQuery();
65 | pageQuery.setPageNo(1);
66 | pageQuery.setPageSize(20);
67 | pageQuery.createCriteria()
68 | .andUserNameLike("JonSnow%");
69 | PageResult userPageResult = userManager.selectByQueryWithPage(pageQuery);
70 | }
71 | }
72 | ```
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-slate
--------------------------------------------------------------------------------
/lib/commons-lang3-3.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/commons-lang3-3.6.jar
--------------------------------------------------------------------------------
/lib/kotlin-reflect.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-reflect.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib-jre7-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib-jre7-sources.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib-jre7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib-jre7.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib-jre8-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib-jre8-sources.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib-jre8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib-jre8.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib-sources.jar
--------------------------------------------------------------------------------
/lib/kotlin-stdlib.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-stdlib.jar
--------------------------------------------------------------------------------
/lib/kotlin-test.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/kotlin-test.jar
--------------------------------------------------------------------------------
/lib/mysql-connector-java-5.1.41.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maihaoche/mybatis-generator-plugin/f9255ade46443574766a6a212f7692f100cb8f48/lib/mysql-connector-java-5.1.41.jar
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/MyConstant.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator
2 |
3 | /**
4 | * 类简介:项目的常量。存储一些配置数据的信息
5 | * 作者: yang
6 | * 时间: 17/7/24
7 | * 邮箱: yangyang1@maihaoche.com
8 | */
9 | class MyConstant {
10 |
11 | companion object {
12 | // -------------------------配置数据库连接的key-------------------------
13 | val DB_CONF_INITED = "db_conf_inited"//mysql是否初始化
14 | val DB_URL = "db_url"//数据库的url
15 | val DB_USER = "db_user"//数据库的用户名
16 | val DB_PW = "db_pw"//数据库的密码
17 | // -------------------------生成数据的一些路径的配置key-------------------------
18 | val DAO_MODULE = "dao_module"//dao的目录
19 | val DAO_PACKAGE = "dao_package"//dao的package名
20 | val MANAGER_MODULE = "namager_module"//manager所在的目录
21 | val MANAGER_PACKAGE = "manager_package"//manager生成目录
22 | val TABLE_PREFIX = "table_prefix"//表名的前缀
23 | val MHC_STAFF = "mhc_staff"//是否生成卖好车内部的代码
24 |
25 | //-------------------------内部字段-------------------------
26 | val TABLE_HISTORY = "table_history"//保存历史选中的表名。
27 |
28 | //-------------------------action的一些路径-------------------
29 |
30 | val ACTION_TOOLS_MENU = "ToolsMenu"
31 | val ACTION_MYBATIS = "Mybatis"
32 | val ACTION_MYBATIS_PATH_CONFIGURE = "配置路径"
33 | val ACTION_MYBATIS_DB_CONFIGURE = "配置数据库"
34 |
35 |
36 | }
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/actions/ActionConfigPath.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.actions
2 |
3 | import com.intellij.openapi.actionSystem.AnAction
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil
6 | import com.intellij.ui.CheckBoxList
7 | import com.intellij.ui.IdeBorderFactory
8 | import com.intellij.ui.components.CheckBox
9 | import main.java.com.yangyang.mybatis.generator.MyConstant
10 | import main.java.com.yangyang.mybatis.generator.utils.NotificationUtil
11 | import main.java.com.yangyang.mybatis.generator.utils.PlatformUtil
12 | import main.java.com.yangyang.mybatis.generator.utils.UIUtil
13 | import main.java.com.yangyang.mybatis.generator.utils.mybatis.MyBatisGenConst
14 | import java.awt.GridBagLayout
15 | import java.util.*
16 | import javax.swing.*
17 |
18 |
19 | /**
20 | * 类简介:配置的动作
21 | * 作者: yang
22 | * 时间: 17/7/24
23 | * 邮箱: yangyang1@maihaoche.com
24 | */
25 | class ActionConfigPath : AnAction() {
26 | /**
27 | * 执行相关的动作
28 | */
29 | override fun actionPerformed(event: AnActionEvent?) {
30 | if (event == null) {
31 | return
32 | }
33 | val project = event.getProject()
34 |
35 | val content = JPanel(GridBagLayout())
36 |
37 | val daoModule = UIUtil.addTextInputToPanel("DO,Query,Mapper所在的module名: ", MyConstant.DAO_MODULE, content)
38 | val daoPackagePath = UIUtil.addTextInputToPanel("DO,Query,Mapper所在的package名: ", MyConstant.DAO_PACKAGE, content)
39 | val managerModule = UIUtil.addTextInputToPanel("Manager所在的module名: ", MyConstant.MANAGER_MODULE, content)
40 | val managerPackagePath = UIUtil.addTextInputToPanel("Manager所在的package: ", MyConstant.MANAGER_PACKAGE, content)
41 | val tablePrefix = UIUtil.addTextInputToPanel("表名的前缀: ", MyConstant.TABLE_PREFIX, content)
42 | content.add(JLabel("是否用于卖好车内部代码: "), ExternalSystemUiUtil.getFillLineConstraints(0))
43 | // 卖好车内部圆通的选择
44 | val isMHCStaffCheck = CheckBoxList()
45 | isMHCStaffCheck.setItems(Arrays.asList("是"), null)
46 | isMHCStaffCheck.border = IdeBorderFactory.createEmptyBorder(8)
47 | content.add(isMHCStaffCheck, ExternalSystemUiUtil.getFillLineConstraints(0))
48 | if (PlatformUtil.getData(MyConstant.MHC_STAFF, false)) {
49 | isMHCStaffCheck.setItemSelected("是", true)
50 | }
51 | //清空缓存
52 | val clearCacheBtn = JButton("清除缓存")
53 | clearCacheBtn.addActionListener {
54 | PlatformUtil.setData(MyConstant.DAO_MODULE, "")
55 | PlatformUtil.setData(MyConstant.DAO_PACKAGE, "")
56 | PlatformUtil.setData(MyConstant.MANAGER_MODULE, "")
57 | PlatformUtil.setData(MyConstant.MANAGER_PACKAGE, "")
58 | isMHCStaffCheck.clearSelection()
59 | MyBatisGenConst.clearConfig()
60 | NotificationUtil.info("清除缓存成功", project)
61 | daoModule.text = ""
62 | daoPackagePath.text = ""
63 | managerModule.text = ""
64 | managerPackagePath.text = ""
65 | tablePrefix.text = ""
66 | }
67 | clearCacheBtn.border = IdeBorderFactory.createEmptyBorder(14, 4, 4, 4)
68 | content.add(clearCacheBtn, ExternalSystemUiUtil.getLabelConstraints(0))
69 | //显示dialog
70 | content.border = IdeBorderFactory.createEmptyBorder(0, 0, 8, 0)
71 |
72 | UIUtil.showDialog("路径配置参数", project, content, {
73 | if (it) {
74 | if (daoPackagePath.text.trim().isNullOrBlank()
75 | || managerModule.text.trim().isNullOrBlank()
76 | || managerPackagePath.text.trim().isNullOrBlank()
77 | ) {
78 | NotificationUtil.popError("路径配置不能为空", event)
79 | return@showDialog
80 | }
81 | PlatformUtil.setData(MyConstant.DAO_MODULE, daoModule.text)
82 | PlatformUtil.setData(MyConstant.DAO_PACKAGE, daoPackagePath.text)
83 | PlatformUtil.setData(MyConstant.MANAGER_MODULE, managerModule.text)
84 | PlatformUtil.setData(MyConstant.MANAGER_PACKAGE, managerPackagePath.text)
85 | PlatformUtil.setData(MyConstant.TABLE_PREFIX, tablePrefix.text)
86 | val isMHCStaff = isMHCStaffCheck.isItemSelected("是")
87 | PlatformUtil.setData(MyConstant.MHC_STAFF, isMHCStaff)
88 |
89 | MyBatisGenConst.setConfig(
90 | daoModule.text,
91 | daoPackagePath.text,
92 | managerModule.text,
93 | managerPackagePath.text,
94 | tablePrefix.text,
95 | isMHCStaff,
96 | project)
97 | NotificationUtil.popInfo("路径配置修改成功", event)
98 | }
99 | })
100 | }
101 |
102 | companion object {
103 | /**
104 | * 显示配置窗口
105 | */
106 | fun showConfigureDialog(msg: String, event: AnActionEvent) {
107 | //总的内容
108 | val content = JPanel(GridBagLayout())
109 | //设置切换为全module任务名
110 | content.add(JLabel(msg), ExternalSystemUiUtil.getFillLineConstraints(0))
111 |
112 | UIUtil.showDialog("错误提示", event.project, content, {
113 | if (it) {
114 | PlatformUtil.performActionWithPath(event, MyConstant.ACTION_TOOLS_MENU, MyConstant.ACTION_MYBATIS, MyConstant.ACTION_MYBATIS_PATH_CONFIGURE)
115 | }
116 | })
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/actions/ActionConfigureDB.kt:
--------------------------------------------------------------------------------
1 | package com.yangyang.mybatis.generator.actions
2 |
3 | import com.intellij.openapi.actionSystem.AnAction
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil
6 | import com.intellij.ui.IdeBorderFactory
7 | import main.java.com.yangyang.mybatis.generator.MyConstant
8 | import main.java.com.yangyang.mybatis.generator.utils.NotificationUtil
9 | import main.java.com.yangyang.mybatis.generator.utils.PlatformUtil
10 | import main.java.com.yangyang.mybatis.generator.utils.UIUtil
11 | import java.awt.GridBagLayout
12 | import javax.swing.JButton
13 | import javax.swing.JLabel
14 | import javax.swing.JPanel
15 |
16 | /**
17 | * 类简介:配置mysql的action
18 | * 作者: yang
19 | * 时间: 17/7/26
20 | * 邮箱: yangyang1@maihaoche.com
21 | */
22 | class ActionConfigureDB : AnAction() {
23 | override fun actionPerformed(event: AnActionEvent?) {
24 | if (event == null) {
25 | return
26 | }
27 | val project = event.getProject()
28 | //总的内容
29 | val content = JPanel(GridBagLayout())
30 | content.add(JLabel("该版本仅支持mysql的驱动(com.mysql.jdbc.Driver): "), ExternalSystemUiUtil.getFillLineConstraints(0))
31 |
32 | val urlInput = UIUtil.addTextInputToPanel("请输入数据库链接的URL: ", MyConstant.DB_URL, content)
33 | val userNameInput = UIUtil.addTextInputToPanel("请输入用户名: ", MyConstant.DB_USER, content)
34 | val passwordInput = UIUtil.addTextInputToPanel("请输入密码: ", MyConstant.DB_PW, content)
35 |
36 | //清空缓存
37 | val clearCacheBtn = JButton("清除缓存")
38 | clearCacheBtn.addActionListener {
39 | PlatformUtil.setData(MyConstant.DB_URL, "")
40 | PlatformUtil.setData(MyConstant.DB_USER, "")
41 | PlatformUtil.setData(MyConstant.DB_PW, "")
42 | PlatformUtil.setData(MyConstant.DB_CONF_INITED, false)
43 | NotificationUtil.info("清除缓存成功", project)
44 | urlInput.text = ""
45 | userNameInput.text = ""
46 | passwordInput.text = ""
47 | }
48 | clearCacheBtn.border = IdeBorderFactory.createEmptyBorder(14, 4, 4, 4)
49 | content.add(clearCacheBtn, ExternalSystemUiUtil.getLabelConstraints(0))
50 | //显示dialog
51 | content.border = IdeBorderFactory.createEmptyBorder(0, 0, 8, 0)
52 |
53 | UIUtil.showDialog("数据库配置参数", project, content, {
54 | if (it) {
55 | if (urlInput.text.trim().isNullOrBlank()
56 | || userNameInput.text.trim().isNullOrBlank()
57 | || passwordInput.text.trim().isNullOrBlank()
58 | ) {
59 | NotificationUtil.popInfo("配置不能为空", event)
60 | return@showDialog
61 | }
62 | PlatformUtil.setData(MyConstant.DB_URL, urlInput.text)
63 | PlatformUtil.setData(MyConstant.DB_USER, userNameInput.text)
64 | PlatformUtil.setData(MyConstant.DB_PW, passwordInput.text)
65 | PlatformUtil.setData(MyConstant.DB_CONF_INITED, true)
66 | NotificationUtil.popInfo("数据库配置修改成功", event)
67 | }
68 | })
69 | }
70 | companion object {
71 | /**
72 | * 显示配置窗口
73 | */
74 | fun showConfigureDialog(msg: String, event: AnActionEvent) {
75 | //总的内容
76 | val content = JPanel(GridBagLayout())
77 | //设置切换为全module任务名
78 | content.add(JLabel(msg), ExternalSystemUiUtil.getFillLineConstraints(0))
79 |
80 | UIUtil.showDialog("错误提示", event.project, content, {
81 | if (it) {
82 | PlatformUtil.performActionWithPath(event, MyConstant.ACTION_TOOLS_MENU, MyConstant.ACTION_MYBATIS, MyConstant.ACTION_MYBATIS_DB_CONFIGURE)
83 | }
84 | })
85 | }
86 | }
87 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/actions/ActionGenerate.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.actions
2 |
3 | import com.intellij.openapi.actionSystem.AnAction
4 | import com.intellij.openapi.actionSystem.AnActionEvent
5 | import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil
6 | import com.intellij.openapi.progress.ProgressIndicator
7 | import com.intellij.openapi.progress.Task
8 | import com.intellij.openapi.progress.util.ProgressIndicatorUtils
9 | import com.intellij.ui.CheckBoxList
10 | import com.intellij.ui.IdeBorderFactory
11 | import com.intellij.util.containers.isNullOrEmpty
12 | import com.yangyang.mybatis.generator.actions.ActionConfigureDB
13 | import main.java.com.yangyang.mybatis.generator.MyConstant
14 | import main.java.com.yangyang.mybatis.generator.utils.NotificationUtil
15 | import main.java.com.yangyang.mybatis.generator.utils.PlatformUtil
16 | import main.java.com.yangyang.mybatis.generator.utils.UIUtil
17 | import main.java.com.yangyang.mybatis.generator.utils.mybatis.MyBatisGenConst
18 | import main.java.com.yangyang.mybatis.generator.utils.mybatis.MybatisCore
19 | import java.awt.GridBagLayout
20 | import javax.swing.JButton
21 | import javax.swing.JLabel
22 | import javax.swing.JPanel
23 | import javax.swing.ListSelectionModel
24 |
25 | /**
26 | * 类简介:产生模板代码的动作
27 | * 作者: yang
28 | * 时间: 17/7/24
29 | * 邮箱: yangyang1@maihaoche.com
30 | */
31 | class ActionGenerate : AnAction() {
32 |
33 |
34 | override fun actionPerformed(event: AnActionEvent?) {
35 | if (event == null) {
36 | return
37 | }
38 | val project = event.project
39 | if (project == null) {
40 | return
41 | }
42 |
43 | if (!MyBatisGenConst.initConfig(project)) {
44 | ActionConfigPath.showConfigureDialog("还没有设置生成代码路径,是否现在去设置?", event)
45 | return
46 | }
47 | if (!PlatformUtil.getData(MyConstant.DB_CONF_INITED, false)) {
48 | ActionConfigureDB.showConfigureDialog("还没有配置数据库连接,是否现在去设置?", event)
49 | return
50 | }
51 |
52 | val content = JPanel(GridBagLayout())
53 | content.add(JLabel("请输入需要产生代码的表名,以\",\"隔开: "), ExternalSystemUiUtil.getFillLineConstraints(0))
54 |
55 | val talbeNameInput = UIUtil.getTextField("")
56 | content.add(talbeNameInput, ExternalSystemUiUtil.getFillLineConstraints(0))
57 |
58 | var tableHistory = PlatformUtil.getDatas(MyConstant.TABLE_HISTORY)?.toList()
59 | val orphanModulesList = CheckBoxList()
60 | if (tableHistory != null && tableHistory.size > 0) {
61 | orphanModulesList.selectionMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
62 | orphanModulesList.setItems(tableHistory) { moduleName -> moduleName }
63 | orphanModulesList.border = IdeBorderFactory.createEmptyBorder(8)
64 | content.add(orphanModulesList, ExternalSystemUiUtil.getFillLineConstraints(0))
65 |
66 | //清空缓存
67 | val clearCacheBtn = JButton("清除缓存")
68 | clearCacheBtn.addActionListener {
69 | content.remove(orphanModulesList)
70 | content.updateUI()
71 | }
72 | clearCacheBtn.border = IdeBorderFactory.createEmptyBorder(14, 4, 4, 4)
73 | content.add(clearCacheBtn, ExternalSystemUiUtil.getLabelConstraints(0))
74 | }
75 | content.border = IdeBorderFactory.createEmptyBorder(0, 0, 8, 0)
76 |
77 | UIUtil.showDialog("请选择表名", project, content,
78 | {
79 | if (it) {
80 | var tableNames = mutableSetOf()
81 | talbeNameInput.text?.split(",")?.let { tableNames.addAll(it.filter { !it.isNullOrBlank() }) }
82 | if (tableHistory != null) {
83 | for (table in tableHistory) {
84 | if (table.isNullOrBlank()) {
85 | continue
86 | }
87 | if (orphanModulesList.isItemSelected(table)) {
88 | tableNames.add(table)
89 | }
90 | }
91 | }
92 | if (tableNames.size == 0) {
93 | return@showDialog
94 | }
95 | PlatformUtil.setDatas(MyConstant.TABLE_HISTORY, tableNames.toTypedArray())
96 | PlatformUtil.executeBackgroundTask(project
97 | , "正在生成代码"
98 | , Runnable {
99 | var exception = MybatisCore.batchGen(tableNames.toList(), project)
100 | if (exception == null) {
101 | NotificationUtil.popInfo("生成代码成功,详情见EventLog控制台输出", event)
102 | } else {
103 | NotificationUtil.popError("生成代码出错,详情见EventLog控制台输出", event)
104 | NotificationUtil.error("生成代码出错exception:" + exception )
105 | }
106 | PlatformUtil.notifyFileChanged(project)
107 | })
108 |
109 | }
110 | })
111 | }
112 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/actions/ActionGroupMybatis.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.actions
2 |
3 | import com.intellij.openapi.actionSystem.DefaultActionGroup
4 |
5 | /**
6 | * 类简介:
7 | * 作者: yang
8 | * 时间: 17/7/24
9 | * 邮箱: yangyang1@maihaoche.com
10 | */
11 | class ActionGroupMybatis : DefaultActionGroup()
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/utils/NotificationUtil.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.utils
2 |
3 | import com.intellij.notification.NotificationDisplayType
4 | import com.intellij.notification.NotificationGroup
5 | import com.intellij.notification.NotificationType
6 | import com.intellij.notification.Notifications
7 | import com.intellij.openapi.actionSystem.AnActionEvent
8 | import com.intellij.openapi.actionSystem.DataKeys
9 | import com.intellij.openapi.diagnostic.Logger
10 | import com.intellij.openapi.project.Project
11 | import com.intellij.openapi.ui.MessageType
12 | import com.intellij.openapi.ui.popup.Balloon
13 | import com.intellij.openapi.ui.popup.JBPopupFactory
14 | import com.intellij.openapi.wm.WindowManager
15 | import com.intellij.ui.awt.RelativePoint
16 |
17 | /**
18 | * 类简介:
19 | * 作者: yang
20 | * 时间: 17/7/24
21 | * 邮箱: yangyang1@maihaoche.com
22 | */
23 | class NotificationUtil private constructor(){
24 |
25 | companion object {
26 | private val sPLUGIN_LOGGER = Logger.getInstance(NotificationUtil::class.java)
27 | private val GROUP_DISPLAY_ID_INFO_BALLOON = NotificationGroup("main.java.com.yangyang.mybatis.generator",
28 | NotificationDisplayType.BALLOON, true)
29 |
30 | private val LOGGING_NOTIFICATION = NotificationGroup("Gradle sync", NotificationDisplayType.NONE, true)
31 |
32 | /**
33 | * IntelliJ自带的API输出的info,android studio 会显示在底部statusbar下面。
34 |
35 | * @param info
36 | */
37 | fun infoToStatusBar(info: String) {
38 | sPLUGIN_LOGGER.info(info)
39 | }
40 |
41 | /**
42 | * 显示在gradle 的consol中的info
43 |
44 | * @param infoMsg
45 | * *
46 | * @param project
47 | */
48 | fun info(infoMsg: String?, project: Project?) {
49 | if (infoMsg == null || infoMsg.trim { it <= ' ' } == "" || project == null) {
50 | return
51 | }
52 | LOGGING_NOTIFICATION.createNotification(infoMsg, MessageType.INFO).notify(project)
53 | }
54 | /**
55 | * 控制台,显示错误信息
56 | */
57 | fun error(errorMsg: String?) {
58 | if (errorMsg == null || errorMsg.trim { it <= ' ' } == "") {
59 | return
60 | }
61 | val notificationX = GROUP_DISPLAY_ID_INFO_BALLOON.createNotification(errorMsg, NotificationType.ERROR)
62 | Notifications.Bus.notify(notificationX)
63 | }
64 |
65 | /**
66 | * 严重的错误,需要弹窗提醒。
67 | */
68 | fun popError(errorMsg: String?, event: AnActionEvent) {
69 | pop(errorMsg,event,MessageType.ERROR)
70 | }
71 |
72 | /**
73 | * 弹窗提醒。
74 | */
75 | fun popInfo(info: String?, event: AnActionEvent) {
76 | pop(info,event,MessageType.INFO)
77 | }
78 |
79 | /**
80 | * 弹出信息。
81 | */
82 | private fun pop(msg:String?,event:AnActionEvent,msgType:MessageType){
83 | if (msg == null || msg.trim { it <= ' ' } == "") {
84 | return
85 | }
86 | val statusBar = WindowManager.getInstance()
87 | .getStatusBar(DataKeys.PROJECT.getData(event.dataContext))
88 | JBPopupFactory.getInstance()
89 | .createHtmlTextBalloonBuilder(msg, msgType, null)
90 | .setFadeoutTime(3500)
91 | .createBalloon()
92 | .show(RelativePoint.getCenterOf(statusBar.component),
93 | Balloon.Position.atRight)
94 | }
95 |
96 |
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/utils/PlatformUtil.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.utils
2 |
3 | import com.intellij.ide.util.PropertiesComponent
4 | import com.intellij.openapi.actionSystem.ActionManager
5 | import com.intellij.openapi.actionSystem.AnAction
6 | import com.intellij.openapi.actionSystem.AnActionEvent
7 | import com.intellij.openapi.actionSystem.DefaultActionGroup
8 | import com.intellij.openapi.application.ApplicationManager
9 | import com.intellij.openapi.application.TransactionGuard
10 | import com.intellij.openapi.progress.ProgressIndicator
11 | import com.intellij.openapi.progress.ProgressManager
12 | import com.intellij.openapi.progress.Task
13 | import com.intellij.openapi.progress.util.ProgressIndicatorUtils
14 | import com.intellij.openapi.progress.util.ReadTask
15 | import com.intellij.openapi.project.Project
16 | import com.intellij.openapi.roots.ex.ProjectRootManagerEx
17 | import com.intellij.openapi.vfs.LocalFileSystem
18 | import com.intellij.openapi.vfs.VirtualFile
19 | import com.intellij.openapi.vfs.VirtualFileManager
20 | import com.intellij.openapi.vfs.newvfs.RefreshQueue
21 | import com.intellij.util.ui.UIUtil
22 | import javax.swing.SwingUtilities
23 |
24 | /**
25 | * 类简介:
26 | * 作者: yang
27 | * 时间: 17/7/24
28 | * 邮箱: yangyang1@maihaoche.com
29 | */
30 | class PlatformUtil {
31 | companion object {
32 |
33 | /**
34 | * 在异步线程池中执行任务,真正的异步任务。不会阻塞主线程
35 | */
36 | fun executeBackgroundTask(project: Project,title: String, runnable: Runnable) {
37 | ApplicationManager.getApplication().invokeLater({
38 | ApplicationManager.getApplication().runReadAction({
39 | object : Task.Backgroundable(project,title) {
40 | override fun run(progressIndicator: ProgressIndicator) {
41 | ProgressIndicatorUtils.runWithWriteActionPriority({
42 | runnable.run()
43 | if (!progressIndicator.isCanceled) {
44 | progressIndicator.stop()
45 | }
46 | }, progressIndicator)
47 | }
48 | override fun shouldStartInBackground(): Boolean {
49 | return true
50 | }
51 | }.queue()
52 | })
53 | })
54 | }
55 |
56 | /**
57 | * 通知文件发生变化
58 | */
59 | fun notifyFileChanged(project: Project) {
60 | project?.getBaseDir()?.refresh(true, true);
61 | }
62 |
63 | /**
64 | * 涉及到Project修改的操作。在主线程执行某个耗时任务,需要调用invokeAndWaitIfNeeded
65 | * 注意,该方法执行的任务会阻塞主线程!
66 | */
67 | fun executeProjectChanges(project: Project, changes: Runnable) {
68 | UIUtil.invokeAndWaitIfNeeded(Runnable {
69 | //在UI主线程执行任务。执行耗时的任务
70 | //官方文档:http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/general_threading_rules.html
71 | //总结:文件修改,涉及project module的修改,等操作都需要用该API来run.
72 | ApplicationManager.getApplication().runWriteAction() {
73 | if (!project.isDisposed) {
74 | ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(changes)
75 | }
76 | }
77 | })
78 | }
79 |
80 |
81 | /**
82 | * 获取本地存储的key value ,string类型
83 | */
84 | fun getData(key: String, defaultValue: String): String {
85 | return PropertiesComponent.getInstance().getValue(key, defaultValue)
86 | }
87 |
88 | /**
89 | * 获取本地存储的key value ,string类型
90 | */
91 | fun getData(key: String, defaultValue: Boolean): Boolean {
92 | return PropertiesComponent.getInstance().getBoolean(key, defaultValue)
93 | }
94 |
95 |
96 | /**
97 | * 数组数据
98 | */
99 | fun getDatas(key: String): Array? {
100 | return PropertiesComponent.getInstance().getValues(key)
101 | }
102 |
103 | /**
104 | * 存储key value数据,string[]类型
105 | */
106 | fun setDatas(key: String, setValue: Array?) {
107 | PropertiesComponent.getInstance().setValues(key, setValue)
108 | }
109 |
110 | /**
111 | * 存储key value数据,string类型
112 | */
113 | fun setData(key: String, stringValue: String) {
114 | PropertiesComponent.getInstance().setValue(key, stringValue)
115 | }
116 |
117 | /**
118 | * 存储key value数据,boolean类型
119 | */
120 | fun setData(key: String, booleanValue: Boolean) {
121 | PropertiesComponent.getInstance().setValue(key, booleanValue)
122 | }
123 |
124 | /**
125 | * 根据路径,执行某个命令。最多三个层级。既:ToolsMenu-->Mybatis-->xxx
126 | */
127 | fun performActionWithPath(event: AnActionEvent, menuName: String?, vararg paths: String) {
128 | if (menuName == null || menuName.isEmpty()) {
129 | return
130 | }
131 | var firstLevelPath: String?
132 | var secondLevelPath = ""
133 | if (paths.size > 0) {
134 | firstLevelPath = paths[0]
135 | //至少有1级深度,切不为空
136 | if (firstLevelPath.isEmpty()) {
137 | NotificationUtil.error("在id为" + menuName + "的菜单栏,paths的第一级路径为空。")
138 | return
139 | }
140 | if (paths.size > 1) {
141 | secondLevelPath = paths[1]
142 | }
143 | } else {
144 | NotificationUtil.error("在id为" + menuName + "的菜单栏,paths为空。")
145 | return
146 | }
147 | val actionManager = ActionManager.getInstance()
148 | val actionGroup = actionManager.getAction(menuName) as DefaultActionGroup
149 | var found = false
150 | val anActions = actionGroup.childActionsOrStubs
151 | if (anActions.size > 0) {
152 | for (i in anActions.indices) {
153 | if (firstLevelPath == anActions[i].templatePresentation.text) {
154 | if (paths.size == 1) {
155 | anActions[i].actionPerformed(event)
156 | return
157 | } else if (secondLevelPath.isEmpty()) {
158 | return
159 | }
160 | var subActions: Array? = null
161 | if (anActions[i] != null && anActions[i] is DefaultActionGroup && anActions[i].templatePresentation.isEnabledAndVisible) {
162 | subActions = (anActions[i] as DefaultActionGroup).childActionsOrStubs
163 | }
164 | if (subActions != null && subActions.size > 0) {
165 | for (j in subActions.indices) {
166 | if (secondLevelPath == subActions[j].templatePresentation.text) {
167 | found = true
168 | subActions[j].actionPerformed(event)
169 | }
170 | }
171 | }
172 | }
173 | }
174 | }
175 | if (!found) {
176 | NotificationUtil.error("在id为" + menuName + "的菜单栏下没有找到Action:" + firstLevelPath + if (secondLevelPath.isEmpty()) "" else "->" + secondLevelPath)
177 | }
178 | }
179 |
180 | }
181 |
182 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/utils/UIUtil.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.utils
2 |
3 | import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil
4 | import com.intellij.openapi.project.Project
5 | import com.intellij.openapi.ui.DialogWrapper
6 | import com.intellij.ui.CheckBoxList
7 | import com.intellij.ui.IdeBorderFactory
8 | import com.intellij.ui.components.JBScrollPane
9 | import java.awt.GridBagLayout
10 | import java.awt.event.ItemEvent
11 | import java.util.ArrayList
12 | import javax.swing.*
13 |
14 | /**
15 | * 类简介:
16 | * 作者: yang
17 | * 时间: 17/7/24
18 | * 邮箱: yangyang1@maihaoche.com
19 | */
20 | class UIUtil {
21 | companion object {
22 | /**
23 | * 显示一个dialog的对话框
24 | */
25 | fun showDialog(titleText:String,project:Project?,content:JComponent, onOkClick:(ok:Boolean)->Unit){
26 | val dialog = object : DialogWrapper(project) {
27 | init {
28 | title = titleText
29 | init()
30 | }
31 |
32 | override fun createCenterPanel(): JComponent? {
33 | return JBScrollPane(content)
34 | }
35 |
36 | override fun createActions(): Array {
37 | return arrayOf(okAction)
38 | }
39 | }
40 | onOkClick.let {
41 | onOkClick(dialog.showAndGet())
42 | }
43 | }
44 | /**在对话框面中
45 | * 添加一个数据框的内容
46 | */
47 | fun addTextInputToPanel(label: String, dataKey: String, panel: JPanel): JTextField {
48 | panel.add(JLabel(label), ExternalSystemUiUtil.getFillLineConstraints(0))
49 | val textField = getTextField(PlatformUtil.getData(dataKey, ""))
50 | panel.add(textField, ExternalSystemUiUtil.getFillLineConstraints(0))
51 | return textField
52 | }
53 |
54 | /**
55 | * 创建一个文本输入框
56 | */
57 | fun getTextField(defaultStr: String): JTextField {
58 | val jTextField = JTextField(defaultStr)
59 | jTextField.border = IdeBorderFactory.createEmptyBorder(4, 4, 4, 4)
60 | return jTextField
61 | }
62 |
63 | /**
64 | * 弹窗选择,单选,则是radiogroup组件。复选,则是checkbox组件
65 |
66 | * @param project
67 | * @param title
68 | * @param datas
69 | * @param singleChoose
70 | * @return
71 | */
72 | private fun chooseFromData(project: Project, title: String, datas: ArrayList, singleChoose: Boolean): ArrayList? {
73 | val mChoosedModuleNames = ArrayList()
74 | //布局
75 | val content = JPanel(GridBagLayout())
76 | content.add(JLabel(title), ExternalSystemUiUtil.getFillLineConstraints(0))
77 | val radioButtons = ArrayList()
78 | val orphanModulesList = CheckBoxList()
79 | if (singleChoose) {
80 | val box = Box.createVerticalBox()
81 | for (i in datas.indices) {
82 | val radioButton = JRadioButton(datas[i])
83 | radioButtons.add(radioButton)
84 | radioButton.addItemListener { e ->
85 | //选中这个,取消其他的选中
86 | if (e.stateChange == ItemEvent.SELECTED) {
87 | for (j in radioButtons.indices) {
88 | if (radioButtons[j] !== radioButton) {
89 | radioButtons[j].isSelected = false
90 | }
91 | }
92 | }
93 | }
94 | box.add(radioButton)
95 | }
96 | box.border = IdeBorderFactory.createEmptyBorder(8)
97 | content.add(box, ExternalSystemUiUtil.getFillLineConstraints(0))
98 | } else {
99 | orphanModulesList.selectionMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
100 | orphanModulesList.setItems(datas) { moduleName -> moduleName }
101 | orphanModulesList.border = IdeBorderFactory.createEmptyBorder(8)
102 | content.add(orphanModulesList, ExternalSystemUiUtil.getFillLineConstraints(0))
103 | }
104 | content.border = IdeBorderFactory.createEmptyBorder(0, 0, 8, 0)
105 |
106 | showDialog("请选择",project,content,{
107 | if (!it) return@showDialog
108 | if (singleChoose) {
109 | for (i in radioButtons.indices) {
110 | if (radioButtons[i].isSelected) {
111 | mChoosedModuleNames.add(radioButtons[i].text)
112 | }
113 | }
114 | } else {
115 | for (i in datas.indices) {
116 | val module = datas[i]
117 | if (orphanModulesList.isItemSelected(i)) {
118 | mChoosedModuleNames.add(module)
119 | }
120 | }
121 | }
122 | })
123 | return mChoosedModuleNames
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/utils/mybatis/MyBatisGenConst.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.utils.mybatis
2 |
3 | import com.intellij.openapi.project.Project
4 | import main.java.com.yangyang.mybatis.generator.MyConstant
5 | import main.java.com.yangyang.mybatis.generator.utils.PlatformUtil
6 | import java.io.File
7 |
8 |
9 | /**
10 | * 类简介:
11 | * 作者: yang
12 | * 时间: 17/7/24
13 | * 邮箱: yangyang1@maihaoche.com
14 | */
15 | class MyBatisGenConst {
16 |
17 | /**
18 | * 伴生对象。companion中的内容,可以通过类直接访问。
19 | */
20 | companion object {
21 | var sConfigured = false
22 | // 包名
23 | var sDaoModule = ""
24 | var sDaoPackage = ""//do,query,mapper,mapper_ext所在的package名
25 | var sManagerModule = ""
26 | var sManagerPackage = ""
27 | var sManagerImplPackage = ""
28 |
29 | var sTablePrefix = ""//表名的前缀
30 |
31 | // 输出目录
32 | var sDaoPackageDir = ""
33 | var sBaseDir = ""//BaseCriteria,BaseQuery,PageResult所在的文件目录
34 | var sMapperXmlDir = ""
35 | var sMapperExtXmlDir = ""
36 | var sDoJavaDir = ""
37 | var sQueryJavaDir = ""
38 | var sMapperJavaDir = ""
39 | var sMapperExtJavaDir = ""
40 | var sManagerJavaDir = ""
41 | var sManagerImplJavaDir = ""
42 |
43 | //是否是mhc内部使用的代码
44 | var sIsMHCStaff = false
45 |
46 | //模板路径
47 | val DO_TEMPLATE = "/template/do.txt"
48 | val QUERY_TEMPLATE = "/template/query.txt"
49 | val SQLMAP_TEMPLATE = "/template/sqlmap.txt"
50 | val MAPPER_TEMPLATE = "/template/mapper.txt"
51 | val MANAGER_TEMPLATE = "/template/manager.txt"
52 | val MANAGER_IMPL_TEMPLATE = "/template/managerImpl.txt"
53 | val MAPPER_EXT_TEMPLATE = "/template/mapper-ext.txt"
54 | val SQLMAP_EXT_TEMPLATE = "/template/sqlmap-ext.txt"
55 |
56 | val PAGERESULT_TEMPLATE = "/template/base/pageResult.txt"
57 | val BASE_CRITERIA_TEMPLATE = "/template/base/baseCriteria.txt"
58 | val CRITERIA_TEMPLATE = "/template/base/criteria.txt"
59 | val BASE_QUERY_TEMPLATE = "/template/base/baseQuery.txt"
60 |
61 |
62 | val QUERY_PREFIX = "Query"
63 | val MAPPER_SUFFIX = "Mapper"
64 | val MANAGER_SUFFIX = "Manager"
65 | val MANAGER_IMPL_SUFFIX = "ManagerImpl"
66 | val MAPPER_EXT_SUFFIX = "ExtMapper"
67 | val DO_SUFFIX = "DO"
68 |
69 | val COMMON_COLUMN_STR = "gmt_create,gmt_modified,"
70 |
71 | // jdbc result set metadata collumn name
72 | val RSMD_COLUMN_NAME = "rsmdColumnName"
73 | val RSMD_COLUMN_CLASS_NAME = "columnClassName"
74 | val RSMD_COLUMN_TYPE_NAME = "columnTypeName"
75 | val RSMD_COLUMN_PRECISION = "Precision"
76 | val RSMD_COLUMN_SCALE = "Scale"
77 | val RSMD_COLUMN_PRIMARY_KEY = "PrimaryKey"
78 | val RSMD_COLUMN_REMARKS = "Remarks"
79 |
80 | val COLUMN_NAME = "COLUMN_NAME"
81 |
82 | // velocity param
83 | val VP_LIST = "list"
84 | val VP_QUERY_PREFIX = "queryPrefix"
85 | val VP_DO_SUFFIX = "doSuffix"
86 | val VP_MAPPER_SUFFIX = "mapperSuffix"
87 | val VP_MANAGER_SUFFIX = "managerSuffix"
88 |
89 | val VP_MANAGER_IMPL_SUFFIX = "managerImplSuffix"
90 | val VP_MAPPER_EXT_SUFFIX = "extMapperSuffix"
91 | val VP_CLASS_NAME = "className"
92 | val VP_MAPPER_PROPERTY_NAME = "mapperPropertyName"
93 | val VP_DAO_PACKAGE = "daoPackage"
94 | val VP_DO_PACKAGE = "doPackage"
95 | val VP_QUERY_PACKAGE = "queryPackage"
96 | val VP_MAPPER_PACKAGE = "mapperPackage"
97 | val VP_MANAGER_PACKAGE = "managerPackage"
98 | val VP_MANAGER_IMPL_PACKAGE = "managerImplPackage"
99 | val VP_MAPPER_EXT_PACKAGE = "mapperExtPackage"
100 | val VP_JAVA_TYPE = "javaType"
101 | val VP_PROP_NAME = "propName"
102 | val VP_GET_METHOD = "getMethod"
103 |
104 | val VP_SET_METHOD = "setMethod"
105 | val VP_COLUMN_NAME = "columnName"
106 | val VP_COLUMN_REMARKS = "columnRemarks"
107 | val VP_TABLE_NAME = "tableName"
108 | val VP_JDBC_TYPE = "jdbcType"
109 | val VP_COLS = "cols"
110 | val VP_COLS_WITHOUT_COMMON_COLUMNS = "colsWithoutCommColumns"
111 | val VP_SERIAL_VERSION_UID = "serialVersionUID"
112 |
113 | val VP_SERIAL_VERSION_UID2 = "serialVersionUID2"
114 | val VP_PRIMARY_KEY = "primaryKey"
115 | val VP_PROP_PRIMARY_KEY = "propPrimaryKey"
116 |
117 | //分库分表 表后缀regex
118 | val SHARDING_SUFFIX_REG = "_[\\d]{4}"
119 |
120 |
121 | fun initConfig(project: Project?): Boolean {
122 | val onNullReturn = {
123 | clearConfig()
124 | sConfigured = false
125 | }
126 |
127 | PlatformUtil.getData(MyConstant.DAO_MODULE, "").let {
128 | if (it.isNullOrBlank()) {
129 | sDaoModule = ""
130 | onNullReturn()
131 | } else {
132 | sDaoModule = it
133 | }
134 | }
135 | PlatformUtil.getData(MyConstant.DAO_PACKAGE, "").let {
136 | if (it.isNullOrBlank()) {
137 | sDaoPackage = ""
138 | onNullReturn()
139 | } else {
140 | sDaoPackage = it
141 | }
142 | }
143 | PlatformUtil.getData(MyConstant.MANAGER_MODULE, "").let {
144 | if (it.isNullOrBlank()) {
145 | sManagerModule = ""
146 | onNullReturn()
147 | } else {
148 | sManagerModule = it
149 | }
150 | }
151 | PlatformUtil.getData(MyConstant.MANAGER_PACKAGE, "").let {
152 | if (it.isNullOrBlank()) {
153 | sManagerPackage = ""
154 | onNullReturn()
155 | } else {
156 | sManagerPackage = it
157 | }
158 | }
159 | PlatformUtil.getData(MyConstant.TABLE_PREFIX, "").let {
160 | if (it.isNullOrBlank()) {
161 | sTablePrefix = ""
162 | onNullReturn()
163 | } else {
164 | sTablePrefix = it
165 | }
166 | }
167 |
168 |
169 | PlatformUtil.getData(MyConstant.MHC_STAFF, false).let {
170 | sIsMHCStaff = it
171 | }
172 | setConfig(sDaoModule,
173 | sDaoPackage,
174 | sManagerModule,
175 | sManagerPackage,
176 | sTablePrefix,
177 | sIsMHCStaff,
178 | project)
179 | return sConfigured
180 | }
181 |
182 | fun setConfig(
183 | daoModule: String,
184 | daoPackage: String,
185 | managerModule: String,
186 | managerPackage: String,
187 | tablePrefix:String,
188 | isMHCStaff: Boolean,
189 | project: Project?
190 | ) {
191 | if (null == project) {
192 | return
193 | }
194 | sIsMHCStaff = isMHCStaff
195 | sDaoModule = daoModule
196 | sDaoPackage = daoPackage
197 | sManagerModule = managerModule
198 | sManagerPackage = managerPackage
199 | sTablePrefix = tablePrefix
200 | sManagerImplPackage = sManagerPackage + ".impl"
201 | sDaoPackageDir = project.baseDir.path + File.separator + sDaoModule
202 | var managerPath = project.baseDir.path + File.separator + sManagerModule
203 | //资源文件路径
204 | sMapperXmlDir = sDaoPackageDir + "/src/main/resources/mapper/"
205 | sMapperExtXmlDir = sDaoPackageDir + "/src/main/resources/mapper/ext/"
206 | //代码文件路径
207 | sBaseDir = sDaoPackageDir + "/src/main/java/" + getFilePathFromPackage(sDaoPackage)
208 | sDoJavaDir = sDaoPackageDir + "/src/main/java/" + getFilePathFromPackage(sDaoPackage) + "/model"
209 | sQueryJavaDir = sDaoPackageDir + "/src/main/java/" + getFilePathFromPackage(sDaoPackage) + "/query"
210 | sMapperJavaDir = sDaoPackageDir + "/src/main/java/" + getFilePathFromPackage(sDaoPackage) + "/mapper"
211 | sMapperExtJavaDir = sDaoPackageDir + "/src/main/java/" + getFilePathFromPackage(sDaoPackage) + "/mapper/ext"
212 | sManagerJavaDir = managerPath + "/src/main/java/" + getFilePathFromPackage(sManagerPackage) + "/manager"
213 | sManagerImplJavaDir = sManagerJavaDir + "/impl"
214 | //
215 |
216 | sConfigured = true
217 | }
218 |
219 | fun getFilePathFromPackage(packageName: String): String {
220 | return packageName.replace(".", "/")
221 | }
222 |
223 | fun clearConfig() {
224 | sIsMHCStaff = false
225 | sDaoModule = ""
226 | sDaoPackage = ""
227 | sManagerModule = ""
228 | sManagerPackage = ""
229 | sManagerImplPackage = ""
230 | sTablePrefix = ""
231 | sMapperXmlDir = ""
232 | sMapperExtXmlDir = ""
233 | sDoJavaDir = ""
234 | sQueryJavaDir = ""
235 | sMapperJavaDir = ""
236 | sManagerJavaDir = ""
237 | sManagerImplJavaDir = ""
238 | sMapperExtJavaDir = ""
239 | sConfigured = false
240 | }
241 |
242 | }
243 | }
--------------------------------------------------------------------------------
/src/main/java/com/yangyang/mybatis/generator/utils/mybatis/MybatisCore.kt:
--------------------------------------------------------------------------------
1 | package main.java.com.yangyang.mybatis.generator.utils.mybatis
2 |
3 | import com.intellij.openapi.project.Project
4 | import main.java.com.yangyang.mybatis.generator.MyConstant
5 | import main.java.com.yangyang.mybatis.generator.utils.NotificationUtil
6 | import main.java.com.yangyang.mybatis.generator.utils.PlatformUtil
7 | import org.apache.commons.lang3.StringUtils
8 | import org.apache.commons.lang3.math.NumberUtils
9 | import org.apache.velocity.VelocityContext
10 | import org.apache.velocity.app.Velocity
11 | import java.io.*
12 | import java.nio.file.Files
13 | import java.nio.file.Paths
14 | import java.sql.*
15 | import java.util.*
16 | import java.util.regex.Pattern
17 | import kotlin.collections.ArrayList
18 |
19 |
20 | /**
21 | * 类简介:mybatis 生成文件的核心工具类
22 | * 作者: yang
23 | * 时间: 17/7/24
24 | * 邮箱: yangyang1@maihaoche.com
25 | */
26 | class MybatisCore {
27 |
28 |
29 | companion object {
30 |
31 | /**
32 | * 批量生成java数据对象类文件和sqlmap文件
33 |
34 | * @param tables 表 多个表用逗号分隔 table1,table2,table3
35 | * *
36 | * @throws Exception 抛出异常
37 | */
38 | fun batchGen(tables: List, project: Project): Exception? {
39 | if (!MyBatisGenConst.sConfigured) {
40 | return Exception("还没有配置参数,请先配置")
41 | }
42 | try {
43 | for (table in tables) {
44 | gen(table.trim { it <= ' ' }, project)
45 | }
46 | } catch (e: Exception) {
47 | return e
48 | }
49 | return null
50 | }
51 |
52 |
53 | /**
54 | * 根据表名获取字段信息
55 |
56 | * @param cn 数据库连接
57 | * *
58 | * @param table 数据库表名
59 | * *
60 | * @return 列infoList
61 | * *
62 | * @throws Exception 抛出错误
63 | */
64 | @Throws(Exception::class)
65 | private fun getColInfoList(cn: Connection, table: String): ArrayList