欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Springboot(一)

程序员文章站 2022-03-09 20:17:09
...

第一个Springboot创建

maven配置略

<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 http://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.1.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.bootstrap01</groupId>
	<artifactId>pbootstrap01-1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>pbootstrap01-1</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-aop</artifactId>
		</dependency>
		<dependency>
		  <groupId>org.springframework.boot</groupId>
		  <artifactId>spring-boot-devtools</artifactId>
		  <optional>true</optional>
		  <scope>true</scope>
		  </dependency>
		<dependency>
          <groupId>org.springframework.boot</groupId>
		  <artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<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>

配置文件 application.properties 

server.port=8080 //端口设置为8080


spring.thymleaf.cache=false  //清除缓存

spring.thymleaf.prefix=classpath:/templates  //查找view资源的根目录为templates

spring.thymleaf.suffix=.html  //查找view的资源的后缀

spring.thymleaf.mode=HTML5  //页面格式HTML5

spring.thymleaf.encoding=utf-8  //采用utf-8编码

spring.thymleaf.servlet.content-type=text/html  文档类型text/html

编写控制器 Controller

 新增package 

Springboot(一)

package com.bootstrap01.controller;

import org.springframework.stereotype.Controller;

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

@Controller
public class indexController{
   @RequestMapping("/")    //...8080/是此处网址
   public String index(){
       return "index";
   }
}

index.html写在src/main/resources/templates下 //对应上文的根目录

运行后结果

      Springboot(一)

 

自用 可能存在不正确处 待后续改正

相关标签: 入门