0
点赞
收藏
分享

微信扫一扫

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目


IDEA支持Spring项目创建向导快速创建项目。

选择需要的模块,向导会联网创建SpringBoot项目

默认生成SpringBoot项目

主程序已经写好,只需要写自己的逻辑

resources文件夹中的目录结构:

static:保存所有的静态资源:js,css,images....

templates:保存所有的模板页面(springboot默认jar包使用嵌入式的Tomcat,默认不支持JSP页面),可以使用模板引擎(freemarker,thymeleaf)

application.properties:SpringBoot应用的配置文件

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目_spring boot

 

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目_spring boot_02

选择spring  web

 

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目_spring_03

 根据选择的组件自动生成的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.0</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.guigu</groupId>
	<artifactId>springbootHelloworld-quick</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>springbootHelloworld-quick</name>
	<description>springbootHelloworld-quick</description>
	<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-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

编写controller: 

//这个类的所有方法返回的数据直接写给浏览器(如果是对象转为json数据)
@ResponseBody
@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "hello,worldquick";
    }
}

 运行:

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目_spring boot_04

 

【尚硅谷SpringBoot笔记】使用SpringInitializer快速创建SpringBoot项目_intellij-idea_05

举报

相关推荐

0 条评论