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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @author yangkai.shen
  63. * @date Created in 2018-09-28 14:49
  64. */
  65. @SpringBootApplication
  66. @RestController
  67. public class SpringBootDemoHelloworldApplication {
  68. public static void main(String[] args) {
  69. SpringApplication.run(SpringBootDemoHelloworldApplication.class, args);
  70. }
  71. /**
  72. * Hello,World
  73. *
  74. * @param who 参数,非必须
  75. * @return Hello, ${who}
  76. */
  77. @GetMapping("/hello")
  78. public String sayHello(@RequestParam(required = false, name = "who") String who) {
  79. if (StrUtil.isBlank(who)) {
  80. who = "World";
  81. }
  82. return StrUtil.format("Hello, {}!", who);
  83. }
  84. }
  85. ```
  86. ### application.yml
  87. ```yaml
  88. server:
  89. port: 8080
  90. servlet:
  91. context-path: /demo
  92. ```