我正在尝试从spring控制器中的一个url重定向到另一个url但是它自己将url更改为我提到的以外的其他url并给出了404错误
我的弹簧控制器如下:
@Controller
@SessionAttributes({ "dataObject", "userId" , "screen" , "scrUpdate" })
public class ScreenDesignerController extends BaseController {
/**
* Injected screen designer service class.
*/
@Autowired
private ScreenDesignerService screendiService;
@RequestMapping(value = "EditScreen", method = RequestMethod.POST)
public String editScreen(Model model , @RequestBody String tempdata , RedirectAttributes ra) throws Exception {
ScreenUpdate scrUpdate;
try {
logger.info("in editscreen post method: ");
scrUpdate = screendiService.formatScreen(tempdata);
logger.info("screenID: " + scrUpdate.getScreenId());
ra.addFlashAttribute("scrUpdate", scrUpdate);
} catch (Exception e) {
logger.error("in editscreen post method: " + e);
}
return "redirect:/UpdateScreen";
}
/**
* Controller get method for Screen Update.
* @param model Model.
* @param scrUpdate to create layout for updating screen.
* @return the template name
* @throws Exception if anything goes wrong
*/
@RequestMapping(value = "UpdateScreen", method = RequestMethod.GET)
public final String updateScreen(Model model, @ModelAttribute("scrUpdate") ScreenUpdate scrUpdate) throws Exception {
try {
model.addAttribute("screen", scrUpdate);
logger.info("Update Screen GET");
} catch (Exception e) {
logger.error("inside GET Catch UpdateScreen: " + e);
}
return "ScreenDesigner/UpdateScreen";
}
答案 0 :(得分:0)
查看代码看起来你要重定向的GET方法是期望(ScreenUpdate)对象作为模型属性请更改get方法如下
@RequestMapping(value = "UpdateScreen", method = RequestMethod.GET)
public final String updateScreen(Model model) throws Exception {
model.addAttribute("screen", scrUpdate);
return "ScreenDesigner/UpdateScreen";
}
如果你想将ScreenUpdate对象发送到这个GET方法,你可以用post方法(editScreen方法)在session中添加它,然后在你的get方法中获取它。