spring boot 结合thymeleaf登录展示页面

本文介绍了如何在Spring Boot项目中结合Thymeleaf创建登录展示页面。首先,展示了工程的pom.xml配置和yml文件设置。接着,提到了Controller的部分,虽然用户相关代码未给出,但强调了登录界面设计时需要注意后台传递参数的重要性,以避免Thymeleaf找不到界面的错误。此外,还推荐了一个Thymeleaf的学习资源。
摘要由CSDN通过智能技术生成
  1. 先搭建spring boot工程 ,pom文件如下
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>Hello</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Hello Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
  </parent>
  <dependencies>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</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>
    <!-- 减少严格的校验 -->
    <dependency>
      <groupId>net.sourceforge.nekohtml</groupId>
      <artifactId>nekohtml</artifactId>
      <version>1.9.22</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>
  </dependencies>
  <build>
    <finalName>Hello</finalName>
  </build>
</project>

yml 文件如下

#目的是为了去除thymeleaf严格的校验,不然html界面写的不严谨就会报错
spring:
    thymeleaf:
          mode: LEGACYHTML5
          encoding: utf-8
          content-type: text/html
          cache: false

controller 如下:

package com.wshh.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;

/**
 * 这是一个实体类的测试类
 *
 *
 *  @version 1.0,2017-9-24 10:02:08
 */
@Controller
public class HelloWorldController {

    @RequestMapping("/index")
    public String  index(Model model){
        User user = new User();
        user.setUsername("张三");
        user.setId(1);
        user.setTelephone("123456789");
        user.setPassword("@#$%^&*()&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值