码迷,mamicode.com
首页 > 其他好文 > 详细

Thymeleaf学习记录(5)--运算及表单

时间:2018-12-24 16:29:25      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:return   mit   标记   The   meta   scribe   some   ppi   new   

Thymeleaf文本及预算:

  • 字面
    • 文本文字:‘one text‘‘Another one!‘,...
    • 号码文字:0343.012.3,...
    • 布尔文字:truefalse
    • 空字面: null
    • 文字标记:onesometextmain,...
  • 文字操作:
    • 字符串连接: +
    • 文字替换: |The name is ${name}|
  • 算术运算:
    • 二元运算符:+-*/%
    • 减号(一元运算符): -
  • 布尔运算:
    • 二元运算符:andor
    • 布尔否定(一元运算符): !not
  • 比较和等价:
    • 比较:><>=<=gtltgele
    • 等价:==!=eqne

示例如下:

技术分享图片

表单提交

增加subscribe.html页面:

内容如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="#" th:action="@{/Hello/subscribe}"  th:object="${user}" method="post">
    <fieldset>
        <input type="text" name="name" />
        <input type="submit" value="名称提交"/>
    </fieldset>
</form>

<form th:attr="action=‘#‘,action=@{/Hello/subscribe},object=${user},method=‘post‘">
    <fieldset>
        <input type="text" name="age" />
        <input type="submit" value="年龄提交"/>
    </fieldset>
</form>
</body>
</html>

如下所示:

技术分享图片 

后台Controller增加:

@RequestMapping(value = "GetPage3", method = RequestMethod.GET)
public String getsubscribe( ) {
    return "subscribe";
}

@RequestMapping(value = "subscribe", method = RequestMethod.POST)
public String getPage1ByName(@ModelAttribute User  user) {
    ModelMap map = new ModelMap();
    user.getName();
    user.getAge();
    map.addAttribute("user",user);
    return "page1";
}

如下所示:

技术分享图片

运行结果:

技术分享图片

名称提交:

技术分享图片

年龄提交:

技术分享图片

 

 

Thymeleaf学习记录(5)--运算及表单

标签:return   mit   标记   The   meta   scribe   some   ppi   new   

原文地址:https://www.cnblogs.com/feichangnice/p/10168510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!