参考lindaZ的IntelliJ IDEA 创建spring boot 的Hello World 项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

1.Open IDEA,choose "New-->Project"

2.Choose "Spring Initializr"

-> next

3.Project Metadata:

Group: com.chanchifeng
Artifact: server-system
Description: server-system project for Spring Boot

-> next

4. Choose "Web"

-> next

5.删除.mvn,mvnw,mvnw.cmd。

创建HelloController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

HelloController.java:

package com.chanchifeng.serversystem;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan("com.chanchifeng.serversystem.ctrl")
public class ServerSystemApplication {

public static void main(String[] args) {
SpringApplication.run(ServerSystemApplication.class, args);
}
}

修改HelloController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

package com.chanchifeng.serversystem.ctrl;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author:porschan
* @description:
* @date: Created in 10:14 2018/6/15
* @modified By:
*/

@RestController
@EnableAutoConfiguration
public class HelloController {

@RequestMapping("/hello")
public String index(){
System.out.println("进入controller");
return "Hello World!";
}
}

运行com.chanchifeng.serversystem.ServerSystemApplication#main,在浏览器输入http://localhost:8080/hello,spring Boot项目搭建成功。