Thymeleaf 对象空值处理

前端代码:

单例实体对象空值处理:

<div clas="form-row">
				<div class="form-group col-md-6">
					<label for="name" class="col-sm-3 control-label">表名称</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="name"
							id="name" readonly="readonly" th:value="${entity?.name}"/>
					</div>
				</div>
				<div class="form-group col-md-6">
					<label for="name" class="col-sm-3 control-label">表名</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="code"
							id="code" readonly="readonly" th:value="${entity?.code}" />
					</div>
				</div>
			</div>
			<div clas="form-row">
				<div class="form-group col-md-6">
					<label for="name" class="col-sm-3 control-label">实体名称</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="entity"
							id="entity" readonly="readonly" th:value="${entity?.entity}"/>
					</div>
				</div>
				<div class="form-group col-md-6">
					<label for="name" class="col-sm-3 control-label">描述</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="comment"
							id="comment" readonly="readonly" th:value="${entity?.comment}"/>
					</div>
				</div>
			</div>

对象集合空值处理:

<table class="table table-striped">
				<tr>
					<th class="col-md-1">名称</th>
					<th class="col-md-1">字段名称</th>
					<th class="col-md-1">数据类型</th>
					<th class="col-md-1">长度</th>
					<th class="col-md-1">精度</th>
					<th class="col-md-1">是否必填</th>
					<th class="col-md-1">是否主键</th>
					<th class="col-md-1">默认值</th>
					<th class="col-md-1">注释</th>
					<th class="col-md-2">操作</th>
				</tr>
				<!--Thymeleaf迭代语句each  -->
				<tr th:each="obj : ${bindColumns}">
					<td th:text="${obj?.name}"></td>
					<td th:text="${obj?.code}"></td>
					<td th:text="${obj?.type}"></td>
					<td th:text="${obj?.length}"></td>
					<td th:text="${obj?.decimal}"></td>
					<td th:text="${obj?.required}"></td>
					<td th:text="${obj?.primary}"></td>
					<td th:text="${obj?.defaultValue}"></td>
					<td th:text="${obj?.comment}"></td>
					<td><a th:href="@{/api/table/unbind(sid=${obj?.sid})}"
						class="btn btn-info btn-sm">解绑</a></td>
				</tr>
			</table>

后台代码:

// 绑定页面
	@RequestMapping(value = "/binding")
	public String binding(Model model, String sid) {
		// 表数据查询
		Table entity = service.selectByPrimaryKey(sid);
		model.addAttribute("entity", entity);
		// 表涉及已绑定字段查询
		Map<String, Object> bindParame = new HashMap<String, Object>();
		bindParame.put("busTableId", sid);
		List<Column> bindColumns = columnService.select(bindParame);
		model.addAttribute("bindColumns", bindColumns);
		// 表涉及未绑定字段查询
		Map<String, Object> unBindParame = new HashMap<String, Object>();
		unBindParame.put("notBusTableId", sid);
		List<Column> unBindColumns = columnService.select(unBindParame);
		model.addAttribute("unbindColumns", unBindColumns);

		return "table/binding";
	}

猜你喜欢

转载自blog.csdn.net/zhouzhiwengang/article/details/90232406
今日推荐