0
点赞
收藏
分享

微信扫一扫

使用Idea IntelliJ构建maven多模块项目(springboot)

1.File-New-Project

  1. 点击NEXT

3.一路NEXT到底

4.给父工程pom文件加上spring-boot-starter-web依赖

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

5.创建子模块:对着父工程右键-New-Module

6.同样的步骤,创建其他子模块:pojoservice后,查看目前工程的目录结构

  1. 子模块之间的依赖关系:web依赖serviceservice依赖pojo

8.编写web模块启动类

  1. 编写测试类代码
package com.example.web;

import com.example.pojo.TestPojo;
import com.example.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/getTestData")
    public TestPojo getTestData() {
        return testService.getTestData();
    }
}
package com.example.service.impl;

import com.example.pojo.TestPojo;
import com.example.service.TestService;
import org.springframework.stereotype.Service;

@Service
public class TestServiceImpl implements TestService {

    @Override
    public TestPojo getTestData() {
        TestPojo pojo = new TestPojo();
        pojo.setTestData("test data : hello world");
        return pojo;
    }
}

package com.example.pojo;


public class TestPojo {

    private String testData;

    public String getTestData() {
        return testData;
    }

    public void setTestData(String testData) {
        this.testData = testData;
    }
}
  1. 启动项目
  1. 测试无误
举报

相关推荐

0 条评论