目录
目的:学习IDEA+SpringBoot+maven的系统实现
任务 :搭建好IDEA+SpringBoot+maven的系统环境
一、实验目的
目的:学习IDEA+SpringBoot+maven的系统实现
任务 :搭建好IDEA+SpringBoot+maven的系统环境
二、实验要求
1、实验内容与要求:
下载好IntelliJ IDEA开发工具并安装配置。安装成功后输入mvn -version命令查看是否安装成功。
下载maven并配置maven环境,添加阿里云镜像配置。将IDEA中的maven配置为本地已安装好的maven。
掌握SpringBoot项目的三种创建方式。
pom.xml中引入thymeleaf依赖,在classpath:/templates/下新建HTML页面(可采用实验一创建的页面),新建controller进行测试,访问页面后返回success成功数据。
要求通过该实验的练习,理解掌握idea工具的基本使用和SpringBoot框架的基本内容;同时掌握和thymeleaf的基本语法。
2、实验安排方式:上机编码。
三、实验代码
配置:
pom引入thymeleaf依赖
<!--引入thymeleaf的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
配置WebMvcConfig
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/#").setViewName("index");
}
}
配置application.yml
spring:
web:
resources:
static-locations: classpath:/static
ZhuceController:
package com.example.project4;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
class ZhuceController {
@RequestMapping("/注册")
public String test(){
return "注册";
}
}
四、实验结果
图1
图2
图3
五、实验体会
通过这次实验,我学习了如何成功进行IDEA+SpringBoot+maven的系统实现,搭建好IDEA+SpringBoot+maven的系统环境,成功地安装并配置了maven的运行环境,学会了创建springboot的三种方式,并且能将之前的实验结合起来运用。