@Controller
@RequestMapping("/order")
public class OrdersController {
@Autowired
private OrdersService ordersService;
@PostMapping(produces = "application/json;charset=utf-8")
@ResponseBody
public String add(Orders orders ) throws Exception {
ordersService.insert(orders);
return "成功";
}
@GetMapping
public String index(){
return "order_add";
}
@ExceptionHandler(DbException.class)
public String handlerDbException(Exception ex, Model model){
model.addAttribute("err",ex.getMessage());
return "err1";
}
@ExceptionHandler(DataException.class)
public ModelAndView handlerDbException2(Exception ex, Model model){
model.addAttribute("err",ex.getMessage());
return new ModelAndView("err2");
}