Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a new module module in jeecg-boot

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to build a new module module in jeecg-boot, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Jeecg-boot New module Module New maven Project

The new maven project is named jeecg-boot-module-jm.

You can use idea, myeclipse and other tools to create a new maven project

The content of pom.xml file is as follows

4.0.0 jeecg-boot-module-jm 2.0.2 org.jeecgframework.boot jeecg-boot-parent 2.0.2 aliyun aliyun Repository http://maven .aliyun.com / nexus/content/groups/public false jeecg jeecg Repository http://maven.jeecg.org/nexus/content/repositories/ Jeecg false org.jeecgframework.boot jeecg-boot-base-common

Note: my pom file directly copied the jeecg-boot-module-system content, changed the jeecg-boot-module-system name to jeecg-boot-module-jm, and noted the comments.

Org.springframework.boot spring-boot-maven-plugin

This code, because the newly created project needs to be packaged as a jar reference in jeecg-boot-module-system, there is no need to package the project into a springboot project, just comment on the code above.

Create a business package

Create a new package name org.jeecg.modules.hello in the root directory of the project (take issues:373 as an example, you can also use other package names, remember this package name, which will be used later in the interface problem swagger-ui)

Add business (test) code

(take issues:373 as an example, we will answer the questions one by one later.) this code cannot be accessed in swagegr-ui later because @ ApiOperation is not added to the method.

Package org.jeecg.modules.hello;import org.jeecg.common.api.vo.Result;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import io.swagger.annotations.Api;import lombok.extern.slf4j.Slf4j / * Test the new module * @ author chengtg * * / @ Slf4j@Api (tags= "New module--jm") @ RestController@RequestMapping ("/ hello") public class HelloController {@ GetMapping (value= "/") public Result hello () {Result result = new Result (); result.setResult ("hello word!"); result.setSuccess (true) Return result;}}

Note: I modified the comment (@ Api (tags= "New module--jm"), which is used later in the swagegr-ui document.

Incorporate the newly built project into parent

Incorporate the newly created jeecg-boot-module-jm into the jeecg-boot-parent

Add jeecg-boot-module-jm to the pom file modules in the jeecg-boot-framework project

The result is the following code

Jeecg-boot-base-common jeecg-boot-module-system jeecg-boot-module-jm add project dependencies

Rely on jeecg-boot-module-jms in jeecg-boot-module-system projects

Modify the pom file of the jeecg-boot-module-system project

Org.jeecgframework.boot jeecg-boot-base-common org.jeecgframework.boot jeecg-boot-module-jm 2.0.2

Compile the entire jeecg-boot-framework

If the compilation is as follows:

[INFO]-maven-install-plugin:2.5.2:install (default-install) @ jeecg-boot-module-system--[INFO] Installing / Users/chengtg/WS-platform/jeecg-boot-framework/jeecg-boot-module-system/target/jeecg-boot-module-system-2.0.2.jar to / Users/chengtg/.m2/repository/org/jeecgframework/boot/jeecg-boot-module-system/2.0.2/jeecg-boot-module-system- 2.0.2.jar [INFO] Installing / Users/chengtg/WS-platform/jeecg-boot-framework/jeecg-boot-module-system/pom.xml to / Users/chengtg/.m2/repository/org/jeecgframework/boot/jeecg-boot-module-system/2.0.2/jeecg-boot-module-system-2.0.2.pom [INFO]-- -- [INFO] Reactor Summary for jeecg-boot-parent 2.0.2: [INFO] [INFO] jeecg-boot-parent. SUCCESS [0.236 s] [INFO] jeecg-boot-base-common.. SUCCESS [1.143 s] [INFO] jeecg-boot-module-jm.. SUCCESS [1.066 s] [INFO] jeecg-boot-module-system.. SUCCESS [3.125 s] [INFO]-[INFO] BUILD SUCCESS [INFO]- -[INFO] Total time: 5.872 s [INFO] Finished at: 2019-08-04T21:41:09+08:00 [INFO]- -

Description, the new project jeecg-boot-module-jm and rely on in jeecg-boot-module-system, success!

Launch the jeecg-boot-module-system project provider document swagger

Http://localhost:8080/jeecg-boot/doc.html

The screenshot is as follows:

The question is why @ Api (tags= "New module--jm") does not appear in the newly added HelloController.

Reason View Swagger2Config configuration, Swagger2Config.java

Because the red circle in the screenshot

/ / the interface document .apis (RequestHandlerSelectors.withMethodAnnotation (ApiOperation.class)) is generated only for classes annotated with ApiOperation.

Means that only ApiOperation annotations are added to the methods of the controller class, otherwise the swagegr-ui document is not generated

Modify HelloController code

Modify the HelloController class of the jeecg-boot-module-system-jm project to add ApiOperation comments to the hello method

Package org.jeecg.modules.hello;import org.jeecg.common.api.vo.Result;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;import io.swagger.annotations.ApiParam;import lombok.extern.slf4j.Slf4j / * Test the new module * @ author chengtg * * / @ Slf4j@Api (tags= "New module--jm") @ RestController@RequestMapping ("/ hello") public class HelloController {@ ApiOperation ("Test hello method") @ GetMapping (value= "/") public Result hello () {Result result = new Result (); result.setResult ("hello word!") Result.setSuccess (true); return result;}}

Recompile starts.

Access the interface document swagger: http://localhost:8080/jeecg-boot/doc.html again

A miracle happened.

Test Interface-Debug

The code is as follows:

Package org.jeecg.config;import java.util.HashMap;import java.util.LinkedHashMap;import java.util.Map;import javax.servlet.Filter;import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;import org.apache.shiro.mgt.DefaultSubjectDAO;import org.apache.shiro.mgt.SecurityManager;import org.apache.shiro.spring.LifecycleBeanPostProcessor;import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;import org.apache.shiro.spring.web.ShiroFilterFactoryBean;import org.apache.shiro.web.mgt.DefaultWebSecurityManager Import org.jeecg.modules.shiro.authc.ShiroRealm;import org.jeecg.modules.shiro.authc.aop.JwtFilter;import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.DependsOn / * * @ author: Scott * @ date: 2018-2-7 * @ description: shiro configuration class * / @ Configurationpublic class ShiroConfig {/ * * Filter Chain definition description * * 1. A URL can be configured with multiple Filter separated by commas. When setting multiple filters, all of them are verified. Some filters can specify parameters, such as perms,roles * / @ Bean ("shiroFilter") public ShiroFilterFactoryBean shiroFilter (SecurityManager securityManager) {ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean () ShiroFilterFactoryBean.setSecurityManager (securityManager); / / interceptor Map filterChainDefinitionMap = new LinkedHashMap (); / / configure the link order that will not be intercepted to determine filterChainDefinitionMap.put ("/ hello/**", "anon") / / Test the newly added module and access filterChainDefinitionMap.put ("/ sys/login", "anon") without token; / / exclude filterChainDefinitionMap.put ("/ sys/getEncryptedString", "anon") from login API; / / get encrypted string filterChainDefinitionMap.put ("/ sys/sms", "anon") / / SMS verification code filterChainDefinitionMap.put ("/ sys/phoneLogin", "anon"); / / log in to filterChainDefinitionMap.put ("/ sys/user/checkOnlyUser", "anon"); / / verify whether the user has filterChainDefinitionMap.put ("/ sys/user/register", "anon") / / user registers filterChainDefinitionMap.put ("/ sys/user/querySysUser", "anon"); / / obtains user information filterChainDefinitionMap.put ("/ sys/user/phoneVerification", "anon") based on mobile number; / / user forgets password to verify mobile number filterChainDefinitionMap.put ("/ sys/user/passwordChange", "anon") / / user changes password filterChainDefinitionMap.put ("/ auth/2step-code", "anon"); / / login verification code filterChainDefinitionMap.put ("/ sys/common/view/**", "anon"); / / Image preview does not restrict token filterChainDefinitionMap.put ("/ sys/common/download/**", "anon") / / File download is not restricted to token filterChainDefinitionMap.put ("/ sys/common/pdf/**", "anon"); / / pdf Preview filterChainDefinitionMap.put ("/ generic/**", "anon"); / / pdf Preview requires file filterChainDefinitionMap.put ("/", "anon"); filterChainDefinitionMap.put ("/ doc.html", "anon") FilterChainDefinitionMap.put ("/ * * / * .js", "anon"); filterChainDefinitionMap.put ("/ * * / * .css", "anon"); filterChainDefinitionMap.put ("/ * * / * .html", "anon"); filterChainDefinitionMap.put ("/ * * / * .svg", "anon") FilterChainDefinitionMap.put ("/ * * / * .jpg", "anon"); filterChainDefinitionMap.put ("/ * * / * .png", "anon"); filterChainDefinitionMap.put ("/ * / * .ico", "anon"); filterChainDefinitionMap.put ("/ druid/**", "anon") FilterChainDefinitionMap.put ("/ swagger-ui.html", "anon"); filterChainDefinitionMap.put ("/ swagger**/**", "anon"); filterChainDefinitionMap.put ("/ webjars/**", "anon"); filterChainDefinitionMap.put ("/ v2gamma *", "anon") / / performance monitoring filterChainDefinitionMap.put ("/ actuator/metrics/**", "anon"); filterChainDefinitionMap.put ("/ actuator/httptrace/**", "anon"); filterChainDefinitionMap.put ("/ actuator/redis/**", "anon") / / form designer filterChainDefinitionMap.put ("/ desform/**", "anon"); / / Custom form filterChainDefinitionMap.put ("/ test/jeecgDemo/demo3", "anon"); / / template test filterChainDefinitionMap.put ("/ test/jeecgDemo/redisDemo/**", "anon") / / redis Test / / the process module component requests filterChainDefinitionMap.put ("/ act/process/**", "anon"); filterChainDefinitionMap.put ("/ act/task/**", "anon"); filterChainDefinitionMap.put ("/ act/model/**", "anon") FilterChainDefinitionMap.put ("/ service/editor/**", "anon"); filterChainDefinitionMap.put ("/ service/model/**", "anon"); filterChainDefinitionMap.put ("/ service/model/**/save", "anon"); filterChainDefinitionMap.put ("/ editor-app/**", "anon") FilterChainDefinitionMap.put ("/ diagram-viewer/**", "anon"); filterChainDefinitionMap.put ("/ modeler.html", "anon"); filterChainDefinitionMap.put ("/ designer", "anon"); filterChainDefinitionMap.put ("/ designer/**", "anon"); filterChainDefinitionMap.put ("/ plug-in/**", "anon") / / exclude Online request filterChainDefinitionMap.put ("/ auto/cgform/**", "anon"); / / FineReport report filterChainDefinitionMap.put ("/ ReportServer**", "anon"); / / add your own filter and name it jwt Map filterMap = new HashMap (1) FilterMap.put ("jwt", new JwtFilter ()); shiroFilterFactoryBean.setFilters (filterMap); / /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report