java代码自动生成带swagger3注解

最近项目换了swagger3原先使用的tkmapper自动生成工具不支持swagger3版本注解。所以,我亲自出手开源了一个针对swagger3支持的项目。使用方法如下:

一:在pom文件中引入jar配置

<dependency>
  <groupId>io.gitee.wang_ming_yi</groupId>
  <artifactId>code_generator</artifactId>
  <version>0.0.2</version>
</dependency>

二:引入相关依赖,如有则可以忽略

     <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.31</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

  

三:创建生成类

package io.gitee.wang_ming_yi.code_generator;

/**
 * @author 名一
 * @ClassName CodeAutoGenerator
 * @description: TODO
 * @datetime 2023年 03月 06日 15:32
 * @version: 1.0
 */
public class CodeAutoGeneratorU {
    private static String author = "名一";
    private static String tableName = "attach";
    private static String jdbcUrl = "jdbc:mysql://你的连接地址:3306/数据库名?serverTimezone=GMT%2B8";
    private static String dirver = "com.mysql.jdbc.Driver";
    private static String user = "用户名";
    private static String pwd = "密码";
    private static String parent = "com.gctl.bol.a";
    private static String entity = "entity";
    private static String mapper = "mapper";
    private static String xmlPath = "test";
    private static String annotation = "ApiModelProperty";

    public static void main(String[] args) {
        GeneratorProperties properties = new GeneratorProperties();
        properties.setTableName(tableName);
        properties.setAuthor(author);
        properties.setJdbcUrl(jdbcUrl);
        properties.setDirver(dirver);
        properties.setUser(user);
        properties.setPwd(pwd);
        properties.setParent(parent);
        properties.setEntity(entity);
        properties.setMapper(mapper);
        properties.setXmlPath(xmlPath);
        properties.setAnnotation(annotation);
        GeneratorUtil.generator(properties);
    }
}

四:运行main方法即可生成

 

 

 

 

 

 

 到此生成操作就完成了,有兴趣的小伙伴们赶紧试试吧。

posted @ 2023-03-07 13:57  名一  阅读(711)  评论(4编辑  收藏  举报