2

コントローラでインスタンス化する特別なエンティティがあります。Duiringリクエストは、ハンドラーのパラメーターに渡す必要があります。

@Controller
@Scope("session")
public class HomeController {
    @Autowired
    Context context; // this thing should be passed into request.
    //context field from controller should be passed into request parameter
    //in order to set request attributes properly.
    //The instance of CommonRequest class should have reference to the context during
    //mapping HTTP request into CommonRequest object.
    @RequestMapping(value = "/do_smth", method = RequestMethod.POST)
    public void doSmth(CommonRequest request) {

    }
}

このトリックを行う方法はありますか?

4

1 に答える 1

1
public void doSmth(CommonRequest request) {
    //context field from controller should be passed into request parameter.
    request.setAttribute("context",context); // if you want to get context back, use Context context = (Context)request.getAttribute("context");
}
于 2012-06-13T09:32:14.757 に答える