栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

利用fast-generator生成基础代码

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用fast-generator生成基础代码

在pom文件中加入这句代码

	
		org.springframework.boot
		spring-boot-starter-parent
		2.2.6.RELEASE
		
	

修改application.yml,先生成pms的代码

# mysql
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    #MySQL配置
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.159.135:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: root

修改generator.properties的包名以及模块名以及前缀

mainPath=com.example
#u5305u540D
package=com.example.gulimall
moduleName=product
#u4F5Cu8005
author=leohams
#Email
email=gf879543517@163.com
#u8868u524Du7F00(u7C7Bu540Du4E0Du4F1Au5305u542Bu8868u524Du7F00)
tablePrefix=pms_

最后去renren-generator/src/main/resources/template/Controller.java.vm注释关于

RequiresPermissions的代码
package ${package}.${moduleName}.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ${package}.${moduleName}.entity.${className}Entity;
import ${package}.${moduleName}.service.${className}Service;
import ${mainPath}.common.utils.PageUtils;
import ${mainPath}.common.utils.R;




@RestController
@RequestMapping("${moduleName}/${pathName}")
public class ${className}Controller {
    @Autowired
    private ${className}Service ${classname}Service;

    
    @RequestMapping("/list")
##    @RequiresPermissions("${moduleName}:${pathName}:list")
    public R list(@RequestParam Map params){
        PageUtils page = ${classname}Service.queryPage(params);

        return R.ok().put("page", page);
    }


    
    @RequestMapping("/info/{${pk.attrname}}")
##    @RequiresPermissions("${moduleName}:${pathName}:info")
    public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
		${className}Entity ${classname} = ${classname}Service.getById(${pk.attrname});

        return R.ok().put("${classname}", ${classname});
    }

    
    @RequestMapping("/save")
##    @RequiresPermissions("${moduleName}:${pathName}:save")
    public R save(@RequestBody ${className}Entity ${classname}){
		${classname}Service.save(${classname});

        return R.ok();
    }

    
    @RequestMapping("/update")
##    @RequiresPermissions("${moduleName}:${pathName}:update")
    public R update(@RequestBody ${className}Entity ${classname}){
		${classname}Service.updateById(${classname});

        return R.ok();
    }

    
    @RequestMapping("/delete")
##    @RequiresPermissions("${moduleName}:${pathName}:delete")
    public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
		${classname}Service.removeByIds(Arrays.asList(${pk.attrname}s));

        return R.ok();
    }

}

然后运行

RenrenApplication

·

打开网址localhost

选择所有表然后生成代码

 

解压得到文件夹

 

将main直接复制到product中

 

 为了方便之后所有的微服务模块的代码运行,需要创建一个公共服务模块

gulimall-common ,提供每一个微服务公共的依赖、bean、工具类等

pom文件:



    
        gulimall
        com.example.gulimall
        0.0.1-SNAPSHOT
    
    4.0.0

    gulimall-common

    每一个微服务公共的依赖、bean、工具类等
    
        8
        8
    
    

        
            com.baomidou
            mybatis-plus-boot-starter
            3.3.1
        
        
            org.projectlombok
            lombok
            1.18.24
        
        
        
            org.apache.httpcomponents
            httpcore
            4.4.14
        
        
            commons-lang
            commons-lang
            2.6
        
        
            javax.servlet
            servlet-api
            2.3
            provided
        
        
            org.springframework.boot
            spring-boot-starter-validation
            2.6.7
        

    

然后去renren-fast模块里复制以下文件

 

 发现main中代码不报错了,就可以进行后续的基本功能测试了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/936555.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号