Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
|
2 years ago | |
---|---|---|
.. | ||
src | 2 years ago | |
README.md | 2 years ago | |
pom.xml | 2 years ago |
本 demo 演示如何使用 Spring Boot 写一个hello world
<dependencies>
<dependency>
<groupId>com.xkcoding</groupId>
<artifactId>common-tools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@SpringBootApplication
@RestController
public class HelloworldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
/**
* Hello,World
*
* @param who 参数,非必须
* @return Hello, ${who}
*/
@GetMapping("/hello")
public String sayHello(@RequestParam(required = false, name = "who") String who) {
if (StrUtil.isBlank(who)) {
who = "World";
}
return StrUtil.format("Hello, {}!", who);
}
}
server:
port: 8080
servlet:
context-path: /demo
启动 HelloworldApplication.java
打开任意浏览器:
http://localhost:8080/demo/hello
,输出 Hello, World!
;http://localhost:8080/demo/hello?who=xkcoding
,输出 Hello, xkcoding!
。一个用来深度学习并实战 spring boot 的项目,目前总共包含 66 个集成demo,已经完成 55 个。
Java SVG CSS JavaScript SQL other