Browse Source

代码生成

chengpeng 5 years ago
parent
commit
ca22706ccf

+ 12 - 5
mec-education/pom.xml

@@ -47,11 +47,6 @@
 		</dependency>
 
 		<dependency>
-			<groupId>com.ym</groupId>
-			<artifactId>mec-biz</artifactId>
-		</dependency>
-
-		<dependency>
 			<groupId>com.baomidou</groupId>
 			<artifactId>mybatis-plus-boot-starter</artifactId>
 			<version>3.1.0</version>
@@ -69,6 +64,18 @@
 			<version>1.18.4</version>
 			<scope>provided</scope>
 		</dependency>
+		<dependency>
+			<groupId>com.baomidou</groupId>
+			<artifactId>mybatis-plus-generate</artifactId>
+			<version>2.3.3</version>
+		</dependency>
+		<!-- 模板引擎 -->
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity-engine-core</artifactId>
+			<version>2.0</version>
+		</dependency>
+
 	</dependencies>
 	<build>
 		<plugins>

+ 1 - 8
mec-education/src/main/java/com/ym/mec/education/EducationApplication.java

@@ -1,23 +1,16 @@
 package com.ym.mec.education;
 
-import org.mybatis.spring.annotation.MapperScan;
+import com.spring4all.swagger.EnableSwagger2Doc;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.client.loadbalancer.LoadBalanced;
-import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.client.RestTemplate;
 
-import com.spring4all.swagger.EnableSwagger2Doc;
-
 @SpringBootApplication
 @EnableDiscoveryClient
-@EnableFeignClients("com.ym.mec")
-@MapperScan("com.ym.mec.biz.dal.dao")
-@ComponentScan(basePackages = "com.ym.mec")
 @Configuration
 @EnableSwagger2Doc
 public class EducationApplication {

+ 2 - 0
mec-education/src/main/java/com/ym/mec/education/config/ResourceServerConfig.java

@@ -1,3 +1,4 @@
+/*
 package com.ym.mec.education.config;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,3 +32,4 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
 	}
 
 }
+*/

+ 8 - 4
mec-education/src/main/java/com/ym/mec/education/config/WebMvcConfig.java

@@ -1,3 +1,4 @@
+/*
 package com.ym.mec.education.config;
 
 import java.io.IOException;
@@ -9,6 +10,8 @@ import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
 
+import com.ym.mec.common.config.EnumConverterFactory;
+import com.ym.mec.common.enums.BaseEnum;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
@@ -32,15 +35,15 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
-import com.ym.mec.common.config.EnumConverterFactory;
-import com.ym.mec.common.enums.BaseEnum;
 
 @Configuration
 public class WebMvcConfig implements WebMvcConfigurer {
 
-	/**
+	*/
+/**
 	 * 枚举类的转换器 addConverterFactory
-	 */
+	 *//*
+
 	@Override
 	public void addFormatters(FormatterRegistry registry) {
 		registry.addConverterFactory(new EnumConverterFactory());
@@ -104,3 +107,4 @@ public class WebMvcConfig implements WebMvcConfigurer {
 	}
 
 }
+*/

+ 139 - 0
mec-education/src/main/java/com/ym/mec/education/entity/SysUser.java

@@ -0,0 +1,139 @@
+package com.ym.mec.education.entity;
+
+import com.baomidou.mybatisplus.enums.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.activerecord.Model;
+import com.baomidou.mybatisplus.annotations.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 用户表
+ * </p>
+ *
+ * @author lqh
+ * @since 2019-09-25
+ */
+@TableName("sys_user")
+@Data
+@ToString
+public class SysUser extends Model<SysUser> {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id_", type = IdType.AUTO)
+    private Integer id;
+    /**
+     * 用户名
+     */
+    @TableField("username_")
+    private String username;
+    @TableField("password_")
+    private String password;
+    /**
+     * 随机盐
+     */
+    @TableField("salt_")
+    private String salt;
+    /**
+     * 简介
+     */
+    @TableField("phone_")
+    private String phone;
+    /**
+     * 头像
+     */
+    @TableField("avatar_")
+    private String avatar;
+    /**
+     * 创建时间
+     */
+    @TableField("create_time_")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @TableField("update_time_")
+    private Date updateTime;
+    /**
+     * 0-正常,9-锁定
+     */
+    @TableField("lock_flag_")
+    private String lockFlag;
+    /**
+     * 0-正常,1-删除
+     */
+    @TableField("del_flag_")
+    private String delFlag;
+    /**
+     * 微信openid
+     */
+    @TableField("wx_openid_")
+    private String wxOpenid;
+    /**
+     * QQ openid
+     */
+    @TableField("qq_openid_")
+    private String qqOpenid;
+    /**
+     * 用户类型(STUDENT/TEACHER/SYSTEM)
+     */
+    @TableField("user_type_")
+    private String userType;
+    /**
+     * 性别(0,女  1,男)
+     */
+    @TableField("gender_")
+    private String gender;
+    /**
+     * 民族
+     */
+    @TableField("nation_")
+    private String nation;
+    /**
+     * 出生日期
+     */
+    @TableField("birthdate_")
+    private Date birthdate;
+    /**
+     * 邮箱
+     */
+    @TableField("email_")
+    private String email;
+    @TableField("organ_id_")
+    private Integer organId;
+    /**
+     * 融云token
+     */
+    @TableField("im_token_")
+    private String imToken;
+    /**
+     * 身份证号码
+     */
+    @TableField("id_card_no_")
+    private String idCardNo;
+    /**
+     * e签宝唯一编号
+     */
+    @TableField("esign_id_")
+    private String esignId;
+    /**
+     * 微信号
+     */
+    @TableField("wechat_id_")
+    private String wechatId;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return id;
+    }
+}

+ 16 - 0
mec-education/src/main/java/com/ym/mec/education/mapper/SysUserMapper.java

@@ -0,0 +1,16 @@
+package com.ym.mec.education.mapper;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.ym.mec.education.entity.SysUser;
+
+/**
+ * <p>
+ * 用户表 Mapper 接口
+ * </p>
+ *
+ * @author lqh
+ * @since 2019-09-25
+ */
+public interface SysUserMapper extends BaseMapper<SysUser> {
+
+}

+ 36 - 0
mec-education/src/main/java/com/ym/mec/education/mapper/xml/SysUserMapper.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ym.mec.education.mapper.SysUserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.ym.mec.education.entity.SysUser">
+        <id column="id_" property="id" />
+        <result column="username_" property="username" />
+        <result column="password_" property="password" />
+        <result column="salt_" property="salt" />
+        <result column="phone_" property="phone" />
+        <result column="avatar_" property="avatar" />
+        <result column="create_time_" property="createTime" />
+        <result column="update_time_" property="updateTime" />
+        <result column="lock_flag_" property="lockFlag" />
+        <result column="del_flag_" property="delFlag" />
+        <result column="wx_openid_" property="wxOpenid" />
+        <result column="qq_openid_" property="qqOpenid" />
+        <result column="user_type_" property="userType" />
+        <result column="gender_" property="gender" />
+        <result column="nation_" property="nation" />
+        <result column="birthdate_" property="birthdate" />
+        <result column="email_" property="email" />
+        <result column="organ_id_" property="organId" />
+        <result column="im_token_" property="imToken" />
+        <result column="id_card_no_" property="idCardNo" />
+        <result column="esign_id_" property="esignId" />
+        <result column="wechat_id_" property="wechatId" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id_, username_, password_, salt_, phone_, avatar_, create_time_, update_time_, lock_flag_, del_flag_, wx_openid_, qq_openid_, user_type_, gender_, nation_, birthdate_, email_, organ_id_, im_token_, id_card_no_, esign_id_, wechat_id_
+    </sql>
+
+</mapper>

+ 16 - 0
mec-education/src/main/java/com/ym/mec/education/service/ISysUserService.java

@@ -0,0 +1,16 @@
+package com.ym.mec.education.service;
+
+import com.baomidou.mybatisplus.service.IService;
+import com.ym.mec.education.entity.SysUser;
+
+/**
+ * <p>
+ * 用户表 服务类
+ * </p>
+ *
+ * @author lqh
+ * @since 2019-09-25
+ */
+public interface ISysUserService extends IService<SysUser> {
+
+}

+ 21 - 0
mec-education/src/main/java/com/ym/mec/education/service/impl/SysUserServiceImpl.java

@@ -0,0 +1,21 @@
+package com.ym.mec.education.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.education.entity.SysUser;
+import com.ym.mec.education.mapper.SysUserMapper;
+import com.ym.mec.education.service.ISysUserService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 用户表 服务实现类
+ * </p>
+ *
+ * @author lqh
+ * @since 2019-09-25
+ */
+@Service
+public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
+
+}

+ 167 - 0
mec-education/src/main/java/test/MpGenerator.java

@@ -0,0 +1,167 @@
+package test;
+
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.*;
+import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.DbType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+/**
+ * <p>
+ * 代码生成器演示
+ * </p>
+ */
+public class MpGenerator {
+
+    final static String dirPath = "D://gen";
+
+    /**
+     * <p>
+     * MySQL 生成演示
+     * </p>
+     */
+    public static void main(String[] args) {
+        AutoGenerator mpg = new AutoGenerator();
+        // 选择 freemarker 引擎,默认 Veloctiy
+        //mpg.setTemplateEngine(new FreemarkerTemplateEngine());
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        gc.setOutputDir(dirPath);
+        gc.setAuthor("lqh");
+        gc.setFileOverride(true); //是否覆盖
+        gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false
+        gc.setEnableCache(false);// XML 二级缓存
+        gc.setBaseResultMap(true);// XML ResultMap
+        gc.setBaseColumnList(true);// XML columList
+
+        // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        // gc.setMapperName("%sDao");
+        // gc.setXmlName("%sMapper");
+        // gc.setServiceName("MP%sService");
+        // gc.setServiceImplName("%sServiceDiy");
+        // gc.setControllerName("%sAction");
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setDbType(DbType.MYSQL);
+        dsc.setTypeConvert(new MySqlTypeConvert() {
+            // 自定义数据库表字段类型转换【可选】
+            @Override
+            public DbColumnType processTypeConvert(String fieldType) {
+                System.out.println("转换类型:" + fieldType);
+                // 注意!!processTypeConvert 存在默认类型转换,如果不是你要的效果请自定义返回、非如下直接返回。
+                return super.processTypeConvert(fieldType);
+            }
+        });
+        dsc.setDriverName("com.mysql.jdbc.Driver");
+        dsc.setUsername("mec_dev");
+        dsc.setPassword("mec_dev");
+        dsc.setUrl("jdbc:mysql://47.99.212.176:3306/mec_dev?characterEncoding=utf8");
+        mpg.setDataSource(dsc);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        // strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
+        //strategy.setTablePrefix(new String[]{"tb_", "tsys_"});// 此处可以修改为您的表前缀
+        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
+         strategy.setInclude(new String[] { "sys_user" }); // 需要生成的表
+        // strategy.setExclude(new String[]{"test"}); // 排除生成的表
+        // 自定义实体父类
+        // strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");
+        // 自定义实体,公共字段
+        // strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
+        // 自定义 mapper 父类
+        // strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
+        // 自定义 service 父类
+        // strategy.setSuperServiceClass("com.baomidou.demo.TestService");
+        // 自定义 service 实现类父类
+        // strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
+        // 自定义 controller 父类
+        // strategy.setSuperControllerClass("com.baomidou.demo.TestController");
+        // 【实体】是否生成字段常量(默认 false)
+        // public static final String ID = "test_id";
+        // strategy.setEntityColumnConstant(true);
+        // 【实体】是否为构建者模型(默认 false)
+        // public User setName(String name) {this.name = name; return this;}
+        strategy.setEntityBuilderModel(true);
+        mpg.setStrategy(strategy);
+
+        //com.ym.mec.education.entity
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setParent("com");
+        pc.setModuleName("ym");
+        pc.setController("education");
+        pc.setEntity("entity");
+        pc.setMapper("mapper");
+        pc.setService("service");
+        pc.setServiceImpl("serviceImpl");
+        pc.setXml("mapperXml");
+
+        mpg.setPackageInfo(pc);
+
+        // 注入自定义配置,可以在 VM 中使用 cfg.abc 【可无】
+        InjectionConfig cfg = new InjectionConfig() {
+            @Override
+            public void initMap() {
+                Map<String, Object> map = new HashMap<String, Object>();
+                map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
+                this.setMap(map);
+            }
+        };
+
+        // 自定义 xxList.jsp 生成
+        List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
+/*        focList.add(new FileOutConfig("/template/list.jsp.vm") {
+            @Override
+            public String outputFile(TableInfo tableInfo) {
+                // 自定义输入文件名称
+                return "D://my_" + tableInfo.getEntityName() + ".jsp";
+            }
+        });
+        cfg.setFileOutConfigList(focList);
+        mpg.setCfg(cfg);*/
+
+        // 调整 xml 生成目录演示
+/*        focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
+            @Override
+            public String outputFile(TableInfo tableInfo) {
+                return dirPath + tableInfo.getEntityName() + "Mapper.xml";
+            }
+        });
+        cfg.setFileOutConfigList(focList);
+        */
+        mpg.setCfg(cfg);
+
+        // 关闭默认 xml 生成,调整生成 至 根目录
+/*        TemplateConfig tc = new TemplateConfig();
+        tc.setXml(null);
+        mpg.setTemplate(tc);*/
+
+        // 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/templates 下面内容修改,
+        // 放置自己项目的 src/main/resources/templates 目录下, 默认名称一下可以不配置,也可以自定义模板名称
+        // TemplateConfig tc = new TemplateConfig();
+        // tc.setController("...");
+        // tc.setEntity("...");
+        // tc.setMapper("...");
+        // tc.setXml("...");
+        // tc.setService("...");
+        // tc.setServiceImpl("...");
+        // 如上任何一个模块如果设置 空 OR Null 将不生成该模块。
+        // mpg.setTemplate(tc);
+
+        // 执行生成
+        mpg.execute();
+
+        // 打印注入设置【可无】
+        System.err.println(mpg.getCfg().getMap().get("abc"));
+    }
+}

+ 2 - 3
mec-education/src/main/resources/application.yml

@@ -49,10 +49,9 @@ spring:
       #连接池中的最小空闲连接
       min-idle: 0
 
-mybatis:
-  mapperLocations: classpath:config/mybatis/*.xml
 mybatis-plus:
-  mapper-locations: classpath*:config/mybatis/*.xml
+  mapper-locations: classpath:com/ym/mec/education/mapper/xml/*.xml
+  typeAliasesPackage : com.ym.mec.education.entity
   configuration:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl