最基础的hello world:
项目目录结构:
卷 software_home 的文件夹 PATH 列表
卷序列号为 7E58-1E96
D:.
│ .txt
│ pom.xml
│ springboot_0_hello.iml
│
├─.idea
│ compiler.xml
│ encodings.xml
│ misc.xml
│ uiDesigner.xml
│ workspace.xml
│
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─swq
│ │ │ HelloController.java
│ │ │ Helloworld.java
│ │ │
│ │ └─resources
│ └─test
│ └─java
└─target
│ springboot_0_hello-1.0-SNAPSHOT.jar
│ springboot_0_hello-1.0-SNAPSHOT.jar.original
│
├─classes
│ └─com
│ └─swq
│ HelloController.class
│ Helloworld.class
│
├─generated-sources
│ └─annotations
├─maven-archiver
│ pom.properties
│
└─maven-status
└─maven-compiler-plugin
├─compile
│ └─default-compile
│ createdFiles.lst
│ inputFiles.lst
│
└─testCompile
└─default-testCompile
inputFiles.lst
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>springboot_0_hello</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Helloworld:
package com.swq;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Helloworld {
public static void main(String[] args) {
SpringApplication.run(Helloworld.class, args);
}
}
HelloController:
package com.swq;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "hello swq !";
}
}
打成jar包,直接CMD界面运行:
扫描二维码关注公众号,回复:
10413300 查看本文章
运行:
访问:
OK!