栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用带注释的@Controllers的AbstractWizardFormController

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用带注释的@Controllers的AbstractWizardFormController

@Controller是定义表单/向导的更灵活的方法。您应该根据请求的路径/请求参数/请求方法将方法映射到请求。因此,您可以根据需要定义向导的步骤(而不是定义视图列表并根据某些必需的“
step”参数处理请求)(还将更透明地处理命令对象)。这是模拟经典AWFC功能的方法(这仅是一个示例,您可以做很多事情)。

@Controller@RequestMapping("/wizard.form")@SessionAttributes("command")public class WizardController {        @RequestMapping    public String getInitialPage(final ModelMap modelMap) {        // put your initial command        modelMap.addAttribute("command", new YourCommandClass());        // populate the model Map as needed        return "initialView";    }        @RequestMapping(params = "_step=1")    public String processFirstStep(final @ModelAttribute("command") YourCommandClass command,  final Errors errors) {        // do something with command, errors, request, response,        // model map or whatever you include among the method        // parameters. See the documentation for @RequestMapping        // to get the full picture.        return "firstStepView";    }        @RequestMapping(method = RequestMethod.POST)    public String processPage(@RequestParam("_page") final int currentPage,        final @ModelAttribute("command") YourCommandClass command,        final HttpServletResponse response) {        // do something based on page number        return pageViews[currentPage];    }        @RequestMapping(params = "_finish")    public String processFinish(final @ModelAttribute("command") YourCommandClass command,          final Errors errors,          final ModelMap modelMap,          final SessionStatus status) {        // some stuff        status.setComplete();        return "successView";    }    @RequestMapping(params = "_cancel")    public String processCancel(final HttpServletRequest request,          final HttpServletResponse response,          final SessionStatus status) {        status.setComplete();        return "canceledView";    }}

我试图改变方法签名,以便您对我提到的灵活性有所了解。当然,还有很多其他功能:您可以在中使用请求方法(GET或POST)

@RequestMapping
,可以定义带有注释的方法
@InitBinder
,等等。

编辑: 我有一个固定的未映射方法(顺便说一句,您需要确保您没有模棱两可的映射-可以映射到多个方法的请求-或未映射的请求-
无法被映射的请求映射到任何方法)。还可以查看@ SessionAttributes,@
SessionStatus和@ModelAttribute,它们也是完全模拟经典AWFC的行为所必需的(我已经编辑了代码以使这一点变得清楚)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409956.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号