我在Eclipse中尝试运行了SpringBoot。(Wǒ zài Eclipse zhōng chángshì yùnxíngle SpringBoot.)
请你提供以下项目的参考:
参考意见:
– 参考书籍
– 参考材料
– 参考案例
– 参考论文
– 参考网站
– 参考数据
– 参考指南
– 参考经验
– 参考专家意见
我根据Spring官方网站的「Spring快速入门指南」进行了尝试。
https://spring.io/quickstart
请注意
只是为了确认是否可行才编写的程序,所以在Main类中进行了路由处理和控制器设置之类的操作,但实际上并不会这样写。
请确保考虑到适当的图层结构来创建它。
环境
-
- Eclipse 2020 Windows 64bit
- Spring Boot
创建一个Spring项目

-
- Gradle
Mavenのpomファイルは性に合わないのでビルドシステムはGradleを選択
Java 8
Kotlinも気になるけどJava
Versionはデフォルト設定
Spring Boot 2.2.6
これは適当
Packaging Jar
Webであることを考えるとWarだけど試しにJarを選択
按下“生成”按钮后,项目将以zip形式下载。
使用Eclipse导入项目。
导入Gradle项目

指定下载的文件夹。

被导入


执行



创建路由处理程序

通过GET请求获取请求参数。
package com.pakhuncho.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}




获取路径参数
package com.pakhuncho.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@RequestMapping("/hello/{name}")
public String hello(@PathVariable String name) {
return String.format("Hello %s!", name);
}
}
