1.File-New-Project
- 点击
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.同样的步骤,创建其他子模块:pojo
、service
后,查看目前工程的目录结构
- 子模块之间的依赖关系:
web
依赖service
,service
依赖pojo
8.编写web
模块启动类
- 编写测试类代码
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;
}
}
- 启动项目
- 测试无误