侧边栏壁纸
  • 累计撰写 26 篇文章
  • 累计创建 9 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

jeecg-boot 创建module新工程

仓鼠
2022-01-01 / 0 评论 / 0 点赞 / 58 阅读 / 10512 字 / 正在检测是否收录...

jeecg-boot 创建module新工程

jeecg-boot 版本 Jeecg Boot Version: 2.4.2

1. 新建 module 工程

1.1. 新建module

操作流程

选中oriental-sttel-cord-energy

20210225120204143.png

file -> New -> Module..

20210225113625965.png

1.2. 选择项目类型

我们选择maven

Maven -> 选择sdk1.8 以上 -> next

20210225113936969.png

1.3. 输入模块名称 {模块名}

20210225114451478.png

next -> 如果名字没对应需要修改名称(会自动删除“-”符号) -> ++F++inish

2.进行配置

2.1 在最外层的pom文件设置

<modules>
    <module>jeecg-boot-base</module>
    <module>jeecg-boot-module-demo</module>
    <module>jeecg-boot-module-system</module>
	<module>jeecg-boot-module-osc</module>
    <module>jeecg-boot-module-task</module>
    <!-- 加入新些的项目 -->
    <module>jeecg-boot-module-{新模块}</module>
	<!--   需要微服务,请打开注释
      <module>jeecg-boot-starter</module>
      <module>jeecg-cloud-module</module>-->
</modules>

2.2 配置swagger 扫描类文件

{项目}\jeecg-boot-base\jeecg-boot-base-core\src\main\java\org\jeecg\config\swagger2Config

之前的模块

@Bean(value = "defaultApi2")
public Docket defaultApi2() {
   return new Docket(DocumentationType.SWAGGER_2)
           .apiInfo(apiInfo())
           .select()
           //此包路径下的类,才生成接口文档
           .apis(RequestHandlerSelectors.basePackage("org.jeecg"))
           //加了ApiOperation注解的类,才生成接口文档
           .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
           .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
           .paths(PathSelectors.any())
           .build()
           .securitySchemes(Collections.singletonList(securityScheme()))
           .securityContexts(securityContexts());
           //.globalOperationParameters(setHeaderToken());
}

原本以为,在 .apis(RequestHandlerSelectors.basePackage("自己的包就可以了")),但是跳进实现类,发现并不可以多个,所以我们得重新复写

public static Predicate<RequestHandler> newbasePackage(final String basePackage) {
        return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true);
    }
private static Function<Class<?>, Boolean> handlerPackage(final String basePackage)     {
    return input -> {
        // 循环判断匹配,我这采用 “,”做分隔符
        for (String strPackage : basePackage.split(",")) {
            boolean isMatch = input.getPackage().getName().startsWith(strPackage);
            if (isMatch) {
                return true;
            }
        }
        return false;
    };
}

private static Optional<? extends Class<?>> declaringClass(RequestHandler input) {
    return Optional.fromNullable(input.declaringClass());
}

之前的的 .apis(RequestHandlerSelectors.basePackage("自己的包"))
就需要修改成
.apis(newbasePackage("自己的包"))

@Bean(value = "defaultApi2")
public Docket defaultApi2() {
   return new Docket(DocumentationType.SWAGGER_2)
           .apiInfo(apiInfo())
           .select()
           //此包路径下的类,才生成接口文档
           .apis(newbasePackage("org.jeecg,com.cs"))
           //加了ApiOperation注解的类,才生成接口文档
           .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
           .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
           .paths(PathSelectors.any())
           .build()
           .securitySchemes(Collections.singletonList(securityScheme()))
           .securityContexts(securityContexts());
           //.globalOperationParameters(setHeaderToken());
}

2.3 修改 数据字典 扫描类

ctrl+N 查询Classes文件:DictAspect

// 定义切点Pointcut
@Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..)) || execution(public * org.{自己模块}.modules..*.*Controller.*(..))")

2.4 配置行模块 POM文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>jeecg-boot-parent</artifactId>
        <groupId>org.jeecgframework.boot</groupId>
        <version>2.4.2</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <!-- 加入一下内容 -->
    <repositories>
        <repository>
            <id>aliyun</id>
            <name>aliyun Repository</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>jeecg</id>
            <name>jeecg Repository</name>
            <url>http://maven.jeecg.org/nexus/content/repositories/jeecg</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <artifactId>jeecg-boot-module-{模块名}</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.jeecgframework.boot</groupId>
            <artifactId>jeecg-boot-base-core</artifactId>
        </dependency>
    </dependencies>

</project>

2.5 修改application.yml 配置文件

jeecg-boot-module-system\src\main\resources\application-dev.yml

2.5.1 修改 mapper.xml 扫描路径

mybatis-plus:
  mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml,com/osc/**/xml/*Mapper.xml,com/task/**/xml/*Mapper.xml

2.5.2 修改 MybatisPlusConfig 扫描路口

jeecg-boot-base\jeecg-boot-base-core\src\main\java\org\jeecg\config\mybatis\MybatisPlusConfig.java

@MapperScan(value={"org.jeecg.modules.**.mapper*","com.osc.**.mapper*","com.task.**.mapper*"})

2.6 在启动类上增加扫描包

JeecgSystemApplication

/**
* 单体启动类(采用此类启动为单体模式)
*/
@Slf4j
@SpringBootApplication
//需要添加的内容
@ComponentScan(basePackages = {"org.jeecg","com.energy"})
public class JeecgSystemApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(JeecgSystemApplication.class);
    }

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
        log.info("\n----------------------------------------------------------\n\t" +
                "Application Jeecg-Boot is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");

    }

}

2.7 在system模块下的pom加入新创建模块的依赖

<dependencies>
	<dependency>
		<groupId>org.jeecgframework.boot</groupId>
		<artifactId>jeecg-system-local-api</artifactId>
	</dependency>
	<dependency>
		<groupId>org.jeecgframework.boot</groupId>
		<artifactId>jeecg-boot-module-demo</artifactId>
		<version>${jeecgboot.version}</version>
	</dependency>
	<!-- 创建的新模块 -->
	<dependency>
		<groupId>org.jeecgframework.boot</groupId>
		<artifactId>jeecg-boot-module-energy</artifactId>
		<version>${jeecgboot.version}</version>
	</dependency>
	<!-- 积木报表 -->
	<dependency>
		<groupId>org.jeecgframework.jimureport</groupId>
		<artifactId>spring-boot-starter-jimureport</artifactId>
		<version>1.2.0</version>
		<exclusions>
			<exclusion>
				<groupId>org.jeecgframework</groupId>
				<artifactId>autopoi-web</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
</dependencies>
0

评论区