Как отобразить страницу сообщения об ошибке и весной - PullRequest
0 голосов
/ 22 апреля 2020

Я пытаюсь повторить возраст ошибки, аналогичный приведенному ниже. Кажется, я не могу найти хороших ресурсов о том, как это сделать. Должен ли код go войти в контроллер или мне нужно создать отдельный контроллер для этой и новой страницы jsp?

Любая помощь будет высоко ценится,

Заранее спасибо !!!!!

ниже находится страница, которую я пытаюсь создать error page I am trying to create

Вот мой диспетчер заказов

package com.sales.controllers;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.sales.models.Customer;
import com.sales.models.Order;
import com.sales.models.Product;
import com.sales.services.CustomerService;
import com.sales.services.OrderService;
import com.sales.services.ProductService;

@Controller
public class OrderController {

    @Autowired
    ProductService ps;

    @Autowired
    CustomerService cs;

    @Autowired
    OrderService os;

    private Product prod;
    private Customer cust;

    @RequestMapping(value = "/showOrders.html")
    public String listOrders(Model model) {

        ArrayList<Order> orders = os.findAll();
        model.addAttribute("allOrders", orders);

        ArrayList<Customer> cust = cs.findAll();
        model.addAttribute("ordrs", cust);
        return "allOrders";
    }

    @RequestMapping(value = "/newOrder.html", method = RequestMethod.GET)
    public String addPerson(Model model) {
        ArrayList<Customer> customer = cs.findAll();
        ArrayList<Product> product = ps.findAll();

        Map<Long, String> customers = new LinkedHashMap<Long, String>();
        for (Customer c : customer) {
            customers.put(c.getcId(), c.getcName());

            model.addAttribute("customers", customers);

            Map<Long, String> products = new LinkedHashMap<Long, String>();
            for (Product p : product) {
                products.put(p.getpId(), p.getpDesc());

                model.addAttribute("products", products);
            }

        }
        Order o = new Order();

        model.addAttribute("orderList", o);

        return "addOrder";

    }

    @RequestMapping(value = "/newOrder.html", method = RequestMethod.POST)
    public String addOrderPost(@Valid @ModelAttribute("orderList") Order o, BindingResult result) {

        System.out.println("In order add");

        if (result.hasErrors()) {
            return "addOrder";
        }

        prod = ps.findOne(o.getProd().getpId());
        cust = cs.findOne(o.getCust().getcId());

        o.setProd(prod);
        prod.setQtyInStock(prod.getQtyInStock() - (o.getQty()));

        os.save(o);

        return "redirect:showOrders.html";

    }



}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...