2, 왼쪽 패널에서 봄 선택 Initializr
프로젝트 이름, 프로젝트 그룹 이름, 프로젝트 ID를 입력하고 클릭하여 다음 단계로 진행하세요
다음 페이지는 종속성 추가 페이지이며 필요에 따라 종속성을 추가할 수 있습니다. 또는 pom.xml 파일에 추가할 수 있습니다. 주로 포함: Core(core dependency), SQL, NOSQL
현재 테스트에서는 Web만 확인하면 됩니다.2. 해당 디렉터리에 example.java를 생성합니다. 코드는 다음과 같습니다:
package com.example.demo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class Example { @RequestMapping("/") String home() { return "Hello World!"; } @RequestMapping("/hello/{myName}") String index(@PathVariable String myName) { return "Hello "+myName+"!!!"; } }
3. 프로젝트를 실행하고 SpringbootTestApplication.java를 선택한 다음 마우스 오른쪽 버튼을 클릭하고 'SpringbootTestApplication'을 실행하거나 표시된 대로 버튼을 클릭합니다.
4. 프로그램이 성공적으로 시작됩니다. 콘솔은 다음과 같습니다(부분): 5. 마지막으로 테스트해 보겠습니다. http://localhost:8080/ 및 http://localhost:8080/hello를 입력합니다. /王达达🎜🎜테스트에 성공했습니다! ! ! 🎜🎜 마지막으로 참고용으로 pom.xml 코드도 첨부합니다. 🎜🎜
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 "> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>springboot_test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot_test</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!--这个就是我们刚刚勾选依赖时选择的 Web--> <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> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
위 내용은 SpringBoot 시작하기 1장: Hello World의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!