【发布时间】:2020-03-05 20:33:35
【问题描述】:
我想在表中保存一条新记录 - 正文。 我使用 Spring Boot 和 HTML。 所以它看起来在 HTML:
<select id="bodiesList" multiple="multiple" class="selector">
<option th:each="b : ${bodies}"
th:value="${b.id}"
th:text="${b.name}"></option>
</select>
控制器:
@Controller
@RequestMapping("/general")
public class OrderController {
@Autowired
@Qualifier("orderServiceImpl")
private OrderService orderService;
@GetMapping(value = "/list")
public String get(Model theModel) {
theModel.addAttribute("orders", orderService.getOrders());
return "general/index";
}
@GetMapping(value = "/showFormForAdd")
public String add(Model theModel) {
Orders orders = new Orders();
List<Body> body = orderService.getBody();
theModel.addAttribute("bodies", body);
theModel.addAttribute("order", orders);
return "general/create-orders";
}
@PostMapping(value = "/saveOrders")
public String addOrders(@ModelAttribute("order") Orders orders, @RequestParam("picture") MultipartFile file) throws IOException {
orders = orderService.uploadOrders(orders, file);
orderService.save(orders);
return "redirect:/general/list";
}
}
但不在数据库中,不在我的列中,没有保存任何内容。
我的代码中需要修复什么?
【问题讨论】:
标签: java html spring thymeleaf