Thymeleaf--th:each 범람지도 목록

24677 단어 Thymeleaf
@RequestMapping("/4")
	public Object a3(Model model){
		Map<String,User> map1=new HashedMap();
		User user1;
		for(int i=0;i<10;i++) {
			user1=new User();
			user1.setUsername("xiao.li"+i);
			user1.setAge(i);
			user1.setAddress("XXX "+i*2);
			map1.put("J"+i, user1);
		}
		model.addAttribute("userMap",map1);
		List<Map<String,User>> list = new ArrayList<Map<String,User>>();
		User user;
		for(int i=0;i<10;i++) {
			Map<String,User> map=new HashedMap();
				user=new User();
				user.setUsername("xiao.li"+i);
				user.setAge(i);
				user.setAddress("XXX "+i*2);
				map.put("A"+i, user);
			list.add(map);
		}
		model.addAttribute("userList",list);
		return "bb";
	}

<html>
<head>
<meta charset="utf-8">
<title>Insert title heretitle>
head>
<body>
 	<table border="1" >
		<tr><td>No.td>
			<td>userStattd>
			<td>userEntrytd>
			<td>UserObjecttd>
			<td>usernametd>
			<td>agetd>
			<td>addresstd>
		tr>
		<tr th:each="userEntry,userStat:${userMap}">
			<td th:text="${userStat.index}">td>
			<td th:text="${userStat}">td>
			<td th:text="${userEntry}">td>
			<td th:text="${userEntry.value}">td>
			<td th:text="${userEntry.value.username}">td>
			<td th:text="${userEntry.value.age}">td>
			<td th:text="${userEntry.value.address}">td>
		tr>
	table> 
	<br/>
	<table border="1" >
		<tr><td>No.td>
			<td>userStattd>
			<td>userEntrytd>
			<td>UserObjecttd>
			<td>usernametd>
			<td>agetd>
			<td>addresstd>
		tr>
		<tr th:each="userEntry,userStat:${userList}">
		
			<td th:text="${userStat.index}">td>
			<td th:text="${userStat}">td>
			<td th:text="${userEntry}">td>
			<td th:text="${userStat.current['A'+userStat.index]}">td>
			<td th:text="${userStat.current['A'+userStat.index].username}">td>
			<td th:text="${userStat.current['A'+userStat.index].age}">td>
			<td th:text="${userStat.current['A'+userStat.index].address}">td>
		tr>
	table>
body>
html>

좋은 웹페이지 즐겨찾기