SpringBoot,日期格式化处理,迭代遍历,域对象操作,URL表达式

4.2日期格式化处理

${#dates.format(key)}(格式化日期)

${#dates.format(date,‘yyyy-MM-dd’)}(自定义格式)

${#dates.year(date)}(取年)

${#dates.month(date)}(取月)

${#dates.day(date)}(取日)

4.3条件判断

th:if

<span th:if="${sex} ==''">
性别:男
</span>
<span th:if="${sex} ==''">
性别:女
</span>

th:switch

<div th:switch="${id}">
	<span th:case="1" >id是1</span>
	<span th:case="2" >id是2</span>
	<span th:case="3" >id是3</span>

</div>
4.4迭代遍历

th:each

@RequestMapping("/show3")
	public String show3(Model model) {
		
		List<Users> list = new ArrayList<>();
		list.add(new Users(01,"pp",22));
		list.add(new Users(02,"pj",23));
		list.add(new Users(03,"jj",24));
		list.add(new Users(04,"jp",25));
		model.addAttribute("list", list);
		return "index3";
	} 
<table border="1">
	<tr>
		<th>id</th>
		<th>name</th>
		<th>age</th>
	</tr>
	<tr th:each="u:${list}">
		
		<td th:text="${u.id}"></td>
			
		<td th:text="${u.name}"></td>
		<td th:text="${u.age}"></td>
	</tr>
</table>

th:each的状态变量

<table border="1">
	<tr>
		<th>id</th>
		<th>name</th>
		<th>age</th>
		<th>index</th>
		<th>size</th>
		<th>count</th>
		<th>even</th>
		<th>odd</th>
		<th>first</th>
		<th>last</th>
	</tr>
	<tr th:each="u,var:${list}">
		
		<td th:text="${u.id}"></td>
		<td th:text="${u.name}"></td>
		<td th:text="${u.age}"></td>
		<td th:text="${var.index}">索引,从0开始</td>
		<td th:text="${var.size}">大小</td>
		<td th:text="${var.count}">计数</td>
		<td th:text="${var.even}">偶数,按索引</td>
		<td th:text="${var.odd}">奇数,按索引</td>
		<td th:text="${var.first}">第一个</td>
		<td th:text="${var.last}">最后一个</td>
		
	</tr>
</table>

th:each遍历map

<table border="2">
	<tr th:each="m:${map}">
		<td th:each="v:${m}" th:text="${v.value.id}"></td>
		<td th:each="v:${m}" th:text="${v.value.name}"></td>
		<td th:each="v:${m}" th:text="${v.value.age}"></td>
	</tr>
</table>
4.5域对象操作

HttpServletRequest

HttpSession

ServletContext

@RequestMapping("/show5")
	public String show5(HttpServletRequest request ) {
			request.setAttribute("request", "----------------request");
			request.getSession().setAttribute("session", "-------------session");
			request.getSession().getServletContext().setAttribute("application","-----------application");
		return "index5";
	} 
Request:<span th:text="${#httpServletRequest.getAttribute('request')}"></span><br/>
Session:<span th:text="${session.session}"></span><br/>
Application:<span th:text="${application.application}"></span
4.6URL表达式

表达式基本语法@{}

URL类型:

绝对路径:

<a th:href="@{http://www.baidu.com}">绝对路径</a>

相对路径:

相对于当前目录的根

<a th:href="@{/index5}">相对路径</a>

相对于服务器的相对路径

<a th:href="@{~/.../...}">相对路径</a>

在URL中实现参数的传递

<a th:href="@{/index5(id=1,name=pj)}">相对路径--传参</a>
@RequestMapping("/{page}")
	public String show5(@PathVariable String page,Integer id,String name,HttpServletRequest request) {
			request.setAttribute("id", id);
			request.setAttribute("name", name);
		return page;
	} 
id:<span th:text="${#httpServletRequest.getAttribute('id')}"></span>
name:<span th:text="${#httpServletRequest.getAttribute('name')}"></span>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值