SpringBoot sub-module project development and integration mybatis

1.SpringBoot sub-module

The module is divided into a plurality of program modules, i.e. maven project.

1) First, create a springboot project:

Step One: Select springboot project

 Step two: fill in the relevant information about the project, the main part is the red box in the figure below, you can change your own, here is the default, the project name is demo

 Step 3: Select the desired dependence, and here only add web Lombok, other later need to be dependent

 After clicking Finish, wait for loading is complete.

2) Create a project starters:

Step One: Select the newly built project, right to create a maven module, fill in the name of the module, here is a project-start

 If the module name there -, then click Next to note the name of the module, two modules have the same name.

Step Two: Once created, the main module of> New Package former parent module of the same name java and test> under java, here is com.example.demo.

The third step: at the start of the java class onto the module package, test the test class is the same, application.properties also drag over:

 

 The third step: delete the parent project src directory, if not mvnw, also delete the associated files.

3) Create a new web module for interacting with the page:

The first step: create a new maven module name for web-project

Step Two: Adding web-project dependency pom.xml file in the project-start:

<dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>web-project</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

第三步:在main>java的目录下创建一个包,包名必须为com.example.demo。然后在这个包下再建其他的包和类即可。这里就在包下新建一个test.UserController的类,里面的内容如下:

package com.example.demo.test;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @RequestMapping("get")
    public String get(){
        return "123哈哈哈";
    }
}

第四步:启动springboot。如果整个项目创建的没有问题,那么下面红色框里是正常的,没有×号。点击右边的三角符号启动项目,那么整个项目都会进行编译运行

 第五步:在浏览器输入localhost:8080/get,即可显示123哈哈哈。此时多模块的项目已经创建完成。若还需要其他模块,就直接创建模块,然后按照3的步骤即可。

注意:以上说的几个包名一定要注意,必须相同,否则是有问题的。

 

Guess you like

Origin www.cnblogs.com/zys2019/p/11945450.html