《Spring in Action》第 5 版這本書附帶了一些可下載的源代碼,這些源代碼是按章節(jié)組織的。可下載軟件的鏈接如下: https://www.manning.com/downloads/1599這是第 1 章示例代碼的 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"> <modelVersion>4.0.0</modelVersion> <groupId>sia</groupId> <artifactId>taco-cloud</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <!--1--> <name>taco-cloud</name> <description>Taco Cloud Example</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <!--2--> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding> UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding> UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <!--3--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>調(diào)用應用程序(在我的本地服務器上運行)的 URL 如下:http://localhost:8080/我想進行更改(對 POM?),以便我可以使用 URL 指定章節(jié)編號。具體來說,我想使用以下 URL 調(diào)用應用程序: http://localhost:8080/Chapter01 控制器代碼中的@GetMapping 注解使用了我想保留的根路徑(即“/”)。請指點指點。
1 回答

森欄
TA貢獻1810條經(jīng)驗 獲得超5個贊
對于具有公共基地址或 URL 路徑的控制器,您可以做的是@RequestMapping("/Chapter01")向您的控制器添加注釋。
您的控制器將如下所示:
@RestController
@RequestMapping("/Chapter01")
public class Controller {
@GetMapping("/")
// some get method
}
現(xiàn)在您使用以下 URL 調(diào)用此方法:http://localhost:8080/Chapter01/
添加回答
舉報
0/150
提交
取消