一、集成SpringMVC

1. 创建父项目

创建新工程

父工程无需选择依赖

 

2. 创建第一个子模块

选择spring web依赖

2.1. 项目结构

 

2.2. 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.13</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.wzh</groupId>
	<artifactId>_1_springboot</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>_1_springboot</name>
	<description>_1_springboot</description>
	<properties>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<!--web依赖-->
		<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>

2.3. 添加Controller代码

package com.wzh._1_springboot.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        return "hello world!";
    }
}

 

2.4. 浏览器访问http://localhost:8080/hello

 

3. 自定义banner

3.1. 在resources目录下创建banner.txt文件

 

             _
__      _____| |__     __ _ _ __  _ __
\ \ /\ / /_  / '_ \   / _` | '_ \| '_ \
 \ V  V / / /| | | | | (_| | |_) | |_) |
  \_/\_/ /___|_| |_|  \__,_| .__/| .__/
                           |_|   |_|             _
__      _____| |__     __ _ _ __  _ __
\ \ /\ / /_  / '_ \   / _` | '_ \| '_ \
 \ V  V / / /| | | | | (_| | |_) | |_) |
  \_/\_/ /___|_| |_|  \__,_| .__/| .__/
                           |_|   |_|

 

3.2. 项目启动效果

 

以上


posted @ 2023-07-19 09:33  在路上的Spike007  阅读(26)  评论(0)    收藏  举报