大家好,欢迎来到IT知识分享网。
项目当前未使用数据库持久化字段所以通过mybatis-plus-generator进行的模板代码生成,后续进行维护时会更新持久化方式。使用mybatis-plus3.5.7版本,根据自定义代码模板,使用velocity模板引擎实现代码生成。
1 、创建代码生成器模块
由于代码生成器不是持久化方式,所以该模块仅限于手动生成,后续改进。
2、添加依赖
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.pinyi.supply</groupId> <artifactId>supply</artifactId> <version>0.1.0</version> </parent> <artifactId>mybatis-plus-generator</artifactId> <dependencies> <!-- 数据库驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.33</version> </dependency> <!-- 其他依赖 --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.31</version> <!-- 请根据需要选择合适的版本 --> </dependency> <!-- 其他依赖 --> <!--模板引擎依赖--> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.3</version> </dependency> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!-- mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.7</version> </dependency> <!-- 代码自动生成器依赖--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.7</version> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.vm</include> </includes> </resource> </resources> <!-- <plugins>--> <!-- <plugin>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-maven-plugin</artifactId>--> <!-- </plugin>--> <!-- </plugins>--> </build> </project>
3、创建生成器实体
package com.pinyi.supply.generator; import com.baomidou.mybatisplus.generator.FastAutoGenerator; import com.baomidou.mybatisplus.generator.config.rules.DateType; import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; import java.util.Properties; public class CodeGenerator {
public static void main(String[] args) {
Properties properties = new Properties(); properties.setProperty("resource.loader", "class"); properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.loader.classpath.ClasspathResourceLoader"); properties.setProperty("velocimacro.library.path", "path/to/your/customMacros.vtl"); // 使用 FastAutoGenerator 快速配置代码生成器 FastAutoGenerator.create("jdbc:mysql://localhost:3306/supply_system?serverTimezone=GMT%2B8", "root", "") .globalConfig(builder -> {
builder.author("SHI") // 设置作者 .enableSwagger() // 开启 Swagger 模式 .dateType(DateType.ONLY_DATE) .commentDate("yyyy-MM-dd HH:mm:ss") .outputDir("E://code"); // 输出目录 }) .packageConfig(builder -> {
builder.parent("com.pinyi.supply.system") // 设置父包名 .entity("model") // 设置实体类包名 .mapper("mapper") // 设置 Mapper 接口包名 .service("service") // 设置 Service 接口包名 .serviceImpl("service.impl") // 设置 Service 实现类包名 .xml("mappers"); // 设置 Mapper XML 文件包名 }) .strategyConfig(builder -> {
builder .controllerBuilder() .template("template/controller.java") .enableRestStyle() .enableHyphenStyle() .serviceBuilder() .serviceTemplate("template/service.java") .formatServiceFileName("I%sService") .formatServiceImplFileName("%sServiceImpl") .serviceImplTemplate("template/serviceImpl.java") .entityBuilder() .enableLombok() // 启用 Lombok .enableTableFieldAnnotation() // 启用字段注解 .javaTemplate("template/entity.java") .mapperBuilder() .mapperTemplate("template/mapper.java") .mapperXmlTemplate("template/mapper.xml") .formatMapperFileName("%sMapper") .formatXmlFileName("%sMapper") .entityBuilder() .enableLombok() // 启用 Lombok .enableTableFieldAnnotation() // 启用字段注解 ; builder.addInclude("sys_role,sys_menu,sys_role_menu,sys_user_role") // 设置需要生成的表名 .entityBuilder() .enableLombok() // 启用 Lombok .enableTableFieldAnnotation() // 启用字段注解 .controllerBuilder() .enableRestStyle(); // 启用 REST 风格 }) .templateEngine(new VelocityTemplateEngine()) // 使用 Freemarker 模板引擎 .execute(); // 执行生成 } }
4、声明vm模板
cotroller.java.vm
package ${
package.Controller}; import com.pinyi.supply.common.http.HttpResult; import ${
package.Entity}.${
entity}; import ${
package.Service}.I${
entity}Service; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; / * ${table.comment} 前端控制器 * 提供${table.comment}的增、删、改、查服务。 * * @author ${author} * @since ${date} */ @Api(tags = "${table.comment}管理") @RestController @AllArgsConstructor @RequestMapping("/${table.entityPath}") public class ${
entity}Controller {
private final I${
entity}Service ${
table.entityPath}Service; / * 根据ID查询${table.comment} * * @param id ${table.comment}的唯一标识ID * @return 包含查询结果的HttpResult对象 */ @ApiOperation(value = "根据ID查询${table.comment}", notes = "根据ID获取${table.comment}详细信息") @GetMapping("/get/{id}") public HttpResult get( @ApiParam(value = "${table.comment}的唯一标识ID", required = true) @PathVariable Long id) {
return id == null ? HttpResult.error("id不能为空") : HttpResult.success("查询成功", ${
table.entityPath}Service.getById(id)); } / * 查询所有${table.comment} * * @param ${table.entityPath} 用于过滤查询条件的实体对象 * @return 包含查询结果的HttpResult对象 */ @PreAuthorize(role = "", permission = "${table.entityPath}:list") @ApiOperation(value = "查询所有${table.comment}", notes = "获取所有${table.comment}列表信息") @GetMapping("/list") public HttpResult list(${
entity} ${
table.entityPath}) {
return HttpResult.success("查询成功", ${
table.entityPath}Service.list(${
table.entityPath})); } / * 分页查询${table.comment} * * @param ${table.entityPath} 包含分页信息和查询条件的实体对象 * @param pageNum 当前页码 * @param pageSize 每页显示的记录数 * @return 包含分页查询结果的HttpResult对象 */ @ApiOperation(value = "分页查询${table.comment}", notes = "分页查询${table.comment}信息") @PostMapping("/page") public HttpResult page( @ApiParam(value = "${table.comment}的分页和查询条件", required = true) @RequestBody ${
entity} ${
table.entityPath}, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
Page<${
entity}> page = new Page<>(pageNum, pageSize); return HttpResult.success("查询成功", ${
table.entityPath}Service.page(${
table.entityPath},page)); } / * 新增${table.comment} * * @param ${table.entityPath} 需要保存的${table.comment}实体对象 * @return 包含保存结果的HttpResult对象 */ @PreAuthorize(role = "", permission = "${table.entityPath}:save") @ApiOperation(value = "新增${table.comment}", notes = "新增一个${table.comment}") @PostMapping("/save") public HttpResult save( @ApiParam(value = "要保存的${table.comment}对象", required = true) @RequestBody ${
entity} ${
table.entityPath}) {
return HttpResult.success("保存成功",${
table.entityPath}Service.save(${
table.entityPath})); } / * 更新${table.comment} * * @param ${table.entityPath} 需要更新的${table.comment}实体对象 * @return 包含更新结果的HttpResult对象 */ @PreAuthorize(role = "", permission = "${table.entityPath}:edit") @ApiOperation(value = "更新${table.comment}", notes = "根据ID更新${table.comment}") @PutMapping("/update") public HttpResult update( @ApiParam(value = "要更新的${table.comment}对象", required = true) @RequestBody ${
entity} ${
table.entityPath}) {
return ${
table.entityPath}.getId() == null ? HttpResult.error("id不能为空") : HttpResult.success("更新成功", ${
table.entityPath}Service.updateById(${
table.entityPath})); } / * 删除${table.comment} * * @param id ${table.comment}的唯一标识ID * @return 包含删除结果的HttpResult对象 */ @PreAuthorize(role = "", permission = "${table.entityPath}:del") @ApiOperation(value = "删除${table.comment}", notes = "根据ID删除${table.comment}") @DeleteMapping("/delete/{id}") public HttpResult delete( @ApiParam(value = "${table.comment}的唯一标识ID", required = true) @PathVariable Long id) {
return id == null ? HttpResult.error("id不能为空") : ${
table.entityPath}Service.delete(id) > 0 ? HttpResult.success("删除成功") : HttpResult.error("删除失败"); } }
entity.java.vm
package ${
package.Entity}; #foreach($pkg in ${
table.importPackages}) import ${
pkg}; #end #if(${
springdoc}) import io.swagger.v3.oas.annotations.media.Schema; #elseif(${
swagger}) import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; #end #if(${
entityLombokModel}) import lombok.Getter; import lombok.Setter; #if(${
chainModel}) import lombok.experimental.Accessors; #end #end / * <p> * $!{table.comment} * </p> * * @author ${author} * @since ${date} */ #if(${
entityLombokModel}) @Getter @Setter #if(${
chainModel}) @Accessors(chain = true) #end #end #if(${
table.convert}) @TableName("${schemaName}${table.name}") #end #if(${
springdoc}) @Schema(name = "${entity}", description = "$!{table.comment}") #elseif(${
swagger}) @ApiModel(value = "${entity}对象", description = "$!{table.comment}") #end #if(${
superEntityClass}) public class ${
entity} extends ${
superEntityClass}#if(${
activeRecord})<${
entity}>#end {
#elseif(${
activeRecord}) public class ${
entity} extends Model<${
entity}> {
#elseif(${
entitySerialVersionUID}) public class ${
entity} implements Serializable {
#else public class ${
entity} {
#end #if(${
entitySerialVersionUID}) private static final long serialVersionUID = 1L; #end ---------- BEGIN 字段循环遍历 ---------- #foreach($field in ${
table.fields}) #if(${
field.keyFlag}) #set($keyPropertyName=${
field.propertyName}) #end #if("$!field.comment" != "") #if(${
springdoc}) @Schema(description = "${field.comment}") #elseif(${
swagger}) @ApiModelProperty("${field.comment}") #else / * ${field.comment} */ #end #end #if(${
field.keyFlag}) 主键 #if(${
field.keyIdentityFlag}) @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) #elseif(!$null.isNull(${
idType}) && "$!idType" != "") @TableId(value = "${field.annotationColumnName}", type = IdType.${
idType}) #elseif(${
field.convert}) @TableId(value = "${field.annotationColumnName}", type = IdType.ASSIGN_ID) #end 普通字段 #elseif(${
field.fill}) ----- 存在字段填充设置 ----- #if(${
field.convert}) @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${
field.fill}) #else @TableField(fill = FieldFill.${
field.fill}) #end #elseif(${
field.convert}) @TableField("${field.annotationColumnName}") #end 乐观锁注解 #if(${
field.versionField}) @Version #end 逻辑删除注解 #if(${
field.logicDeleteField}) @TableLogic #end private ${
field.propertyType} ${
field.propertyName}; #end ---------- END 字段循环遍历 ---------- #if(!${
entityLombokModel}) #foreach($field in ${
table.fields}) #if(${
field.propertyType.equals("boolean")}) #set($getprefix="is") #else #set($getprefix="get") #end public ${
field.propertyType} ${
getprefix}${
field.capitalName}() {
return ${
field.propertyName}; } #if(${
chainModel}) public ${
entity} set${
field.capitalName}(${
field.propertyType} ${
field.propertyName}) {
#else public void set${
field.capitalName}(${
field.propertyType} ${
field.propertyName}) {
#end this.${
field.propertyName} = ${
field.propertyName}; #if(${
chainModel}) return this; #end } #end --foreach end--- #end --end of #if(!${
entityLombokModel})-- #if(${
entityColumnConstant}) #foreach($field in ${
table.fields}) public static final String ${
field.name.toUpperCase()} = "${field.name}"; #end #end #if(${
activeRecord}) @Override public Serializable pkVal() {
#if(${
keyPropertyName}) return this.${
keyPropertyName}; #else return null; #end } #end #if(!${
entityLombokModel}) @Override public String toString() {
return "${entity}{" + #foreach($field in ${
table.fields}) #if($!{
foreach.index}==0) "${field.propertyName} = " + ${
field.propertyName} + #else ", ${field.propertyName} = " + ${
field.propertyName} + #end #end "}"; } #end }
mapper.java.vm
package ${
package.Mapper}; import ${
package.Entity}.${
entity}; import ${
superMapperClassPackage}; #if(${
mapperAnnotation}) import org.apache.ibatis.annotations.Mapper; #end / * $!{table.comment}Mapper接口 * @author ${author} * @date ${date} */ #if(${
mapperAnnotation}) @Mapper #end public interface ${
table.mapperName} extends ${
superMapperClass}<${
entity}> {
}
mapper.xml.vm
<?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="${package.Mapper}.${table.mapperName}"> #if(${
enableCache}) <!-- 开启二级缓存 --> <cache type="${cacheClassName}"/> #end #if(${
baseResultMap}) <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="${package.Entity}.${entity}"> #foreach($field in ${
table.fields}) #if(${
field.keyFlag})生成主键排在第一位 <id column="${field.name}" property="${field.propertyName}" /> #end #end #foreach($field in ${
table.commonFields})生成公共字段 <result column="${field.name}" property="${field.propertyName}" /> #end #foreach($field in ${
table.fields}) #if(!${
field.keyFlag})生成普通字段 <result column="${field.name}" property="${field.propertyName}" /> #end #end </resultMap> #end #if(${
baseColumnList}) <!-- 通用查询结果列 --> <sql id="Base_Column_List"> #foreach($field in ${
table.commonFields}) ${
field.columnName}, #end ${
table.fieldNames} </sql> #end </mapper>
service.java.vm
package ${
package.Service}; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import ${
package.Entity}.${
entity}; import java.util.List; / * ${table.comment}服务类 * 定义了对${table.comment}进行增删查改操作的方法 * 服务实现类需要实现这个接口以提供${table.comment}的业务逻辑功能 * * @author ${author} * @since ${date} */ public interface I${
entity}Service extends IService<${
entity}> {
/ * 根据ID获取${table.comment} * * @param id ${table.comment}ID * @return ${entity} ${table.comment}对象 */ ${
entity} get(Long id); / * 列出符合查询条件的${table.comment}信息 * * @param ${table.entityPath} 查询条件 * @return List<${entity}> ${table.comment}对象列表 */ List<${
entity}> list(${
entity} ${
table.entityPath}); / * 分页查询${table.comment}信息 * * @param page 分页对象,包含了分页参数和数据列表 * @return Page<${entity}> 分页数据对象,包含当前页的${table.comment}信息列表 */ Page<${
entity}> page(${
entity} ${
table.entityPath}, Page<${
entity}> page); / * 新增${table.comment}信息 * * @param ${table.entityPath} 待保存的${table.comment}对象 * @return boolean 插入操作是否成功 */ boolean save(${
entity} ${
table.entityPath}); / * 更新${table.comment}信息 * * @param ${table.entityPath} 待更新的${table.comment}对象 * @return Integer 更新受影响的行数 */ Integer update(${
entity} ${
table.entityPath}); / * 根据ID删除${table.comment}信息 * * @param id ${table.comment}ID * @return int 删除受影响的行数 */ int delete(Long id); }
serviceImpl.java.vm
package ${
package.ServiceImpl}; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import ${
package.Mapper}.${
entity}Mapper; import ${
package.Entity}.${
entity}; import ${
package.Service}.I${
entity}Service; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; import java.util.List; / * ${table.comment} 服务实现类 * 提供对${table.comment}的增、删、改、查等操作。 * * @author ${author} * @since ${date} */ @Service public class ${
entity}ServiceImpl extends ServiceImpl<${
entity}Mapper, ${
entity}> implements I${
entity}Service {
@Resource private ${
entity}Mapper ${
table.entityPath}Mapper; / * 根据ID获取${table.comment} * * @param id ${table.comment}ID * @return ${entity} ${table.comment}对象 */ @Override public ${
entity} get(Long id) {
return ${
table.entityPath}Mapper.selectById(id); } / * 列出符合查询条件的${table.comment}列表 * * @param ${table.entityPath} 查询条件 * @return ${entity}列表 */ @Override public List<${
entity}> list(${
entity} ${
table.entityPath}) {
LambdaQueryWrapper<${
entity}> wrapper = getWrapper(${
table.entityPath}); return ${
table.entityPath}Mapper.selectList(wrapper); } / * 构建查询条件封装器 * * 通过遍历所有字段来生成查询条件 * * @param ${table.entityPath} 查询条件 * @return LambdaQueryWrapper<${entity}> 查询条件封装器 */ private LambdaQueryWrapper<${
entity}> getWrapper(${
entity} ${
table.entityPath}) {
LambdaQueryWrapper<${
entity}> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(${
table.entityPath}.getId() != null, ${
entity}::getId, ${
table.entityPath}.getId()); return wrapper; } / * 分页查询${table.comment}列表 * * @param ${table.entityPath} 查询条件 * @param page 分页对象 * @return 分页对象,包含查询结果 */ @Override public Page<${
entity}> page(${
entity} ${
table.entityPath}, Page<${
entity}> page) {
LambdaQueryWrapper<${
entity}> wrapper = getWrapper(${
table.entityPath}); return ${
table.entityPath}Mapper.selectPage(page, wrapper); } / * 新增${table.comment} * * @param ${table.entityPath} 待新增的${table.comment}对象 * @return 插入操作是否成功 */ @Override public boolean save(${
entity} ${
table.entityPath}) {
if (${
table.entityPath} ==null){
throw new IllegalArgumentException("${table.comment}参数不能为空"); } saveInitMethod(${
entity} ${
table.entityPath}); return ${
table.entityPath}Mapper.insert(${
table.entityPath}) > 0; } / * 更新${table.comment} * * @param ${table.entityPath} 待更新的${table.comment}对象 * @return 更新受影响的行数 */ @Override public Integer update(${
entity} ${
table.entityPath}) {
if (${
table.entityPath} ==null || ObjectUtil.isEmpty(${
table.entityPath}.getId())){
throw new IllegalArgumentException("${table.comment}主键不能为空"); } updateInitMethod(${
entity} ${
table.entityPath}); return ${
table.entityPath}Mapper.updateById(${
table.entityPath}); } / * 新增${table.comment}信息表初始化 * @param ${table.entityPath} 新增的${table.comment}对象 */ private void saveInitMethod(${
entity} ${
table.entityPath}) {
//TODO: 用户 新增数据 初始化方法 //获取当前登录用户 Date date = new Date(); SysUser user = UserContext.getUser(); ${
table.entityPath}.setCreateBy(user.getUserName()); // 考虑从配置文件或环境变量读取 ${
table.entityPath}.setUpdateBy(user.getUserName()); // 同上 ${
table.entityPath}.setCreateTime(date); ${
table.entityPath}.setUpdateTime(date); } / * 更新用户信息表初始化 * @param ${table.entityPath} 更新的${table.comment}对象 */ private void updateInitMethod(${
entity} ${
table.entityPath}) {
//TODO: 用户 修改数据 初始化方法 Date date = new Date(); SysUser user = UserContext.getUser(); ${
table.entityPath}.setUpdateBy(user.getUserName()); // 同上 ${
table.entityPath}.setUpdateTime(date); } / * 删除${table.comment} * * @param id ${table.comment}ID * @return 删除受影响的行数 */ @Override public int delete(Long id) {
if (id == null) {
throw new IllegalArgumentException("主键不能为空"); } ${
entity} ${
table.entityPath} =${
table.entityPath}Mapper.selectById(id); if (ObjectUtil.isEmpty(${
table.entityPath})) {
throw new IllegalStateException("未找到该${table.comment}"); } return ${
table.entityPath}Mapper.deleteById(id); } }
5、生成效果
package com.pinyi.supply.system.controller; import com.pinyi.supply.common.http.HttpResult; import com.pinyi.supply.system.model.SysMenu; import com.pinyi.supply.system.service.ISysMenuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; / * 菜单权限表 前端控制器 * 提供菜单权限表的增、删、改、查服务。 * * @author SHI * @since 2024-08-29 09:39:57 */ @Api(tags = "菜单权限表管理") @RestController @AllArgsConstructor @RequestMapping("/sysMenu") public class SysMenuController {
private final ISysMenuService sysMenuService; / * 根据ID查询菜单权限表 * * @param id 菜单权限表的唯一标识ID * @return 包含查询结果的HttpResult对象 */ @ApiOperation(value = "根据ID查询菜单权限表", notes = "根据ID获取菜单权限表详细信息") @GetMapping("/get/{id}") public HttpResult get( @ApiParam(value = "菜单权限表的唯一标识ID", required = true) @PathVariable Long id) {
return id == null ? HttpResult.error("id不能为空") : HttpResult.success("查询成功", sysMenuService.getById(id)); } / * 查询所有菜单权限表 * * @param sysMenu 用于过滤查询条件的实体对象 * @return 包含查询结果的HttpResult对象 */ @ApiOperation(value = "查询所有菜单权限表", notes = "获取所有菜单权限表列表信息") @GetMapping("/list") public HttpResult list(SysMenu sysMenu) {
return HttpResult.success("查询成功", sysMenuService.list(sysMenu)); } / * 分页查询菜单权限表 * * @param sysMenu 包含分页信息和查询条件的实体对象 * @param pageNum 当前页码 * @param pageSize 每页显示的记录数 * @return 包含分页查询结果的HttpResult对象 */ @ApiOperation(value = "分页查询菜单权限表", notes = "分页查询菜单权限表信息") @PostMapping("/page") public HttpResult page( @ApiParam(value = "菜单权限表的分页和查询条件", required = true) @RequestBody SysMenu sysMenu, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
Page<SysMenu> page = new Page<>(pageNum, pageSize); return HttpResult.success("查询成功", sysMenuService.page(sysMenu,page)); } / * 新增菜单权限表 * * @param sysMenu 需要保存的菜单权限表实体对象 * @return 包含保存结果的HttpResult对象 */ @ApiOperation(value = "新增菜单权限表", notes = "新增一个菜单权限表") @PostMapping("/save") public HttpResult save( @ApiParam(value = "要保存的菜单权限表对象", required = true) @RequestBody SysMenu sysMenu) {
return HttpResult.success("保存成功",sysMenuService.save(sysMenu)); } / * 更新菜单权限表 * * @param sysMenu 需要更新的菜单权限表实体对象 * @return 包含更新结果的HttpResult对象 */ @ApiOperation(value = "更新菜单权限表", notes = "根据ID更新菜单权限表") @PutMapping("/update") public HttpResult update( @ApiParam(value = "要更新的菜单权限表对象", required = true) @RequestBody SysMenu sysMenu) {
return sysMenu.getId() == null ? HttpResult.error("id不能为空") : HttpResult.success("更新成功", sysMenuService.updateById(sysMenu)); } / * 删除菜单权限表 * * @param id 菜单权限表的唯一标识ID * @return 包含删除结果的HttpResult对象 */ @ApiOperation(value = "删除菜单权限表", notes = "根据ID删除菜单权限表") @DeleteMapping("/delete/{id}") public HttpResult delete( @ApiParam(value = "菜单权限表的唯一标识ID", required = true) @PathVariable Long id) {
return id == null ? HttpResult.error("id不能为空") : sysMenuService.delete(id) > 0 ? HttpResult.success("删除成功") : HttpResult.error("删除失败"); } }
6、完结散花
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/137756.html