• 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;

    }
    }

  • 相关阅读:
    js 获取表单和页面控件数据
    vue axios upload 多个文件
    vue antd axios 使用
    antd vue 修改modal弹窗样式
    线性回归的改进-岭回归
    线性回归
    00
    集成学习方法之随机森林
    决策树
    第十讲 让机器像人类一样学习--强化学习-----学习总结
  • 原文地址:https://www.cnblogs.com/liushuaibiao/p/13163726.html
Copyright © 2020-2023  润新知