zoukankan      html  css  js  c++  java
  • Sping 补充完成修改功能

    1.视图层完整示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <form action="#" th:action="@{/update/{id}(id=${user.id})}" th:object="${user}" method="post" >
        <label for="name" >姓名</label>
        <input type="text" th:field="*{name}" id="name" placeholder="Name" >
         
        <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}" ></p>
         
        <label for="age">年龄</label>
        <input type="text" th:field="*{age}"   id="age" placeholder="age" name="age">
         
        <p th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></p>
         
        <label for="email">邮箱</label>
        <input type="text" th:field="*{email}" id="email" placeholder="Email">
         
        <p th:if="${#fields.hasErrors('email')}" th:errors="*{email}" ></p>
         
        <input type="submit" value="修改">
    </form>

      2.控制器层代码

    1
    2
    3
    4
    5
    6
    7
    8
    @PostMapping("/edit/{id}")
    public String editUser(@Valid User user,BindingResult bindingResult) {
         
        if(bindingResult.hasErrors()) {
            return "update-user";
        }
        return "update-user";
    }
  • 相关阅读:
    Android 基础-2.0 拔打电话号码
    Android 基础-1.0 按钮4种点击事件
    Android Studio 技巧备忘
    Android Studio Mac版快捷键
    face++静态库转为动态库之二
    Podfile语法参考
    iOS 高级去水印,涂鸦去水印
    vector 用法小例子
    UltraCompare 激活
    linux 日志查询
  • 原文地址:https://www.cnblogs.com/q2546/p/11107843.html
Copyright © 2011-2022 走看看