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.6 kB

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

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