1、官方源创建
2、阿里源创建(当官方源创建失败时)
3、maven创建
1、官方源创建
①打开IDEA,选择New Project(新建项目)

②选择Spring Initializr -> 选择自己的java版本 -> 选择默认的官网导入即可 -> 点击next

③配置项目信息,Java版本

④选择Spring Web依赖,点击next

⑤填写你的项目名称和存储路径,点击Finish

⑥创建controller包,index主页,在pom添加依赖

package com.hx.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class helloSpring {
@RequestMapping
public String index() {
return "index";
}
}
⑦运DemoApplication去网页查看,当8080被占用时,可以在application.properties更改端口号


2、阿里源创建(当官方源创建失败时)
①若使用默认源显示,将Custom换成阿里源即可(https://start.aliyun.com/)

②配置项目信息

③选择Spring Web依赖,点击next

④选择你的项目名称路径,点击Finish

⑥创建controller包,index主页,在pom添加依赖

package com.hx.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class helloSpring {
@RequestMapping
public String index() {
return "index";
}
}
⑦运DemoApplication去网页查看,当8080被占用时,可以在application.properties更改端口号


3、maven创建
①选择maven,选择Java版本,点击next

②配置项目名称路径、标识,点击Finish

③编辑pom文件,导入依赖

<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.0.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
④更改端口,新建controller包,启动类,测试类


package Demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class);
}
}
package Demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class halloSpring {
@RequestMapping
public String index() {
return "index";
}
}
Comments | NOTHING