前端笔记-thymeleaf获取及回显select数据(combox)

如下:

以及回显

前端代码如下:

<div class="form-group">
	<label>选课</label>
	<select name="courseID" class="form-control input1">
		<option value="">请选择</option>
			<option
				th:each="courseItem : ${courseList}"
				th:value="${courseItem.id}"
				th:text="${courseItem.id} +':'+${courseItem.name}"
				th:selected="${people!=null}?${courseItem.id eq people.courseId.id}"
			></option>
		</select>
</div>

从中可以看到,在使用的是select标签,

回显使用th:selected进行判断,当xxID eq等于 xxxID的时候选中。

显示的th:text为,传到后端的数据为th:value。

后端接收如下:

这里直接存储String类型,因为在本表中course和student的ID都是存储String类型。

发布了1312 篇原创文章 · 获赞 2429 · 访问量 185万+

猜你喜欢

转载自blog.csdn.net/qq78442761/article/details/104890159
今日推荐