傅行帆 преди 6 години
родител
ревизия
db7c8ba6da

+ 20
- 0
SmartCommunity/mybatisGeneratorCode/pom.xml Целия файл

@@ -43,6 +43,26 @@
43 43
 			<scope>runtime</scope>
44 44
 		</dependency>
45 45
 
46
+		<dependency>
47
+			<groupId>com.baomidou</groupId>
48
+			<artifactId>mybatis-plus-boot-starter</artifactId>
49
+			<version>3.0.6</version>
50
+		</dependency>
51
+		<!-- https://mvnrepository.com/artifact/freemarker/freemarker -->
52
+		<dependency>
53
+			<groupId>freemarker</groupId>
54
+			<artifactId>freemarker</artifactId>
55
+			<version>2.3.8</version>
56
+		</dependency>
57
+
58
+		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
59
+		<dependency>
60
+			<groupId>org.projectlombok</groupId>
61
+			<artifactId>lombok</artifactId>
62
+			<version>1.18.2</version>
63
+			<scope>provided</scope>
64
+		</dependency>
65
+
46 66
 		<dependency>
47 67
 			<groupId>org.springframework.boot</groupId>
48 68
 			<artifactId>spring-boot-starter-test</artifactId>

+ 20
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/baomidou/ant/tp/controller/UserController.java Целия файл

@@ -0,0 +1,20 @@
1
+package com.baomidou.ant.tp.controller;
2
+
3
+
4
+import org.springframework.web.bind.annotation.RequestMapping;
5
+
6
+import org.springframework.web.bind.annotation.RestController;
7
+
8
+/**
9
+ * <p>
10
+ * 物业web端用户表 前端控制器
11
+ * </p>
12
+ *
13
+ * @author jobob
14
+ * @since 2018-12-18
15
+ */
16
+@RestController
17
+@RequestMapping("/tp/user")
18
+public class UserController {
19
+
20
+}

+ 87
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/baomidou/ant/tp/entity/User.java Целия файл

@@ -0,0 +1,87 @@
1
+package com.baomidou.ant.tp.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import java.time.LocalDateTime;
5
+import java.io.Serializable;
6
+import lombok.Data;
7
+import lombok.EqualsAndHashCode;
8
+import lombok.experimental.Accessors;
9
+
10
+/**
11
+ * <p>
12
+ * 物业web端用户表
13
+ * </p>
14
+ *
15
+ * @author jobob
16
+ * @since 2018-12-18
17
+ */
18
+@Data
19
+@EqualsAndHashCode(callSuper = false)
20
+@Accessors(chain = true)
21
+@TableName("tp_user")
22
+public class User implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    /**
27
+     * 小区id
28
+     */
29
+    private Integer communityId;
30
+
31
+    /**
32
+     * 用户姓名
33
+     */
34
+    private String userName;
35
+
36
+    /**
37
+     * 登录账号就是手机号确保唯一
38
+     */
39
+    private String loginName;
40
+
41
+    /**
42
+     * 登录密码
43
+     */
44
+    private String loginPassword;
45
+
46
+    /**
47
+     * 1 有效 0 无效(逻辑删除)
48
+     */
49
+    private String status;
50
+
51
+    /**
52
+     * 备注
53
+     */
54
+    private String remark;
55
+
56
+    /**
57
+     * 邮箱
58
+     */
59
+    private String email;
60
+
61
+    /**
62
+     * 头像
63
+     */
64
+    private String headPortrait;
65
+
66
+    /**
67
+     * 创建人
68
+     */
69
+    private Integer createUser;
70
+
71
+    /**
72
+     * 创建时间
73
+     */
74
+    private LocalDateTime createDate;
75
+
76
+    /**
77
+     * 更新人
78
+     */
79
+    private Integer updateUser;
80
+
81
+    /**
82
+     * 更新时间
83
+     */
84
+    private LocalDateTime updateDate;
85
+
86
+
87
+}

+ 16
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/baomidou/ant/tp/mapper/UserMapper.java Целия файл

@@ -0,0 +1,16 @@
1
+package com.baomidou.ant.tp.mapper;
2
+
3
+import com.baomidou.ant.tp.entity.User;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+
6
+/**
7
+ * <p>
8
+ * 物业web端用户表 Mapper 接口
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2018-12-18
13
+ */
14
+public interface UserMapper extends BaseMapper<User> {
15
+
16
+}

+ 16
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/baomidou/ant/tp/service/IUserService.java Целия файл

@@ -0,0 +1,16 @@
1
+package com.baomidou.ant.tp.service;
2
+
3
+import com.baomidou.ant.tp.entity.User;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 物业web端用户表 服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2018-12-18
13
+ */
14
+public interface IUserService extends IService<User> {
15
+
16
+}

+ 20
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/baomidou/ant/tp/service/impl/UserServiceImpl.java Целия файл

@@ -0,0 +1,20 @@
1
+package com.baomidou.ant.tp.service.impl;
2
+
3
+import com.baomidou.ant.tp.entity.User;
4
+import com.baomidou.ant.tp.mapper.UserMapper;
5
+import com.baomidou.ant.tp.service.IUserService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 物业web端用户表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2018-12-18
16
+ */
17
+@Service
18
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
19
+
20
+}

+ 129
- 0
SmartCommunity/mybatisGeneratorCode/src/main/java/com/example/demo/MybatiesPlus.java Целия файл

@@ -0,0 +1,129 @@
1
+package com.example.demo;
2
+
3
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
4
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
5
+import com.baomidou.mybatisplus.generator.AutoGenerator;
6
+import com.baomidou.mybatisplus.generator.InjectionConfig;
7
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
8
+import com.baomidou.mybatisplus.generator.config.FileOutConfig;
9
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
10
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
11
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
12
+import com.baomidou.mybatisplus.generator.config.TemplateConfig;
13
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
14
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
15
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
16
+import org.springframework.util.StringUtils;
17
+
18
+import java.util.ArrayList;
19
+import java.util.List;
20
+import java.util.Scanner;
21
+
22
+/**
23
+ * @author FXF
24
+ * @date 2018-12-18
25
+ */
26
+public class MybatiesPlus {
27
+		/**
28
+		 * <p>
29
+		 * 读取控制台内容
30
+		 * </p>
31
+		 */
32
+		public static String scanner(String tip) {
33
+			Scanner scanner = new Scanner(System.in);
34
+			StringBuilder help = new StringBuilder();
35
+			help.append("请输入" + tip + ":");
36
+			System.out.println(help.toString());
37
+			if (scanner.hasNext()) {
38
+				String ipt = scanner.next();
39
+				if (!StringUtils.isEmpty(ipt)) {
40
+					return ipt;
41
+				}
42
+			}
43
+			throw new MybatisPlusException("请输入正确的" + tip + "!");
44
+		}
45
+		
46
+		public static void main(String[] args) {
47
+			// 代码生成器
48
+			AutoGenerator mpg = new AutoGenerator();
49
+			
50
+			// 全局配置
51
+			GlobalConfig gc = new GlobalConfig();
52
+			String projectPath = System.getProperty("user.dir");
53
+			gc.setOutputDir(projectPath + "/src/main/java");
54
+			gc.setAuthor("jobob");
55
+			gc.setOpen(false);
56
+			mpg.setGlobalConfig(gc);
57
+			
58
+			// 数据源配置
59
+			DataSourceConfig dsc = new DataSourceConfig();
60
+			dsc.setUrl("jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/smart_community_dev?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true");
61
+			// dsc.setSchemaName("public");
62
+			dsc.setDriverName("com.mysql.jdbc.Driver");
63
+			dsc.setUsername("root");
64
+			dsc.setPassword("DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q");
65
+			mpg.setDataSource(dsc);
66
+			
67
+			// 包配置
68
+			PackageConfig pc = new PackageConfig();
69
+			pc.setModuleName(scanner("模块名"));
70
+			pc.setParent("com.community.huiju");
71
+			mpg.setPackageInfo(pc);
72
+			
73
+			// 自定义配置
74
+			InjectionConfig cfg = new InjectionConfig() {
75
+				@Override
76
+				public void initMap() {
77
+					// to do nothing
78
+				}
79
+			};
80
+			
81
+			// 如果模板引擎是 freemarker
82
+			String templatePath = "/templates/mapper.xml.ftl";
83
+			// 如果模板引擎是 velocity
84
+			// String templatePath = "/templates/mapper.xml.vm";
85
+			
86
+			// 自定义输出配置
87
+			List<FileOutConfig> focList = new ArrayList<>();
88
+			// 自定义配置会被优先输出
89
+			focList.add(new FileOutConfig(templatePath) {
90
+				@Override
91
+				public String outputFile(TableInfo tableInfo) {
92
+					// 自定义输出文件名
93
+					return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
94
+							+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
95
+				}
96
+			});
97
+			
98
+			cfg.setFileOutConfigList(focList);
99
+			mpg.setCfg(cfg);
100
+			
101
+			// 配置模板
102
+			TemplateConfig templateConfig = new TemplateConfig();
103
+			
104
+			// 配置自定义输出模板
105
+			// templateConfig.setEntity();
106
+			// templateConfig.setService();
107
+			// templateConfig.setController();
108
+			
109
+			templateConfig.setXml(null);
110
+			mpg.setTemplate(templateConfig);
111
+			
112
+			// 策略配置
113
+			StrategyConfig strategy = new StrategyConfig();
114
+			strategy.setNaming(NamingStrategy.underline_to_camel);
115
+			strategy.setColumnNaming(NamingStrategy.underline_to_camel);
116
+			//strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
117
+			strategy.setEntityLombokModel(true);
118
+			strategy.setRestControllerStyle(true);
119
+			//strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
120
+			strategy.setInclude(scanner("表名"));
121
+			strategy.setSuperEntityColumns("id");
122
+			strategy.setControllerMappingHyphenStyle(true);
123
+			strategy.setTablePrefix(pc.getModuleName() + "_");
124
+			mpg.setStrategy(strategy);
125
+			mpg.setTemplateEngine(new FreemarkerTemplateEngine());
126
+			mpg.execute();
127
+		}
128
+
129
+}

+ 5
- 0
SmartCommunity/mybatisGeneratorCode/src/main/resources/mapper/tp/UserMapper.xml Целия файл

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.baomidou.ant.tp.mapper.UserMapper">
4
+
5
+</mapper>