Spring MVC Study Guide P62-63 mentioned Flash attributes, you can use POST to pass values when redirecting, the Controller code is posted for you:
@RequestMapping(value = "/product_save", method = RequestMethod.POST)
public String saveProduct(ProductForm productForm, RedirectAttributes redirectAttributes) {
logger.info("saveProduct called");
// no need to create and instantiate a ProductForm
// create Product
Product product = new Product();
product.setName(productForm.getName());
product.setDescription(productForm.getDescription());
try {
product.setPrice(Float.parseFloat(productForm.getPrice()));
} catch (NumberFormatException e) {
}
// add product
Product savedProduct = productService.add(product);
redirectAttributes.addFlashAttribute("message", "The product was successfully added.");
return "redirect:/product_view/" + savedProduct.getId();
}
"To use Flash properties, you must have one in the Springmvc configuration file <annotation-driven/>元素。然后,还必须在方法上添加一个新的参数类型org.springframework.web.servlet.mvc.support.RedirectAttributes"
I think this is a design problem. Since you have decided to redirect, of course you cannot use the post method. Of course, you can also use httpclient and other tools to simulate posts. This is a project in progress, right?
I agree with the opinion above, there is a problem in terms of design. Since I have the need to redirect to the past, why limit myself to only accepting get requests?
Spring MVC Study Guide P62-63 mentioned Flash attributes, you can use POST to pass values when redirecting, the Controller code is posted for you:
"To use Flash properties, you must have one in the Springmvc configuration file
<annotation-driven/>
元素。然后,还必须在方法上添加一个新的参数类型org.springframework.web.servlet.mvc.support.RedirectAttributes
"I think this is a design problem. Since you have decided to redirect, of course you cannot use the post method. Of course, you can also use httpclient and other tools to simulate posts. This is a project in progress, right?
I agree with the opinion above, there is a problem in terms of design.
Since I have the need to redirect to the past, why limit myself to only accepting get requests?
Your approach is impossible. Spring redirection does not support changing GET to POST