Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取@PathVariableValue并将其添加到@ModelAttribute字符串值?_Java_Spring Mvc - Fatal编程技术网

Java 如何获取@PathVariableValue并将其添加到@ModelAttribute字符串值?

Java 如何获取@PathVariableValue并将其添加到@ModelAttribute字符串值?,java,spring-mvc,Java,Spring Mvc,我有: 如何通过从@PathVariable中获取特定id\u值来查询客户id\uuuuuuuuu{某些id\u值}: @RequestMapping public String someMethod(final RedirectAttributes redirectAttributes) { redirectAttributes.addFlashAttribute("customer_id" + someId, customerWithThatId); return "redir

我有:

如何通过从
@PathVariable
中获取
特定id\u值
来查询
客户id\uuuuuuuuu{某些id\u值}

@RequestMapping
public String someMethod(final RedirectAttributes redirectAttributes) {

   redirectAttributes.addFlashAttribute("customer_id" + someId, customerWithThatId);
   return "redirect:showcustomer.html";    
}

通常,您不需要从
@PathVariable
中填充
@ModelAttribute
。您需要从那里获取
id
,然后从数据库中获取模型。如下所示:

@RequestMapping
public String showCustomer(@ModelAttribute("customer_id_{howToTakeTheIdFromPathVariable?}") Customer customer, @PathVariable("customerId") String customerId) {
    // ...
}

从Spring 3.1开始,使用
@PathVariable
注释的参数将自动暴露于模型中,因此无需特殊处理

RedirectAttributes
flash作用域属性也是如此

重定向后,flash属性将自动添加到为目标URL提供服务的控制器的模型中


我需要从flash作用域属性中获取值,而不是从数据库中获取值……说来话长
@Autowired
private CustomerRepository customerRepository;

@RequestMapping("/show/customer/customer_id_{customerId}")
public String showCustomer(@PathVariable("customerId") long customerId) {
    Customer customer = customerRepository.get(customerId);
    ......
}