{"id":1648,"date":"2017-07-14T17:01:21","date_gmt":"2017-07-14T09:01:21","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1648"},"modified":"2017-07-14T17:01:21","modified_gmt":"2017-07-14T09:01:21","slug":"basecommandcontroller%ef%bc%88%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4%e6%8e%a7%e5%88%b6%e5%99%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1648","title":{"rendered":"BaseCommandController\uff08\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\uff09"},"content":{"rendered":"<p>\n\tBaseCommandController\uff08\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\uff09\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\u63d0\u4f9b\u4e86\u521b\u5efa\u547d\u4ee4\u5bf9\u8c61\u548c\u901a\u8fc7HTTP\u8bf7\u6c42\u53c2\u6570\u5bf9\u547d\u4ee4\u5bf9\u8c61\u8fdb\u884c\u7ed1\u5b9a\u548c\u6821\u9a8c\u7684\u529f\u80fd\u65b9\u6cd5\u3002\n<\/p>\n<p>\n\tAbstractCommandController \u62bd\u8c61\u547d\u4ee4\u63a7\u5236\u5668\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u5b9e\u73b0\u4e00\u4e2a\u7ebf\u6027\u7684\u6d41\u7a0b\uff0c\u9996\u5148\u521b\u5efa\u547d\u4ee4\u5bf9\u8c61\uff0c\u7136\u540e\u7ed1\u5b9a\u6821\u9a8c\u547d\u4ee4\u5bf9\u8c61\uff0c\u6700\u540e\u4f20\u9012\u547d\u4ee4\u5bf9\u8c61\u5230\u62bd\u8c61\u7684\u65b9\u6cd5\u8fdb\u884c\u4e1a\u52a1\u903b\u8f91\u7684\u5904\u7406\u3002\u5b50\u7c7b\u5e94\u8be5\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u5b9e\u73b0\u6b64\u65b9\u6cd5\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u662fAbstractCommandController \u7684\u6e90\u7801\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\npublic abstract class AbstractCommandController extends BaseCommandController {\r\n    public AbstractCommandController() {}\r\n    public AbstractCommandController(Class commandClass) {\r\n        setCommandClass(commandClass);\r\n    }\r\n    public AbstractCommandController(Class commandClass, String commandName) {\r\n        setCommandClass(commandClass);\r\n        setCommandName(commandName);\r\n    } \r\n    @Override\r\n    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)\r\n            throws Exception {\r\n        \/\/ \u6839\u636e\u547d\u4ee4\u7c7b\u578b\uff0c\u521b\u5efa\u547d\u4ee4\u5bf9\u8c61\r\n        Object command = getCommand(request);\r\n        \/\/ \u7ed1\u5b9a\u547d\u4ee4\u5bf9\u8c61\u5230HTTP\u8bf7\u6c42\u53c2\u6570\uff0c\u5e76\u4e14\u6821\u9a8c\r\n        ServletRequestDataBinder binder = bindAndValidate(request, command);\r\n        \/\/ \u6784\u9020\u7ed1\u5b9a\u7ed3\u679c\u5bf9\u8c61\r\n        BindException errors = new BindException(binder.getBindingResult());\r\n        \/\/ \u8c03\u7528\u4e1a\u52a1\u903b\u8f91\u5904\u7406\u65b9\u6cd5\r\n        return handle(request, response, command, errors);\r\n    }\r\n    \/\/ \u5b50\u7c7b\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u5b9e\u73b0\u6b64\u65b9\u6cd5\uff0c\u5b83\u901a\u5e38\u4e0d\u9002\u7528\u4e8eForm\u6d41\u7a0b\uff0c\u5b83\u9002\u7528\u4e8e\u4e00\u4e2a\u7b80\u5355\u7684AJAX\u8bf7\u6c42\r\n    protected abstract ModelAndView handle(\r\n            HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)\r\n            throws Exception;\r\n}<\/pre>\n<p>\n\t\u547d\u4ee4\u63a7\u5236\u5668\u901a\u7528\u57fa\u7c7b\uff0c\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u529f\u80fd\u652f\u6301\uff1a\n<\/p>\n<ul>\n<li>\n\t\t\u6570\u636e\u7ed1\u5b9a\uff1a\u8bf7\u6c42\u53c2\u6570\u7ed1\u5b9a\u5230\u4e00\u4e2acommand object\uff08\u547d\u4ee4\u5bf9\u8c61\uff0c\u975eGoF\u91cc\u7684\u547d\u4ee4\u8bbe\u8ba1\u6a21\u5f0f\uff09\uff0c\u8fd9\u91cc\u7684\u547d\u4ee4\u5bf9\u8c61\u662f\u6307\u7ed1\u5b9a\u8bf7\u6c42\u53c2\u6570\u7684\u4efb\u4f55POJO\u5bf9\u8c61\uff1b\n\t<\/li>\n<li>\n\t\t\u9a8c\u8bc1\u529f\u80fd\uff1a\u63d0\u4f9bValidator\u6ce8\u518c\u529f\u80fd\uff0c\u6ce8\u518c\u7684\u9a8c\u8bc1\u5668\u4f1a\u9a8c\u8bc1\u547d\u4ee4\u5bf9\u8c61\u5c5e\u6027\u6570\u636e\u662f\u5426\u5408\u6cd5\uff1b\n\t<\/li>\n<li>\n\t\tvalidators\uff1a\u901a\u8fc7\u8be5\u5c5e\u6027\u6ce8\u5165\u9a8c\u8bc1\u5668\uff0c\u9a8c\u8bc1\u5668\u7528\u6765\u9a8c\u8bc1\u547d\u4ee4\u5bf9\u8c61\u5c5e\u6027\u662f\u5426\u5408\u6cd5\uff1b\n\t<\/li>\n<\/ul>\n<p>\n\tcommandClass\uff1a\u8868\u793a\u547d\u4ee4\u5bf9\u8c61\u5b9e\u73b0\u7c7b\uff0c\u5982UserModel\uff1b<br \/>\n\tcommandName\uff1a\u8868\u793a\u653e\u5165\u8bf7\u6c42\u7684\u547d\u4ee4\u5bf9\u8c61\u540d\u5b57\uff08\u9ed8\u8ba4command\uff09\uff0crequest.setAttribute(commandName, commandObject);\n<\/p>\n<p>\n\t\u8be5\u62bd\u8c61\u7c7b\u6ca1\u6709\u6ca1\u6709\u63d0\u4f9b\u6d41\u7a0b\u529f\u80fd\uff0c\u53ea\u662f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u516c\u5171\u7684\u529f\u80fd\uff0c\u5b9e\u9645\u4f7f\u7528\u65f6\u9700\u8981\u4f7f\u7528\u5b83\u7684\u5b50\u7c7b\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1648\">BaseCommandController\uff08\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\uff09<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>BaseCommandController\uff08\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\uff09\u57fa\u672c\u547d\u4ee4\u63a7\u5236\u5668\u63d0\u4f9b\u4e86\u521b\u5efa\u547d\u4ee4\u5bf9\u8c61\u548c\u901a\u8fc7HTTP\u8bf7\u6c42 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1376,1374,1375,1350,1359],"class_list":["post-1648","post","type-post","status-publish","format-standard","hentry","category-java","tag-abstractcommandcontroller","tag-basecommandcontroller","tag-commandclass","tag-spring-mvc","tag-spring-mvc-"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1648"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1648\/revisions"}],"predecessor-version":[{"id":1649,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1648\/revisions\/1649"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}