我正在尝试借助 ControllerAdvice 将 ModelAttribute 值添加到同一应用程序中的不同页面,但输出消息未显示在 jsp 页面上。
服务控制器.java
package com.test;
@Controller
public class ServicesController {
@RequestMapping("/serviceUser")
public String dis() {
return "input";
}
}
ProductsController.java
package com.test;
@Controller
public class ProductsController {
@RequestMapping("/products")
public ModelAndView display()
{
ModelAndView m=new ModelAndView("output");
return m;
}
}
GlobalAdviceHandler.java
package com.test;
@ControllerAdvice
public class GlobalAdviceHandler {
@ModelAttribute
public void show(Model model) {
model.addAttribute("msg", "hello world");
}
}
输入.jsp
<body>
<p>Services </p>
${msg}
</body>
输出.jsp
<body>
<p>Products </p>
${msg}
</body>
先感谢您!!