dev #1
|
@ -32,12 +32,22 @@
|
|||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.baomidou</groupId> -->
|
||||
<!-- <artifactId>mybatis-plus-generator</artifactId> -->
|
||||
<!-- <version>3.4.1</version> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.apache.velocity</groupId> -->
|
||||
<!-- <artifactId>velocity-engine-core</artifactId> -->
|
||||
<!-- <version>2.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package cn.bunny.common;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
public class CodeGet {
|
||||
public static void main(String[] args) {
|
||||
// 1、创建代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 2、全局配置
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
// TODO 需要修改路径名称
|
||||
gc.setOutputDir("F:\\web项目\\Bunny-Cli\\Java\\java-template\\service" + "/src/main/java");
|
||||
gc.setServiceName("%sService"); // 去掉Service接口的首字母I
|
||||
gc.setAuthor("bunny");
|
||||
gc.setOpen(false);
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 3、数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
// TODO 需要修改数据库
|
||||
dsc.setUrl("jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true");
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("02120212");
|
||||
dsc.setDbType(DbType.MYSQL);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 4、包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setParent("cn.bunny");
|
||||
// TODO 需要修改模块名
|
||||
pc.setModuleName("service");
|
||||
pc.setController("controller");
|
||||
pc.setService("service");
|
||||
pc.setMapper("mapper");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 5、策略配置
|
||||
StrategyConfig strategy = getStrategyConfig();
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
// 6、执行
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
private static StrategyConfig getStrategyConfig() {
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// TODO 要生成的表
|
||||
strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
strategy.setRestControllerStyle(true); // restful api风格控制器
|
||||
strategy.setControllerMappingHyphenStyle(true); // url中驼峰转连字符
|
||||
return strategy;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package cn.bunny.common.generator;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class NewCodeGet {
|
||||
// 数据连接
|
||||
public static final String sqlHost = "jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
|
||||
// 作者名称
|
||||
public static final String author = "Bunny";
|
||||
// 公共路径
|
||||
public static final String outputDir = "G:\\web项目\\Bunny-Cli\\Java\\java-template\\service";
|
||||
// 实体类名称
|
||||
public static final String entity = "Bunny";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Generation("sys_menu");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名生成相应结构代码
|
||||
*
|
||||
* @param tableName 表名
|
||||
*/
|
||||
public static void Generation(String... tableName) {
|
||||
// TODO 修改数据库路径、账户、密码
|
||||
FastAutoGenerator.create(sqlHost, "root", "02120212")
|
||||
.globalConfig(builder -> {
|
||||
// 添加作者名称
|
||||
builder.author(author)
|
||||
// 启用swagger
|
||||
.enableSwagger()
|
||||
// 指定输出目录
|
||||
.outputDir(outputDir + "/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.entity(entity)// 实体类包名
|
||||
// TODO 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
||||
.parent("cn.bunny.service")
|
||||
.controller("controller")// 控制层包名
|
||||
.mapper("mapper")// mapper层包名
|
||||
.service("service")// service层包名
|
||||
.serviceImpl("service.impl")// service实现类包名
|
||||
// 自定义mapper.xml文件输出目录
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, outputDir + "/src/main/resources/mapper"));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
// 设置要生成的表名
|
||||
builder.addInclude(tableName)
|
||||
//.addTablePrefix("sys_")// TODO 设置表前缀过滤
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
.enableChainModel()
|
||||
.naming(NamingStrategy.underline_to_camel)// 数据表映射实体命名策略:默认下划线转驼峰underline_to_camel
|
||||
.columnNaming(NamingStrategy.underline_to_camel)// 表字段映射实体属性命名规则:默认null,不指定按照naming执行
|
||||
.idType(IdType.AUTO)// TODO 添加全局主键类型
|
||||
.formatFileName("%s")// 格式化实体名称,%s取消首字母I,
|
||||
.mapperBuilder()
|
||||
.mapperAnnotation(Mapper.class)// 开启mapper注解
|
||||
.enableBaseResultMap()// 启用xml文件中的BaseResultMap 生成
|
||||
.enableBaseColumnList()// 启用xml文件中的BaseColumnList
|
||||
.formatMapperFileName("%sMapper")// 格式化Dao类名称
|
||||
.formatXmlFileName("%sMapper")// 格式化xml文件名称
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")// 格式化 service 接口文件名称
|
||||
.formatServiceImplFileName("%sServiceImpl")// 格式化 service 接口文件名称
|
||||
.controllerBuilder()
|
||||
.enableRestStyle();
|
||||
})
|
||||
// .injectionConfig(consumer -> {
|
||||
// Map<String, String> customFile = new HashMap<>();
|
||||
// // 配置DTO(需要的话)但是需要有能配置Dto的模板引擎,比如freemarker,但是这里我们用的VelocityEngine,因此不多作介绍
|
||||
// customFile.put(outputDir, "/src/main/resources/templates/entityDTO.java.ftl");
|
||||
// consumer.customFile(customFile);
|
||||
// })
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package cn.bunny.common.generator;
|
||||
|
||||
public class OldCodeGet {
|
||||
public static void main(String[] args) {
|
||||
// // 1、创建代码生成器
|
||||
// AutoGenerator mpg = new AutoGenerator();
|
||||
//
|
||||
// // 2、全局配置
|
||||
// // 全局配置
|
||||
// GlobalConfig gc = new GlobalConfig();
|
||||
// // TODO 需要修改路径名称
|
||||
// gc.setOutputDir("F:\\web项目\\Bunny-Cli\\Java\\java-template\\service" + "/src/main/java");
|
||||
// gc.setServiceName("%sService"); // 去掉Service接口的首字母I
|
||||
// gc.setAuthor("bunny");
|
||||
// gc.setOpen(false);
|
||||
// mpg.setGlobalConfig(gc);
|
||||
//
|
||||
// // 3、数据源配置
|
||||
// DataSourceConfig dsc = new DataSourceConfig();
|
||||
// // TODO 需要修改数据库
|
||||
// dsc.setUrl("jdbc:mysql://106.15.251.123:3305/guigu-oa?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true");
|
||||
// dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
// dsc.setUsername("root");
|
||||
// dsc.setPassword("02120212");
|
||||
// dsc.setDbType(DbType.MYSQL);
|
||||
// mpg.setDataSource(dsc);
|
||||
//
|
||||
// // 4、包配置
|
||||
// PackageConfig pc = new PackageConfig();
|
||||
// pc.setParent("cn.bunny");
|
||||
// // TODO 需要修改模块名
|
||||
// pc.setModuleName("service");
|
||||
// pc.setController("controller");
|
||||
// pc.setService("service");
|
||||
// pc.setMapper("mapper");
|
||||
// mpg.setPackageInfo(pc);
|
||||
//
|
||||
// // 5、策略配置
|
||||
// StrategyConfig strategy = getStrategyConfig();
|
||||
// mpg.setStrategy(strategy);
|
||||
//
|
||||
// // 6、执行
|
||||
// mpg.execute();
|
||||
// }
|
||||
//
|
||||
// private static StrategyConfig getStrategyConfig() {
|
||||
// StrategyConfig strategy = new StrategyConfig();
|
||||
// // TODO 要生成的表
|
||||
// strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
// strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
// strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
// strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
// strategy.setRestControllerStyle(true); // restful api风格控制器
|
||||
// strategy.setControllerMappingHyphenStyle(true); // url中驼峰转连字符
|
||||
// return strategy;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package cn.bunny.service.Bunny;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-06
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("sys_menu")
|
||||
@ApiModel(value = "SysMenu对象", description = "菜单表")
|
||||
public class SysMenu implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("编号")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("所属上级")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("类型(0:目录,1:菜单,2:按钮)")
|
||||
private Byte type;
|
||||
|
||||
@ApiModelProperty("路由地址")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("组件路径")
|
||||
private String component;
|
||||
|
||||
@ApiModelProperty("权限标识")
|
||||
private String perms;
|
||||
|
||||
@ApiModelProperty("图标")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sortValue;
|
||||
|
||||
@ApiModelProperty("状态(0:禁止,1:正常)")
|
||||
private Byte status;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty("删除标记(0:不可用 1:可用)")
|
||||
private Byte isDeleted;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cn.bunny.service.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sysMenu")
|
||||
public class SysMenuController {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.bunny.service.mapper;
|
||||
|
||||
import cn.bunny.service.Bunny.SysMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-06
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.bunny.service.service;
|
||||
|
||||
import cn.bunny.service.Bunny.SysMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-06
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cn.bunny.service.service.impl;
|
||||
|
||||
import cn.bunny.service.Bunny.SysMenu;
|
||||
import cn.bunny.service.mapper.SysMenuMapper;
|
||||
import cn.bunny.service.service.SysMenuService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-06
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?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="cn.bunny.service.mapper.SysMenuMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.service.Bunny.SysMenu">
|
||||
<id column="id" property="id" />
|
||||
<result column="parent_id" property="parentId" />
|
||||
<result column="name" property="name" />
|
||||
<result column="type" property="type" />
|
||||
<result column="path" property="path" />
|
||||
<result column="component" property="component" />
|
||||
<result column="perms" property="perms" />
|
||||
<result column="icon" property="icon" />
|
||||
<result column="sort_value" property="sortValue" />
|
||||
<result column="status" property="status" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="is_deleted" property="isDeleted" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, parent_id, name, type, path, component, perms, icon, sort_value, status, create_time, update_time, is_deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue