“Spring Boot-HelloWorld”的版本间的差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
Jihongchang(讨论 | 贡献)  | 
				Jihongchang(讨论 | 贡献)   | 
				||
| 第34行: | 第34行: | ||
</profiles>  | </profiles>  | ||
</syntaxhighlight>https://www.bilibili.com/video/BV19K4y1L7MT?p=5  | </syntaxhighlight>https://www.bilibili.com/video/BV19K4y1L7MT?p=5  | ||
| + | |||
| + | === Java代码 ===  | ||
| + | |||
| + | ==== MainApplication.java ====  | ||
| + | <syntaxhighlight lang="java">  | ||
| + | package io.github.jihch.boot;  | ||
| + | |||
| + | import org.springframework.boot.SpringApplication;  | ||
| + | import org.springframework.boot.autoconfigure.SpringBootApplication;  | ||
| + | |||
| + | |||
| + | /**  | ||
| + |  * 主程序类  | ||
| + |  * @SpringBootApplication:这是一个 Spring Boot 应用  | ||
| + |  */  | ||
| + | @SpringBootApplication  | ||
| + | public class MainApplication {  | ||
| + | |||
| + |     public static void main(String[] args) {  | ||
| + |         SpringApplication.run(MainApplication.class, args);  | ||
| + |     }  | ||
| + | |||
| + | }  | ||
| + | |||
| + | </syntaxhighlight>  | ||
| + | |||
| + | ==== HelloController.java ====  | ||
| + | <syntaxhighlight lang="java">  | ||
| + | package io.github.jihch.boot.controller;  | ||
| + | |||
| + | import org.springframework.web.bind.annotation.RequestMapping;  | ||
| + | import org.springframework.web.bind.annotation.RestController;  | ||
| + | |||
| + | @RestController  | ||
| + | public class HelloController {  | ||
| + | |||
| + |     @RequestMapping("/hello")  | ||
| + |     public String handle01() {  | ||
| + |         return "Hello, Spring Boot 2!";  | ||
| + |     }  | ||
| + | |||
| + | }  | ||
| + | |||
| + | </syntaxhighlight>  | ||
2023年2月1日 (三) 06:17的版本
Spring Boot 2 入门
系统要求
Java 8 & 兼容 java 14
Maven 3.3+
idea 2019.12
maven 设置
<mirrors>
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>
<profiles>
    <profile>
        <id>jdk-1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>
</profiles>
https://www.bilibili.com/video/BV19K4y1L7MT?p=5
Java代码
MainApplication.java
package io.github.jihch.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * 主程序类
 * @SpringBootApplication:这是一个 Spring Boot 应用
 */
@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }
}
HelloController.java
package io.github.jihch.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String handle01() {
        return "Hello, Spring Boot 2!";
    }
}