You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # spring-boot-demo-helloworld
  2. > 本 demo 演示如何使用 Spring Boot 写一个hello world
  3. ## pom.xml
  4. ```xml
  5. <?xml version="1.0" encoding="UTF-8"?>
  6. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  8. <modelVersion>4.0.0</modelVersion>
  9. <groupId>com.xkcoding</groupId>
  10. <artifactId>spring-boot-demo-helloworld</artifactId>
  11. <version>0.0.1-SNAPSHOT</version>
  12. <packaging>jar</packaging>
  13. <name>spring-boot-demo-helloworld</name>
  14. <description>Demo project for Spring Boot</description>
  15. <parent>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-parent</artifactId>
  18. <version>2.0.5.RELEASE</version>
  19. <relativePath/> <!-- lookup parent from repository -->
  20. </parent>
  21. <properties>
  22. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  23. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  24. <java.version>1.8</java.version>
  25. </properties>
  26. <dependencies>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-web</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.springframework.boot</groupId>
  33. <artifactId>spring-boot-starter-test</artifactId>
  34. <scope>test</scope>
  35. </dependency>
  36. <dependency>
  37. <groupId>cn.hutool</groupId>
  38. <artifactId>hutool-all</artifactId>
  39. <version>4.1.14</version>
  40. </dependency>
  41. </dependencies>
  42. <build>
  43. <finalName>spring-boot-demo-helloworld</finalName>
  44. <plugins>
  45. <plugin>
  46. <groupId>org.springframework.boot</groupId>
  47. <artifactId>spring-boot-maven-plugin</artifactId>
  48. </plugin>
  49. </plugins>
  50. </build>
  51. </project>
  52. ```
  53. ## SpringBootDemoHelloworldApplication.java
  54. ```java
  55. /**
  56. * <p>
  57. * SpringBoot启动类
  58. * </p>
  59. *
  60. * @package: com.xkcoding.helloworld
  61. * @description: SpringBoot启动类
  62. * @author: yangkai.shen
  63. * @date: Created in 2018/9/28 2:49 PM
  64. * @copyright: Copyright (c)
  65. * @version: V1.0
  66. * @modified: yangkai.shen
  67. */
  68. @SpringBootApplication
  69. @RestController
  70. public class SpringBootDemoHelloworldApplication {
  71. public static void main(String[] args) {
  72. SpringApplication.run(SpringBootDemoHelloworldApplication.class, args);
  73. }
  74. /**
  75. * Hello,World
  76. *
  77. * @param who 参数,非必须
  78. * @return Hello, ${who}
  79. */
  80. @GetMapping("/hello")
  81. public String sayHello(@RequestParam(required = false, name = "who") String who) {
  82. if (StrUtil.isBlank(who)) {
  83. who = "World";
  84. }
  85. return StrUtil.format("Hello, {}!", who);
  86. }
  87. }
  88. ```
  89. ## application.yml
  90. ```yaml
  91. server:
  92. port: 8080
  93. servlet:
  94. context-path: /demo
  95. ```

一个用来深度学习并实战 spring boot 的项目,目前总共包含 66 个集成demo,已经完成 55 个。

Contributors (1)