一、使用场景,页面中,循环遍历,获得控制器穿过来的值。

1.1 控制器

    /**
* 获得所有的图书信息
* @return
*/
@RequestMapping("/turnIndexPage")
public String turnIndexPage(ModelMap modelMap){
Map<String, Object> resultMap = bookService.selectAllBooks();
if (200 == (Integer)resultMap.get("code")){
List<Book> bookList = (List<Book>) resultMap.get("result");
modelMap.addAttribute("bookList",bookList);
return "index";
}
return "404";
}

1.2 HTML页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<title>首页</title> </head> <h1>欢迎登录图书管理系统</h1> <table border="1px solid black" cellspacing="0" >
<tr>
<th>图书编号</th>
<th>名称</th>
<th>价格</th>
<th>作者</th>
<th>日期</th>
<th>类型</th>
<th>操作</th>
</tr> <!-- 1.1 book,起的名字 1.2 后台的值
1. 写在th 标签内部 each 标签 th:each="book: ${bookList}"
2. 直接跳HTML页面,搞不定,跳到后台控制器,在让它跳转到指定的HTML 页面。
-->
<tr th:each="book:${bookList}">
<td th:text="${book.id}"></td>
<td th:text="${book.bookname}"></td>
<td th:text="${book.price}"></td>
<td th:text="${book.autor}"></td>
<td th:text="${book.bookdate}"></td>
<td th:text="${book.booktype}"></td>
<td>
<a th:href="@{deleteBook(id=${book.id})}">删除</a>
<a th:href="@{updateBook(id=${book.id})}">修改</a>
<a href="toAdd">录入</a>
</td>
</tr> </table> </body>
</html>

1.3 跳到后台,再跳到HTML页面。

    /**
*
* 跳转到add 添加页面
* @return
*/
@RequestMapping("/toAdd")
public String toAdd(){
return "add";
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<title>录入书籍</title>
</head>
<body>
<form method="post" action="insertBook">
名称 <input type="text" name="bookname" ><br />
价格 <input type="number" name="price" ><br />
作者 <input type="text" name="autor"><br />
类型 <input type="text" name="booktype" ><br />
<input type="submit" value="提交">
</form> </body>
</html>

二、页面取值。

2.1 控制器

    /**
* 获得要修改的信息
* @param book
* @param modelMap
* @return
*/
@RequestMapping("/updateBook")
public String updateBook(Book book,ModelMap modelMap){ Map oneBook = bookService.getOneBook(book.getId());
if (200 == (Integer) oneBook.get("code")){
modelMap.addAttribute("book",oneBook.get("result"));
return "update";
}else {
return "404";
}
}

2.2 页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post" action="update">
<input type="hidden" name="id" th:value="${book.id}"><br />
名称 <input type="text" name="bookname" th:value="${book.bookname}"><br />
价格 <input type="number" name="price" th:value="${book.price}"><br />
作者 <input type="text" name="autor" th:value="${book.autor}"><br />
类型 <input type="text" name="booktype" th:value="${book.booktype}"><br />
<input type="submit" value="提交">
</form> </body>
</html>

th 表达式的简单使用。的更多相关文章

  1. EL表达式的简单介绍

    EL表达式的简单介绍 一.JSP EL语言定义 E L(ExpressionLanguage)  目的:为了使JSP写起来更加简单. 表达式语言的灵感来自于ECMAScript 和 XPath 表达式 ...

  2. sql server 公共表达式的简单应用(cte)

    一.前言 现在做项目数据访问基本都会选择一种orm框架,它以面向对象的形式屏蔽底层的数据访问形式,让开发人员更集中在业务处理上,而不是和数据库的交互上,帮助我们提高开发效率:例如一些简单的insert ...

  3. Linq和Lamda表达式的简单处理方式

    一 什么是LINQ? LINQ即Language Integrated Query(语言集成查询),LINQ是集成到C#和Visual Basic.NET这些语言中用于提供查询数据能力的一个新特性. ...

  4. EL表达式的简单实用

    EL表达式 EL(Expression Language) 是为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方 ...

  5. 前缀、中缀、后缀表达式以及简单计算器的C++实现

    前缀表达式(波兰表达式).中缀表达式.后缀表达式(逆波兰表达式) 介绍 三种表达式都是四则运算的表达方式,用以四则运算表达式求值,即数学表达式的求解. 前缀表达式 前缀表达式是一种没有括号的算术表达式 ...

  6. Java中Lambda表达式的简单使用

    Lambda表达式是Java SE 8中一个重要的新特性.你可以把 Lambda表达式 理解为是一段可以传递的代码 (将代码像数据一样进行传递).可以写出更简洁.更灵活的代码.作为一种更紧凑的代码风格 ...

  7. (二)Thymeleaf标准表达式之——简单表达式

    2. 标准表达式(Standard Expression Syntax) 标准表达式包含以下几个方面: 简单表达式: 变量表达式: ${...} 选择变量表达式: *{...} 消息表达式: #{.. ...

  8. lambda表达式的简单入门

    前言:本人在看<Java核心技术I>的时候对lamdba表达式还不是太上心,只是当做一个Java 8的特性了解一下而已,可是在<Java核心技术II>里面多次用到,所以重新入门 ...

  9. C# lambda表达式(简单易懂)

    前言 1.天真热,程序员活着不易,星期天,也要顶着火辣辣的太阳,总结这些东西. 2.夸夸lambda吧:简化了匿名委托的使用,让你让代码更加简洁,优雅.据说它是微软自c#1.0后新增的最重要的功能之一 ...

  10. [Swust OJ 322]--东6宿舍灵异事件(中缀表达式转化为后缀表达式的简单运用)

    题目链接:http://acm.swust.edu.cn/problem/322/ Time limit(ms): 1000 Memory limit(kb): 65535     Descripti ...

随机推荐

  1. mac学习Python第一天:安装、软件说明、运行python的三种方法

    一.Python安装 从Python官网下载Python 3.x的安装程序,下载后双击运行并安装即可: Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. MAC 系统一般 ...

  2. MCU变量加载过程

    前言 在开发mcu代码的时候经常会有些疑惑,变量是怎么在编译之后进入单片机的ram区的呢,特别是在使用keil开发的时候.后来在接触gcc编译器和自研的mcu后,终于明白了这个问题.实际上变量编译后被 ...

  3. vmware虚拟IOS系统

    安装虚拟机     --以管理员的身份运行

  4. vue3+TypeScript+vue-router使用

    简单使用 创建项目 vue-cli创建 $npm install -g @vue/cli $vue --version @vue/cli 4.5.15 $vue create my-project 然 ...

  5. CGO封装C语言qsort函数

    封装qsort函数 package qsort /* #include <stdlib.h> typedef int (*qsort_cmp_func_t) (const void* a, ...

  6. SpringBoot 之 配置文件、yaml语法、配置注入、松散绑定

    配置文件 SpringBoot 有两种配置文件格式,二选一即可,官方推荐 yaml: application.properties key=value的格式 application.yaml key: ...

  7. 发布 vscode 插件 Cnblogs Client For VSCode 预览版

    为了方便大家使用 vscode 发布博文,我们做了一个小插件,今天发布预览版,欢迎大家试用并反馈问题与建议. 插件的英文名称是 Cnblogs Client For VSCode,简称是 vscode ...

  8. Centos 7 上 查看MySQL当前使用的配置文件my.cnf的方法

    my.cnf是mysql启动时加载的配置文件,一般会放在mysql的安装目录中,用户也可以放在其他目录加载.总的来说,my.cnf类似与window中my.ini 使用locate my.cnf命令可 ...

  9. 去掉所有包含this或is的行

    题目描述 写一个 bash脚本以实现一个需求,去掉输入中含有this的语句,把不含this的语句输出 示例: 假设输入如下: that is your bag is this your bag? to ...

  10. git clone 失败 ,提示 fatal: unable to access 'https://github.com/xxx.git/': OpenSSL SSL_read: Connection was reset, errno 10054

    怎么解决? 把原来的指令 $ git clone https://github.com/cen-xi/express.git 改成 $ git clone git://github.com/cen-x ...