话不多说直接上代码:
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();
}
这都不点赞 说明你电脑不行