场景
在进行新增和编辑时,如果后台有传递到前端值,则根据值的内容选中下拉框。
实现
<select class="form-control" name="businessInitiator" id="businessInitiator">
<option id="yuanliaoInitiator" th:selected="${refundOrder != null && refundOrder.businessInitiator != null && refundOrder.businessInitiator == '原料立库'}" value="原料立库"><span th:text="原料立库"></span></option>
<option id="qingjieInitiator" th:selected="${refundOrder != null && refundOrder.businessInitiator != null && refundOrder.businessInitiator == '清洁车间'}" value="清洁车间"><span th:text="清洁车间"></span></option>
<option id="zhengjiInitiator" th:selected="${refundOrder != null && refundOrder.businessInitiator != null && refundOrder.businessInitiator == '正极车间'}" value="正极车间"><span th:text="正极车间"></span></option>
<option id="fujiInitiator" th:selected="${refundOrder != null && refundOrder.businessInitiator != null && refundOrder.businessInitiator == '负极车间'}" value="负极车间"><span th:text="负极车间"></span></option>
<option value="" disabled selected hidden>选择退货发起方</option>
</select>
后台返回数据代码:
@Description("获取新增或者编辑界面")
@RequestMapping("/toAddRefundOrder")
public String toAddRefundOrder( int id, Model model){
if ( id != 0){
//如果是编辑操作,查询出当前退货单
WmsRefundOrder refundOrder = refundOrderService.getById(id);
model.addAttribute("refundOrder",refundOrder);
}
return "refund/addRefundOrder.html";
}
标签:Thymelaf,退货,回显,toAddRefundOrder,编辑,refundOrder,model,id,select From: https://blog.51cto.com/BADAOLIUMANGQZ/6115095