【springboot shiro】(3)Spring Boot快速入门

1.1. 建立Maven项目,导入spring boot父工程

3-1.png 3-2.png 3-3.png

修改pom.xml: `` <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">

4.0.0

org.springframework.boot

spring-boot-starter-parent

1.5.4.RELEASE

com.itheima

springboot-shiro

0.0.1-SNAPSHOT

``

1.2. 导入web支持 修改pom.xml ``

org.springframework.boot

spring-boot-starter-web

``

1.3. 编写测试Controller类

`` package com.itheima.controller;

import org.springframework.stereotype.Controller;

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

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

@Controller

public class UserController {

//测试方法

@RequestMapping("/hello")

@ResponseBody

public String hello(){

System.out.println("UserController.hello()");

return "ok";

}

} ``

1.4. 编写SpringBoot启动类 `` package com.itheima; import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

1.5. 导入thymeleaf页面模块 l 引入thymeleaf依赖

org.springframework.boot

spring-boot-starter-thymeleaf

``

l 在Controller添加测试方法

``

//测试thymeleaf

@RequestMapping("/testThymeleaf")

public String testThymeleaf(Model model){

//把数据存入model

model.addAttribute("name", "黑马程序员");

//返回test.html

return "test";

} ``

l 建立test.html页面

在src/main/resource目录下创建templates目录,然后创建test.html页面

``

测试Thymeleaf的使用

``

在thymeleaf3.0以前对页面标签语法要求比较严格,开始标签必须有对应的结束标签。

如果希望页面语法不严谨,但是也能够运行成功,可以把thymeleaf升级为3.0或以上版本。

升级thymeleaf3.0.2版本: ``

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

<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>

<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>

``

已有 0 条评论

    欢迎您,新朋友,感谢参与互动!