SpringBoot---基本配置

1、首先在pom.xml添加对HTML的相关依赖

/**
 * pom.xml文件
 */
<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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>**

2、在application.yml文件添加SpringBoot相关配置

spring:

  thymeleaf:
    prefix: classpath:/templates/

注意:application.yml 如果是空文件,则默认视图文件存放在
templates文件下,资源文件存放在static目录下,由于SpringBoot对jsp支持不太友好,一般使用自带的标签实现数据的赋值



在Controller里面写跳转HTML页面方法

@Controller  //注意这里必须为Controller
public class HelloController {

    /**
     * 本地访问内容地址 :http://localhost:8080/lmycc/hello
     * @param map 传递参数
     * @return
     */
    @RequestMapping("/hello")
    public String helloHtml(HashMap<String, Object> map) {
        map.put("hello", "欢迎进入HTML页面");
        return "/index";
    }
}
posted on 2018-09-06 11:02  csguo  阅读(439)  评论(0编辑  收藏  举报