zoukankan      html  css  js  c++  java
  • thymeleaf的基本用法

    添加thymelleaf依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    1.例如登录验证 ,前端代码例子

    <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org" >

    <head>
    <!-- 页面meta -->
    <meta charset="utf-8">

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/css/theme-chalk.css">
    <link rel="stylesheet" href="/css/login_style.css">
    </head>


    <form class="loginForm clear" th:action="@{/loginverify}" method="post">
    <div class="loginMain">
    <div class="loginlogo"></div>
    <p style="color:red" th:text="${message}" th:if="${not #strings.isEmpty(message)}"></p>
    <div class="loginCon">
    <span class="el-form-item">

    <span class="userIcon"></span>
    <span class="el-input">
    <input class="el-input__inner" name="username" required="" autofocus="" placeholder="账号"/>
    </span>
    </span>


    2.后端代码建议使用modelandview
    public ModelAndView postViewLogin(ModelAndView mv, HttpServletRequest request, HttpSession session) throws NoSuchAlgorithmException {
    String username = request.getParameter("username")
    User user = userDao.findAllByUsername(username);
    if(user==null){
    mv.addObject("message","用户名或密码错误");
    mv.setViewName("login");
    return mv;

    }
    }

  • 相关阅读:
    L2-1 功夫传人 (25分)
    7-11 家庭房产(25 分)
    7-11 玩转二叉树 (25分)
    7-10 排座位 (25分)
    7-12 最长对称子串 (25分)
    7-10 树的遍历 (25分)
    STL
    Max Gcd
    水果
    Rails
  • 原文地址:https://www.cnblogs.com/liushuaibiao/p/13163726.html
Copyright © 2011-2022 走看看