关于thymeleaf下拉框(select option)的回显选中问题

话不多说直接上代码:

HTML代码:(我用的学生表和班级表)

<select name="ccid">
	<option th:each="cla:${cla}"
		th:selected="${s.ccid == cla.cid}"
		th:value="${cla.cid}" th:text="${cla.cname}">
	</option>
</select>`

Controler代码:

// 查询数据 并跳转到upd.html
	@RequestMapping(value = "upd1")
	public String GirlFindONe1(Model model, HttpServletRequest req) {
		//我的id都是String型的
		String id = req.getParameter("id");
		//查询学生表的一条数据 spservice是StuService的对象
		Springboot sp = stuservice.findById(id);
		model.addAttribute("s", sp);
		//查询班级  claservice是ClaService的对象
		Iterable<Cla> cla = claservice.findAll();
		model.addAttribute("cla", cla);
		return "pages/Springboot/upd";
	}

ClaService代码:

//查询全部数据
public List<Cla> findAll(){
		return cladao.findAll();
	}

StuService代码:

//查询单条数据
	public Springboot findById(String id) {
		return studao.findById(id).get();
	}

这都不点赞 说明你电脑不行

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值