{"id":1650,"date":"2017-07-14T17:14:45","date_gmt":"2017-07-14T09:14:45","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1650"},"modified":"2017-07-14T17:14:45","modified_gmt":"2017-07-14T09:14:45","slug":"abstractcommandcontroller%ef%bc%88%e6%8a%bd%e8%b1%a1%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=1650","title":{"rendered":"AbstractCommandController\uff08\u62bd\u8c61\u547d\u4ee4\u63a7\u5236\u5668\uff09"},"content":{"rendered":"<p>\n\t\u4e0a\u4e00\u7ae0\u4e2d\uff0c\u6211\u5c31\u63d0\u5230\u4e86\u62bd\u8c61\u547d\u4ee4\u63a7\u5236\u5668\uff1aAbstractCommandController\u3002\u4e5f\u5217\u4e3e\u4e86\u5b83\u7684\u4e00\u4e9b\u6e90\u4ee3\u7801\u3002\u672c\u7ae0\u5c06\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u5b9e\u4f8b\u6765\u52a0\u6df1\u6211\u4eec\u5bf9\u5b83\u7684\u7406\u89e3\u3002\n<\/p>\n<p>\n\t\u547d\u4ee4\u63a7\u5236\u5668\uff0c\u53ef\u4ee5\u5b9e\u73b0\u8be5\u63a7\u5236\u5668\u6765\u521b\u5efa\u547d\u4ee4\u63a7\u5236\u5668\uff0c\u8be5\u63a7\u5236\u5668\u80fd\u628a\u81ea\u52a8\u5c01\u88c5\u8bf7\u6c42\u53c2\u6570\u5230\u4e00\u4e2a\u547d\u4ee4\u5bf9\u8c61\uff0c\u800c\u4e14\u63d0\u4f9b\u4e86\u9a8c\u8bc1\u529f\u80fd\u3002\n<\/p>\n<p>\n\t\u5148\u521b\u5efa\u547d\u4ee4\u7c7b\uff08\u5c31\u662f\u666e\u901a\u7684JavaBean\u7c7b\/POJO\uff09\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\npackage com.xttblog.chapter4.model;  \r\npublic class UserModel {  \r\n    private String username;  \r\n    private String password;  \r\n        \/\/\u7701\u7565setter\/getter  \r\n}  <\/pre>\n<p>\n\t\u5b9e\u73b0\u63a7\u5236\u5668\u7684\u4ee3\u7801\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\npackage com.xttblog.web.controller;  \r\n\/\/\u7701\u7565import  \r\npublic class MyAbstractCommandController extends AbstractCommandController {  \r\n    public MyAbstractCommandController() {  \r\n        \/\/\u8bbe\u7f6e\u547d\u4ee4\u5bf9\u8c61\u5b9e\u73b0\u7c7b  \r\n        setCommandClass(UserModel.class);  \r\n    }  \r\n    @Override  \r\n    protected ModelAndView handle(HttpServletRequest req, HttpServletResponse resp, Object command, BindException errors) throws Exception {  \r\n        \/\/\u5c06\u547d\u4ee4\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b9e\u9645\u7c7b\u578b  \r\n        UserModel user = (UserModel) command;  \r\n        ModelAndView mv = new ModelAndView();  \r\n        mv.setViewName(&quot;abstractCommand&quot;);  \r\n        mv.addObject(&quot;user&quot;, user);  \r\n        return mv;  \r\n    }  \r\n}   <\/pre>\n<p>\n\t\u7136\u540e\u518d\u518dSpring\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884cbean\u7684\u914d\u7f6e\u3002\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;!&mdash; \u5728chapter4-servlet.xml\u914d\u7f6e\u5904\u7406\u5668 --&gt;     \r\n&lt;bean name=&quot;\/abstractCommand&quot;   \r\n\tclass=&quot;com.xttblog.chapter4.web.controller.MyAbstractCommandController&quot;&gt;  \r\n\t&lt;!-- \u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165 \u6ce8\u5165\u547d\u4ee4\u5b9e\u73b0\u7c7b --&gt;  \r\n\t&lt;!-- property name=&quot;commandClass&quot; value=&quot;com.xttblog.chapter4.model.UserModel&quot;\/--&gt;  \r\n&lt;\/bean&gt; <\/pre>\n<p>\n\t\u6700\u540e\u6211\u4eec\u7f16\u5199jsp\u89c6\u56fe\u4ee3\u7801\u3002\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;!&mdash; WEB-INF\/jsp\/abstractCommand.jsp\u89c6\u56fe\u4e0b\u7684\u4e3b\u8981\u5185\u5bb9 --&gt;     \r\n${user.username }-${user.password }  <\/pre>\n<p>\n\t\u5f53\u6211\u4eec\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165&ldquo;http:\/\/localhost:9080\/springmvc-chapter4\/abstractCommand?username=123&amp;password=123&rdquo;\uff0c\u4f1a\u81ea\u52a8\u5c06\u8bf7\u6c42\u53c2\u6570username\u548cpassword\u7ed1\u5b9a\u5230\u547d\u4ee4\u5bf9\u8c61\uff1b\u7ed1\u5b9a\u65f6\u6309\u7167JavaBean\u547d\u540d\u89c4\u8303\u7ed1\u5b9a\uff1b\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"AbstractCommandController \u6848\u4f8b\" src=\"http:\/\/img.bbs.csdn.net\/upload\/201707\/14\/1500023542_562557.jpg\" style=\"width: 830px;height: 148px\" \/><\/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=1650\">AbstractCommandController\uff08\u62bd\u8c61\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>\u4e0a\u4e00\u7ae0\u4e2d\uff0c\u6211\u5c31\u63d0\u5230\u4e86\u62bd\u8c61\u547d\u4ee4\u63a7\u5236\u5668\uff1aAbstractCommandController\u3002\u4e5f\u5217\u4e3e\u4e86\u5b83\u7684\u4e00\u4e9b\u6e90\u4ee3\u7801 [&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,1350,1359,1377],"class_list":["post-1650","post","type-post","status-publish","format-standard","hentry","category-java","tag-abstractcommandcontroller","tag-spring-mvc","tag-spring-mvc-"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1650","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=1650"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1650\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1650\/revisions\/1651"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}