web入门,软件IntelliJ IDEA,maven
1.新建文件
new module
选择Spring Initializr
Type 选择 maven language 选择Java
Group 更改自己的项目名称为com.itheima ,
Aetifact 更改为自己的名称 springboot-web-quickstart
Java选择为11
点击Next
选择Spring Boot为稳定版2.7.15
在左侧Dependencies中选择 web -> 单击Spring web框
src->main->java->com.itheima. springboot-web-quickstart ->controller文件夹下点击new -JavaClass 新建JAVA类hellocontroller
文件创建完成。
2.文件介绍
1pom.xml
org.springframework.boot
spring-boot-starter-parent
2.7.15
<groupId>com.itheima</groupId>
<artifactId>springboot-web-quickstart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-web-quickstart</name>
<description>springboot-web-quickstart</description>
<properties>
<java.version>11</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
org.springframework.boot spring-boot-maven-plugin 2. src->main->java->com.itheima. springboot-web-quickstart -文件夹下的 SpringbootWebQuickstart1Application文件 //启动类。启动springboot工程 @SpringBootApplication public class SpringbootWebQuickstart1Application {
public static void main(String[] args) {
SpringApplication.run(SpringbootWebQuickstart1Application.class, args);
}
}
从此main对项目启动
3.hellocontroller类文件
//请求处理类
@RestController
public class hellocontroller {
@RequestMapping(“/hello”) //映射,绑定关键字/hello
public String hello(){ //主要操作
System.out.println(“Hello world”);
return “hello world”;
}
}
// 两个@会自动弹出相关的import
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
3项目执行
SpringbootWebQuickstart1Application文件点击主函数操作后,spring项目执行,端口为8080.
登录网址 http://localhost:8080/hello
网址执行输出hello world
IntelliJ IDEA也输出 hello world
入门结束