jeecg

您所在的位置:网站首页 jeecgboot和ruoyi哪个好 jeecg

jeecg

2024-06-04 13:44| 来源: 网络整理| 查看: 265

jeecg-boot框架的使用总结 一、jeecg-boot框架简介二、jeecg-boot常用注解2.1 lombok注解2.2 swagger注解2.3 自定义注解

一、jeecg-boot框架简介

JeecgBoot是一款基于BPM的低代码平台,支持微服务。强大的代码生成器让前后端代码一键生成,实现低代码开发。JeecgBoot引领新低代码开发模式:OnlineCoding-> 代码生成器-> 手工MERGE, 帮助Java项目解决70%的重复工作,让开发更多关注业务,既能快速提高效率,节省研发成本,同时又不失灵活性!

JeecgBoot框架总的来说有以下特性:

jeecg-boot是一个真正前后端分离的模版项目,便于二次开发,使用的都是较流行的新技术。 后端技术主要有spring-boot2.x、shiro、Mybatis-plus、redis等; 前端项目基于node.js、webpack构建,主要技术使用Vue、vuex、axios等。

作为模版项目,便于快速二次开发。 现成基本功能包括用户管理、角色管理、菜单管理(前端根据角色动态路由)、部门管理、 数据字典、消息中心、定时任务、及各种丰富的各种前端效果示例及最重要的代码生成功能。

全栈开发。

jeecg-boot为二次开发基础,适合用户。

二、jeecg-boot常用注解

jeecg-boot使用有lombok注解,swagger注解,springboot注解,自定义注解,导入导出Excel注解。

2.1 lombok注解 @Data注解在类上,会为类的所有属性自动生成setter/getter、equals、canEqual、hashCode、toString方法,注意如果为final属性,则不会为该属性生成setter方法。 也可以使用@Getter/@Setter注解添加到对应的属性上,则只生成对应属性的get/set方法; @EqualsAndHashCode(callSuper = false) ,不调用父类的属性,那么子类属性相同的话,那hashcode的值就相同; @Accessors(chain = true):chain的中文含义是链式的,设置为true,则setter方法返回当前对象,如果不加,则表示返回当前属性。 2.2 swagger注解 在实体类Eneity上

@ApiModel()用于类

表示对类进行说明,用于参数用实体类接收。

@ApiModel(value="students对象", description="学生类") // swagger注解 public class Students { }

@ApiModelProperty()用于方法,字段

@ApiModel(value="students对象", description="学生类") // swagger注解 public class Students { @ApiModelProperty(value = "用户名",name="userName",example="张三") private String userName; }

@ApiIgnore()用于类,方法,方法参数

表示这个方法或者类被忽略。

在接口类上

@Api()用于类

表示标识这个类是swagger的资源。

@ApiModel(value="user对象",description="用户对象user") public class User implements Serializable{ private static final long serialVersionUID = 1L; @ApiModelProperty(value="用户名",name="username",example="zhangsan") private String username; @ApiModelProperty(value="状态",name="state",required=true) private Integer state; private String password; private String nickName; private Integer isDeleted; @ApiModelProperty(value="id数组",hidden=true) private String[] ids; private List idList; //省略get/set }

@ApiOperation()用于方法

表示一个http请求的操作。

@ApiOperation("更改用户信息") @PostMapping("/updateUserInfo") public int updateUserInfo(User user){ int num = userService.updateUserInfo(user); return num; }

@ApiParam()用于方法,参数,字段说明;

表示对参数的添加元数据(说明或是否必填等)。

@ApiOperation("更改用户信息") @PostMapping("/updateUserInfo") public int updateUserInfo(@RequestBody @ApiParam(name="用户对象",value="传入json格式",required=true) User user){ int num = userService.updateUserInfo(user); return num; }

@ApiImplicitParam() 用于方法

表示单独的请求参数。

@ApiOperation("查询测试") @GetMapping("select") @ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query") public void select(){ }

@ApiImplicitParams() 用于方法,包含多个 @ApiImplicitParam

@ApiOperation("查询测试") @GetMapping("select") @ApiImplicitParams({ @ApiImplicitParam(name="name",value="用户名",dataType="string", paramType = "query",example="zhangsan"), @ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query") }) public void select(){ } 2.3 自定义注解

@AutoLog

在需要记录日志信息的方法上添加@AutoLog注解,通过配置的切面类,即可插入数据库对应的日志信息。

/** * 系统日志注解 * */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface AutoLog { /** * 日志内容 * * @return */ String value() default ""; /** * 日志类型 * * @return 0:操作日志;1:登录日志;2:定时任务; */ int logType() default CommonConstant.LOG_TYPE_2; }

使用@interface表明是注解类 凡是在目标上使用@AutoLog都会触发AOP操作

@Dict

在生成的实体类的属性上添加@Dict注解,主要就是实现字符的转换,给前端提供想要的数据。

/** * 日志类型(1登录日志,2操作日志) */ @Dict(dicCode = "log_type") private Integer logType;

在前台查询时,会返回logType(对应的数据库的值),同时返回logType_dictText,为通过切面解析到的文本值。

@PermissionData

此注解是用来进行数据权限控制的。 ①在前台页面对指定菜单添加数据规则; ②配置角色授予权限规则; ③在进行查询的方法上添加 @PermissionData(pageComponent=“text/StudentsList”)注解。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3