{"id":95543,"date":"2026-08-26T14:24:42","date_gmt":"2026-08-26T06:24:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/95543.html"},"modified":"2026-08-26T14:24:42","modified_gmt":"2026-08-26T06:24:42","slug":"ssm%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/95543.html","title":{"rendered":"SSM\u6846\u67b6"},"content":{"rendered":"<h2>01_SpringloC&amp;DI<\/h2>\n<h3>1.Spring\u6982\u8ff0<\/h3>\n<h4>1.1Spring\u662f\u4ec0\u4e48(\u7406\u89e3)<\/h4>\n<p>Spring\u662f\u5206\u5c42\u7684Java SE\/EE\u5e94\u7528 full-stack \u8f7b\u91cf\u7ea7\u5f00\u6e90\u6846\u67b6&#xff0c;\u4ee5 loC(Inverse Of Control:\u53cd\u8f6c\u63a7\u5236)\u548cAOP(Aspect Oriented Programming&#xff1a;\u9762\u5411\u5207\u9762\u7f16\u7a0b)\u4e3a\u5185\u6838\u3002<\/p>\n<p>\u63d0\u4f9b\u4e86\u5c55\u73b0\u5c42SpringMVC\u548c\u6301\u4e45\u5c42Spring JDBCTemplate\u4ee5\u53ca\u4e1a\u52a1\u5c42\u4e8b\u52a1\u7ba1\u7406\u4f17\u591a\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u6280\u672f&#xff0c;\u8fd8\u80fd\u6574\u5408\u5f00\u6e90\u65f6\u95f4\u4f17\u591a\u8457\u540d\u7684\u7b2c\u4e09\u65b9\u6846\u67b6\u548c\u7c7b\u5e93&#xff0c;\u9010\u6e10\u6210\u4e3a\u4f7f\u7528\u6700\u591a\u7684Java EE\u4f01\u4e1a\u5e94\u7528\u5f00\u6e90\u6846\u67b6<\/p>\n<h4>1.2Spring\u53d1\u5c55\u5386\u7a0b(\u4e86\u89e3)<\/h4>\n<p>Rod Johnson(Spring \u4e4b\u7236)<\/p>\n<p>Expert One-to-One J2EE Design and Development(2002)<\/p>\n<p>\u9610\u8ff0\u4e86J2EE\u4f7f\u7528EJB\u5f00\u53d1\u8bbe\u8ba1\u7684\u4f18\u70b9\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n<p>Expert One-to-One J2EE Development without EJB(2004)<\/p>\n<p>\u9610\u8ff0\u4e86J2EE\u5f00\u53d1\u4e0d\u4f7f\u7528EJB\u7684\u89e3\u51b3\u65b9\u5f0f(Spring \u96cf\u5f62)<\/p>\n<p>2017\u5e749\u6708\u4efd\u53d1\u5e03\u4e86Spring\u7684\u6700\u65b0\u7248\u672cSpring5.0 \u901a\u7528\u7248(GA)<\/p>\n<h4>1.3Spring\u7684\u4f18\u52bf(\u7406\u89e3)<\/h4>\n<p>1&#xff09;\u65b9\u4fbf\u89e3\u8026&#xff0c;\u7b80\u5316\u5f00\u53d1<\/p>\n<p>\u901a\u8fc7Spring\u63d0\u4f9b\u7684loC\u5bb9\u5668&#xff0c;\u53ef\u4ee5\u5c06\u5bf9\u8c61\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u4ea4\u7531Spring\u8fdb\u884c\u63a7\u5236&#xff0c;\u907f\u514d\u786c\u7f16\u7801\u6240\u9020\u6210\u7684\u8fc7\u5ea6\u8026\u5408\u3002\u7528\u6237\u4e5f\u4e0d\u5fc5\u518d\u4e3a\u5355\u4f8b\u6a21\u5f0f\u7c7b\u3001\u5c5e\u6027\u6587\u4ef6\u89e3\u6790\u7b49\u8fd9\u4e9b\u7684\u9700\u6c42\u7f16\u5199\u4ee3\u7801&#xff0c;\u53ef\u4ee5\u66f4\u4e13\u6ce8\u4e8e\u4e0a\u5c42\u7684\u5e94\u7528\u3002<\/p>\n<p>2&#xff09;AOP\u7f16\u7a0b\u7684\u652f\u6301<\/p>\n<p>\u901a\u8fc7Spring\u7684AOP\u529f\u80fd&#xff0c;\u65b9\u4fbf\u8fdb\u884c\u9762\u5411\u5207\u9762\u7f16\u7a0b&#xff0c;\u8bb8\u591a\u4e0d\u5bb9\u6613\u7528\u4f20\u7edfOOP\u5b9e\u73b0\u7684\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7AOP\u8f7b\u677e\u5b9e\u73b0\u3002<\/p>\n<p>3&#xff09;\u58f0\u660e\u5f0f\u4e8b\u52a1\u7684\u652f\u6301<\/p>\n<p>\u53ef\u4ee5\u5c06\u6211\u4eec\u4ece\u5355\u8c03\u70e6\u95f7\u7684\u4e8b\u52a1\u7ba1\u7406\u4ee3\u7801\u4e2d\u89e3\u8131\u51fa\u6765&#xff0c;\u901a\u8fc7\u58f0\u660e\u5f0f\u65b9\u5f0f\u7075\u6d3b\u7684\u8fdb\u884c\u4e8b\u52a1\u7ba1\u7406&#xff0c;\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u8d28\u91cf\u3002<\/p>\n<p>4&#xff09;\u65b9\u4fbf\u7a0b\u5e8f\u7684\u6d4b\u8bd5<\/p>\n<p>\u53ef\u4ee5\u7528\u975e\u5bb9\u5668\u4f9d\u8d56\u7684\u7f16\u7a0b\u65b9\u5f0f\u8fdb\u884c\u51e0\u4e4e\u6240\u6709\u7684\u6d4b\u8bd5\u5de5\u4f5c&#xff0c;\u6d4b\u8bd5\u4e0d\u518d\u662f\u6602\u8d35\u7684\u64cd\u4f5c&#xff0c;\u800c\u662f\u968f\u624b\u53ef\u505a\u7684\u4e8b\u60c5\u3002<\/p>\n<p>5&#xff09;\u65b9\u4fbf\u96c6\u6210\u5404\u79cd\u4f18\u79c0\u6846\u67b6<\/p>\n<p>Spring\u5bf9\u5404\u79cd\u4f18\u79c0\u6846\u67b6&#xff08;Struts\u3001Hibernate\u3001Hessian\u3001Quartz\u7b49&#xff09;\u7684\u652f\u6301\u3002<\/p>\n<p>6&#xff09;\u964d\u4f4eJavaEE API\u7684\u4f7f\u7528\u96be\u5ea6<\/p>\n<p>Spring\u5bf9javaEE API&#xff08;\u5982JDBC\u3001javaMail\u3001\u8fdc\u7a0b\u8c03\u7528\u7b49&#xff09;\u8fdb\u884c\u4e86\u8584\u8584\u7684\u5c01\u88c5\u5c42&#xff0c;\u4f7f\u8fd9\u4e9bAPI\u7684\u4f7f\u7528\u96be\u5ea6\u5927\u4e3a\u964d\u4f4e\u3002<\/p>\n<p>7&#xff09;Java\u6e90\u7801\u662f\u7ecf\u5178\u5b66\u4e60\u8303\u4f8b<\/p>\n<p>Spring\u7684\u6e90\u4ee3\u7801\u8bbe\u8ba1\u7cbe\u5999\u3001\u7ed3\u6784\u6e05\u6670\u3001\u5320\u5fc3\u72ec\u7528&#xff0c;\u5904\u5904\u4f53\u73b0\u7740\u5927\u5e08\u5bf9java\u8bbe\u8ba1\u6a21\u5f0f\u7075\u6d3b\u8fd0\u7528\u4ee5\u53ca\u5bf9java\u6280\u672f\u7684\u9ad8\u6df1\u9020\u8be3\u3002\u5b83\u7684\u6e90\u4ee3\u7801\u65e0\u7591\u662fjava\u6280\u672f\u7684\u6700\u4f73\u5b9e\u8df5\u7684\u8303\u4f8b\u3002<\/p>\n<h4>1.4Spring\u7684\u4f53\u7cfb\u7ed3\u6784(\u4e86\u89e3)<\/h4>\n<\/p>\n<h3>2.Spring\u5feb\u901f\u5165\u95e8<\/h3>\n<h4>2.1Spring\u7a0b\u5e8f\u5f00\u53d1\u6b65\u9aa4<\/h4>\n<\/p>\n<li>\n<p>\u5bfc\u5165Spring\u5f00\u53d1\u7684\u57fa\u672c\u5305\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Dao\u63a5\u53e3\u548c\u5b9e\u73b0\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaSpring\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u5728Spring\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6eUserDaoImpl<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528Spring\u7684API\u83b7\u5f97Bean\u5b9e\u4f8b<\/p>\n<\/li>\n<h4>2.2\u5bfc\u5165Spring\u5f00\u53d1\u7684\u57fa\u672c\u5305\u5750\u6807<\/h4>\n<p>&lt;properties&gt;<br \/>\n \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n&lt;\/dependencies&gt; <\/p>\n<h4>2.3 \u7f16\u5199Dao\u63a5\u53e3\u548c\u5b9e\u73b0\u7c7b<\/h4>\n<p>public interface UserDao{<br \/>\n \u00a0 \u00a0public void save();<br \/>\n}<br \/>\n\u200b<br \/>\npublic class UserDaoImpl implements UserDao{<br \/>\n \u00a0 \u00a0&#064;Override<br \/>\n \u00a0 \u00a0public void save(){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0sout(&#034;UserDao save method running&#8230;.&#034;)<br \/>\n \u00a0  }<br \/>\n} <\/p>\n<h4>2.4\u521b\u5efaSpring\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p>\u5728\u7c7b\u8def\u5f84\u4e0b&#xff08;resource&#xff09;\u521b\u5efaapplicationContext.xml\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034; ?&gt;<br \/>\n&lt;beans xmlns&#061;&#034;http:\/\/www.springframework.org\/schema\/beans&#034;<br \/>\n \u00a0 \u00a0xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0xsi:schemaLocation&#061;&#034; http:\/\/www.springframework.org\/schema\/beans \u00a0 \u00a0     \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&#034;&gt;<br \/>\n&lt;\/beans&gt; <\/p>\n<h4>2.5\u5728Spring\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6eUserDaoImpl<\/h4>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034; ?&gt;<br \/>\n&lt;beans xmlns&#061;&#034;http:\/\/www.springframework.org\/schema\/beans&#034;<br \/>\n \u00a0 \u00a0 \u00a0 xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n \u00a0 \u00a0 \u00a0 xsi:schemaLocation&#061;&#034;http:\/\/www.springframework.org\/schema\/beans \u00a0 \u00a0       \u00a0 http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&#034;&gt;<br \/>\n \u00a0 \u00a0<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.dao.impl.UserDaoImpl&#034;&gt;&lt;\/bean&gt;<br \/>\n \u00a0 \u00a0<br \/>\n&lt;\/beans&gt; <\/p>\n<h4>2.6\u4f7f\u7528Spring\u7684API\u83b7\u5f97Bean\u5b9e\u4f8b<\/h4>\n<p>&#064;Test<br \/>\npublic void test1{<br \/>\n \u00a0 \u00a0Application applicationContext&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n \u00a0 \u00a0UserDao userDao&#061;(UserDao)applicationContext.getBean(&#034;userDao&#034;);<br \/>\n \u00a0 \u00a0userDao.save();<br \/>\n} <\/p>\n<h4>2.7\u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>Spring\u7684\u5f00\u53d1\u6b65\u9aa4<\/p>\n<li>\n<p>\u5bfc\u5165\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaBean<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaapplicationContext.xml<\/p>\n<\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u914d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaApplicationContext\u5bf9\u8c61getBean<\/p>\n<\/li>\n<h3>3. Spring\u914d\u7f6e\u6587\u4ef6<\/h3>\n<h4>3.1 Bean\u6807\u7b7e\u57fa\u672c\u914d\u7f6e<\/h4>\n<p>\u7528\u4e8e\u914d\u7f6e\u5bf9\u8c61\u4ea4\u7531Spring\u6765\u521b\u5efa\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5b83\u8c03\u7528\u7684\u662f\u7c7b\u4e2d\u65e0\u53c2\u6784\u9020\u51fd\u6570&#xff0c;\u5982\u679c\u6ca1\u6709\u65e0\u53c2\u6784\u9020\u51fd\u6570\u5219\u4e0d\u80fd\u521b\u5efa\u6210\u529f\u3002<\/p>\n<p>\u57fa\u672c\u5c5e\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>id&#xff1a;Bean\u5b9e\u4f8b\u5728Spring\u5bb9\u5668\u4e2d\u7684\u552f\u4e00\u6807\u8bc6<\/p>\n<\/li>\n<li>\n<p>class&#xff1a;Bean\u7684\u5168\u9650\u5b9a\u540d\u79f0<\/p>\n<\/li>\n<\/ul>\n<h4>3.2 Bean\u6807\u7b7e\u8303\u56f4\u914d\u7f6e<\/h4>\n<p>scope&#xff1a;\u6307\u5bf9\u8c61\u7684\u4f5c\u7528\u8303\u56f4&#xff0c;\u53d6\u503c\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u53d6\u503c\u8303\u56f4\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>singleton<\/td>\n<td>\u9ed8\u8ba4\u503c&#xff0c;\u5355\u4f8b\u7684<\/td>\n<\/tr>\n<tr>\n<td>prototype<\/td>\n<td>\u591a\u4f8b\u7684<\/td>\n<\/tr>\n<tr>\n<td>request<\/td>\n<td>web\u9879\u76ee\u4e2d&#xff0c;Spring\u521b\u5efa\u4e00\u4e2aBean\u7684\u5bf9\u8c61&#xff0c;\u5c06\u5bf9\u8c61\u5b58\u5165\u5230request\u57df\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>session<\/td>\n<td>web\u9879\u76ee\u4e2d&#xff0c;Spring\u521b\u5efa\u4e00\u4e2aBean\u7684\u5bf9\u8c61&#xff0c;\u5c06\u5bf9\u8c61\u5b58\u5165\u5230session\u57df\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>global session<\/td>\n<td>web\u9879\u76ee\u4e2d&#xff0c;\u5e94\u7528\u5728portlet\u73af\u5883&#xff0c;\u5982\u679c\u6ca1\u6709porlet\u73af\u5883\u90a3\u4e48globalSession\u76f8\u5f53\u4e8esession<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<li>\n<p>\u5f53scope\u7684\u53d6\u503c\u4e3asingleton\u65f6<\/p>\n<p>Bean\u7684\u5b9e\u4f8b\u5316\u4e2a\u6570&#xff1a;\u4e00\u4e2a<\/p>\n<p>Bean\u7684\u5b9e\u4f8b\u5316\u65f6\u673a&#xff1a;\u5f53Spring\u6838\u5fc3\u6587\u4ef6\u88ab\u52a0\u8f7d\u65f6&#xff0c;\u5b9e\u4f8b\u5316\u914d\u7f6e\u7684Bean\u5b9e\u4f8b&#xff08;applicationContext&#xff09;<\/p>\n<p>Bean\u7684\u751f\u547d\u5468\u671f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bf9\u8c61\u521b\u5efa&#xff1a;\u5f53\u5e94\u7528\u52a0\u8f7d&#xff0c;\u521b\u5efa\u5bb9\u5668\u65f6&#xff0c;\u5bf9\u8c61\u5c31\u88ab\u521b\u5efa\u4e86<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u8c61\u8fd0\u884c&#xff1a;\u53ea\u8981\u5bb9\u5668\u5728&#xff0c;\u5bf9\u8c61\u4e00\u76f4\u6d3b\u7740<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u8c61\u9500\u6bc1&#xff1a;\u5f53\u5e94\u7528\u5378\u8f7d&#xff0c;\u9500\u6bc1\u5bb9\u5668\u65f6&#xff0c;\u5bf9\u8c61\u5c31\u88ab\u9500\u6bc1\u4e86<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5f53scope\u7684\u53d6\u503c\u4e3aprototype\u65f6<\/p>\n<p>Bean\u7684\u5b9e\u4f8b\u5316\u4e2a\u6570&#xff1a;\u591a\u4e2a<\/p>\n<p>Bean\u7684\u5b9e\u4f8b\u5316\u65f6\u673a&#xff1a;\u5f53\u8c03\u7528getBean()\u65b9\u6cd5\u65f6\u5b9e\u4f8b\u5316Bean<\/p>\n<ul>\n<li>\n<p>\u5bf9\u8c61\u521b\u5efa&#xff1a;\u5f53\u4f7f\u7528\u5bf9\u8c61\u65f6&#xff0c;\u521b\u5efa\u65b0\u7684\u5bf9\u8c61\u5b9e\u4f8b<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u8c61\u8fd0\u884c&#xff1a;\u53ea\u8981\u5bf9\u8c61\u5728\u4f7f\u7528\u4e2d&#xff0c;\u5c31\u4e00\u76f4\u6d3b\u7740<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u8c61\u9500\u6bc1&#xff1a;\u5f53\u5bf9\u8c61\u957f\u65f6\u95f4\u4e0d\u7528\u65f6&#xff0c;\u88abjava\u7684\u5783\u573e\u56de\u6536\u5668\u56de\u6536\u4e86<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h4>3.3 Bean\u751f\u547d\u5468\u671f\u914d\u7f6e&#xff08;\u5f53\u751f\u6210\u548c\u9500\u6bc1\u65f6\u4f1a\u6267\u884c\u76f8\u5e94\u7684\u65b9\u6cd5&#xff09;<\/h4>\n<ul>\n<li>\n<p>init-method&#xff1a;\u6307\u5b9a\u7c7b\u4e2d\u7684\u521d\u59cb\u5316\u65b9\u6cd5\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>destory-method&#xff1a;\u6307\u5b9a\u7c7b\u4e2d\u9500\u6bc1\u65b9\u6cd5\u540d\u79f0<\/p>\n<\/li>\n<\/ul>\n<h4>3.4 Bean\u5b9e\u4f8b\u5316\u4e09\u79cd\u65b9\u5f0f<\/h4>\n<ul>\n<li>\n<p>\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<\/li>\n<li>\n<p>\u5de5\u5382\u9759\u6001\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<\/li>\n<li>\n<p>\u5de5\u5382\u5b9e\u4f8b\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>\u4f7f\u7528\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<p>\u5b83\u4f1a\u6839\u636e\u9ed8\u8ba4\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\u6765\u521b\u5efa\u7c7b\u5bf9\u8c61&#xff0c;\u5982\u679cbean\u4e2d\u6ca1\u6709\u9ed8\u8ba4\u65e0\u53c2\u6784\u9020\u51fd\u6570&#xff0c;\u5c06\u4f1a\u521b\u5efa\u5931\u8d25<\/p>\n<p> public interface UserDao{<br \/>\n \u00a0 \u00a0public void save();<br \/>\n}<br \/>\n\u200b<br \/>\npublic class UserServiceImpl implements UserService {<br \/>\n \u00a0 \u00a0public void save() {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0ApplicationContext app&#061; new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0UserDao userDao1 &#061; (UserDao) app.getBean(&#034;userDao&#034;);<br \/>\n \u00a0  }<br \/>\n} &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;&lt;\/bean&gt; public class SpringText {<br \/>\n \u00a0 \u00a0&#064;Test<br \/>\n \u00a0 \u00a0\/\/\u6d4b\u8bd5scope<br \/>\n \u00a0 \u00a0public void text1(){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0ApplicationContext app&#061; new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0UserDao userDao1 &#061; (UserDao) app.getBean(&#034;userDao&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0System.out.println(userDao1);<br \/>\n \u00a0  }<br \/>\n} <\/li>\n<li>\n<p>\u5de5\u5382\u9759\u6001\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<p>\u5de5\u5382\u7684\u9759\u6001\u65b9\u6cd5\u8fd4\u56deBean\u5b9e\u4f8b<\/p>\n<p> public class staticFactoy{<br \/>\n \u00a0 \u00a0public static UserDao createUserDao(){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return new UserDaoImpl();<br \/>\n \u00a0  }<br \/>\n} &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.factory.staticFactory&#034; factory-method&#061;&#034;createUserDao&#034;&gt;&lt;\/bean&gt; <\/li>\n<li>\n<p>\u5de5\u5382\u5b9e\u4f8b\u65b9\u6cd5\u5b9e\u4f8b\u5316<\/p>\n<p>\u5de5\u5382\u7684\u975e\u9759\u6001\u65b9\u6cd5\u8fd4\u56deBean\u5b9e\u4f8b(\u5148\u521b\u5efa\u51fa\u5de5\u5382\u7c7b&#xff0c;\u7136\u540e\u518d\u5de5\u5382\u65b9\u6cd5)<\/p>\n<p> public class DynamicFactoy(){<br \/>\n \u00a0 \u00a0public UserDao createUserDao(){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return new UserDaoImpl();<br \/>\n \u00a0  }<br \/>\n} &lt;bean id&#061;&#034;factory&#034; class&#061;&#034;com.itheima.factory.DynamicFactoy&#034;&gt;&lt;\/bean&gt;<br \/>\n&lt;bean id&#061;&#034;userDao&#034; factory-bean&#061;&#034;factory&#034; factory-method&#061;&#034;createUserDao&#034;&gt;&lt;\/bean&gt; <\/li>\n<h4>3.5Bean\u7684\u4f9d\u8d56\u6ce8\u5165\u5165\u95e8<\/h4>\n<li>\n<p>\u521b\u5efaUserService&#xff0c;UserService\u5185\u90e8\u5728\u8c03\u7528UserDao\u7684save()\u65b9\u6cd5<\/p>\n<p> public class UserServiceImpl implements UserService{<br \/>\n \u00a0 \u00a0&#064;Override<br \/>\n public void save(){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0ApplicationContext applicationContext&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0UserDao userDao&#061;(UserDao) applicationContext.getBean(&#034;userDao&#034;);<br \/>\n \u00a0  }<br \/>\n} <\/li>\n<li>\n<p>\u5c06UserServiceImpl\u7684\u521b\u5efa\u6743\u4ea4\u7ed9Spring<\/p>\n<p> &lt;bean id&#061;&#034;userService&#034; class&#061;&#034;com.itheima.impl.UserServiceImpl&#034;&gt;&lt;\/bean&gt; <\/li>\n<li>\n<p>\u4eceSpring\u5bb9\u5668\u4e2d\u83b7\u5f97UserService\u8fdb\u884c\u64cd\u4f5c<\/p>\n<p> ApplicationContext applicationContext&#061;new ClassPathXmlApplication(&#034;applicationContext.xml&#034;);<br \/>\nUserService userService&#061;(UserService)applicationContext.getBean(&#034;userService&#034;);<br \/>\nuserService.save(); <\/li>\n<h4>3.6 Bean\u7684\u4f9d\u8d56\u6ce8\u5165\u5206\u6790<\/h4>\n<p>\u76ee\u524dUserService\u5b9e\u4f8b\u548cUserDao\u5b9e\u4f8b\u90fd\u5b58\u5728\u4e0eSpring\u5bb9\u5668\u4e2d&#xff0c;\u5f53\u524d\u7684\u505a\u6cd5\u662f\u5728\u5bb9\u5668\u5916\u90e8\u83b7\u5f97UserService\u5b9e\u4f8b\u548cUserDao\u5b9e\u4f8b&#xff0c;\u7136\u540e\u5728\u7a0b\u5e8f\u4e2d\u8fdb\u884c\u7ed3\u5408\u3002<\/p>\n<\/p>\n<p>\u56e0\u4e3aUserService\u548cUserDao\u90fd\u5728Spring\u5bb9\u5668\u4e2d&#xff0c;\u800c\u6700\u7ec8\u7a0b\u5e8f\u76f4\u63a5\u4f7f\u7528\u7684\u662fUserService&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u5728Spring\u5bb9\u5668\u4e2d&#xff0c;\u5c06UserDao\u8bbe\u7f6e\u5230UserService\u5185\u90e8\u3002<\/p>\n<\/p>\n<h4>3.7Bean\u7684\u4f9d\u8d56\u6ce8\u5165\u6982\u5ff5<\/h4>\n<p>\u4f9d\u8d56\u6ce8\u5165(Dependency Injection)&#xff1a;\u5b83\u662fSpring\u6846\u67b6\u6838\u5fc3IOC\u7684\u5177\u4f53\u5b9e\u73b0\u3002<\/p>\n<p>\u5728\u7f16\u5199\u7a0b\u5e8f\u65f6&#xff0c;\u901a\u8fc7\u63a7\u5236\u53cd\u8f6c&#xff0c;\u628a\u5bf9\u8c61\u7684\u521b\u5efa\u6743\u4ea4\u7ed9\u4e86Spring&#xff0c;\u4f46\u662f\u4ee3\u7801\u4e2d\u4e0d\u53ef\u80fd\u51fa\u73b0\u6ca1\u6709\u4f9d\u8d56\u7684\u60c5\u51b5\u3002<\/p>\n<p>IOC\u89e3\u8026\u53ea\u662f\u964d\u4f4e\u4ed6\u4eec\u7684\u4f9d\u8d56\u5173\u7cfb&#xff0c;\u4f46\u4e0d\u4f1a\u6d88\u9664\u3002\u4f8b\u5982&#xff1a;\u4e1a\u52a1\u5c42\u4f9d\u7136\u4f1a\u8c03\u7528\u6301\u4e45\u5c42\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u90a3\u8fd9\u79cd\u4e1a\u52a1\u5c42\u548c\u6301\u4e45\u5c42\u7684\u4f9d\u8d56\u5173\u7cfb&#xff0c;\u5728\u4f7f\u7528Spring\u4e4b\u540e&#xff0c;\u5c31\u8ba9Spring\u6765\u7ef4\u62a4\u4e86\u3002<\/p>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u5c31\u662f\u5750\u7b49\u6846\u67b6\u628a\u6301\u4e45\u5c42\u5bf9\u8c61\u4f20\u5165\u4e1a\u52a1\u5c42&#xff0c;\u800c\u4e0d\u7528\u6211\u4eec\u81ea\u5df1\u53bb\u83b7\u53d6\u3002<\/p>\n<h4>3.8 Bean\u7684\u4f9d\u8d56\u6ce8\u5165\u65b9\u5f0f<\/h4>\n<p>\u600e\u4e48\u5c06UserDao\u6ce8\u5165\u5230UserService\u5185\u90e8\u5462&#xff1f;<\/p>\n<ul>\n<li>\n<p>\u6784\u9020\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>set\u65b9\u6cd5<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>set\u65b9\u6cd5<\/p>\n<p>\u5728UserServiceImpl\u4e2d\u6dfb\u52a0setUserDao\u65b9\u6cd5<\/p>\n<p> public class UserServiceImpl implements UserService{<br \/>\n    private UserDao userDao;<br \/>\n    public void setUserDao(UserDao userDao){<br \/>\n        this.userDao&#061;userDao;<br \/>\n    }<br \/>\n    &#064;Override<br \/>\n    public void save(){<br \/>\n        userDao.save();<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u914d\u7f6eSpring\u5bb9\u5668\u8c03\u7528set\u65b9\u6cd5\u8fdb\u884c\u6ce8\u5165<\/p>\n<p> &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;&lt;\/bean&gt;<\/p>\n<p>&lt;bean id&#061;&#034;userService&#034; class&#061;&#034;com.itheima.impl.UServiceImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;userDao&#034; ref&#061;&#034;userDao&#034;&gt;&lt;\/property&gt;<br \/>\n    &lt;!&#8211;name\u7684userDao\u662fsetUserDao\u540e\u9762\u5c0f\u5199userDao \u800cref\u7684userDao\u662f\u4e0a\u9762\u914d\u7f6e\u7684userDao&#8211;&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<li> public class UserController {<br \/>\n    public static void main(String[] args) {<br \/>\n        ApplicationContext app&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        UserService userService &#061; (UserService) app.getBean(&#034;userService&#034;);<br \/>\n        userService.save();<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u7b2c\u4e8c\u79cdSet\u4f9d\u8d56\u6ce8\u5165<\/p>\n<p>p\u547d\u540d\u7a7a\u95f4\u672c\u8d28\u4e5f\u662fset\u65b9\u6cd5\u6ce8\u5165&#xff0c;\u4f46\u6bd4\u8d77\u4e0a\u8ff0\u7684set\u65b9\u6cd5\u6ce8\u5165\u66f4\u52a0\u65b9\u4fbf&#xff0c;\u4e3b\u8981\u4f53\u73b0\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u5982\u4e0b&#xff1a;<\/p>\n<p>\u9996\u5148\u9700\u8981\u5f15\u5165\u547d\u540d\u7a7a\u95f4&#xff1a;<\/p>\n<\/p>\n<p>\u5176\u6b21&#xff0c;\u9700\u8981\u4fee\u6539\u6ce8\u5165\u65b9\u5f0f<\/p>\n<p> &lt;bean id&#061;&#034;userService&#034; class&#061;&#034;com.itheima.Service.impl.UserServiceImpl&#034; p:userDao-ref&#061;&#034;userDao&#034;&gt;&lt;\/bean&gt; <\/li>\n<p>\u6784\u9020\u65b9\u6cd5\u6ce8\u5165<\/p>\n<li>\n<p>\u521b\u5efa\u6709\u53c2\u6784\u9020<\/p>\n<p> public class UserServceImpl implements UserService{<br \/>\n    private UserDao userDao;<\/p>\n<p>    public UserServceImpl(){}<\/p>\n<p>    public UserServceImpl(UserDao userDao){<br \/>\n        this.userDao&#061;userDao;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void save(){<br \/>\n        userDao.save();<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u914d\u7f6eSpring\u5bb9\u5668\u8c03\u7528\u6709\u53c2\u6784\u9020\u65f6\u8fdb\u884c\u6ce8\u5165<\/p>\n<p> &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;&lt;\/bean&gt;<br \/>\n&lt;bean id&#061;&#034;userService&#034; class&#061;&#034;com.itheima.impl.UserServiceImpl&#034;&gt;<br \/>\n    &lt;constructor-arg name&#061;&#034;userDao&#034; ref&#061;&#034;userDao&#034;&gt;&lt;\/constructor-arg&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<h4>3.9Bean\u7684\u4f9d\u8d56\u6570\u636e\u7c7b\u578b<\/h4>\n<p>\u4e0a\u9762\u7684\u64cd\u4f5c&#xff0c;\u90fd\u662f\u6ce8\u5165\u5f15\u7528Bean&#xff0c;\u9664\u4e86\u5bf9\u8c61\u7684\u5f15\u7528\u53ef\u4ee5\u6ce8\u5165&#xff0c;\u666e\u901a\u6570\u636e\u7c7b\u578b\u3001\u96c6\u5408\u7b49\u53ef\u4ee5\u5728\u5bb9\u5668\u4e2d\u8fdb\u884c\u6ce8\u5165\u3002<\/p>\n<p>\u6ce8\u5165\u6570\u636e\u7684\u4e09\u79cd\u6570\u636e\u7c7b\u578b<\/p>\n<ul>\n<li>\n<p>\u666e\u901a\u6570\u636e\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>\u5f15\u7528\u6570\u636e\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>\u96c6\u5408\u6570\u636e\u7c7b\u578b<\/p>\n<\/li>\n<\/ul>\n<p>\u5176\u4e2d\u5f15\u7528\u6570\u636e\u7c7b\u578b&#xff0c;\u6b64\u5904\u5c31\u4e0d\u5728\u591a\u8bf4&#xff0c;\u4e4b\u524d\u90fd\u662f\u5bf9UserDao\u5bf9\u8c61\u7684\u5f15\u7528\u8fdb\u884c\u6ce8\u5165&#xff0c;\u4e0b\u9762\u5c06\u4ee5set\u65b9\u6cd5\u6ce8\u5165\u4e3a\u4f8b&#xff0c;\u6f14\u793a\u666e\u901a\u6570\u636e\u7c7b\u578b\u548c\u96c6\u5408\u6570\u636e\u7c7b\u578b\u7684\u6ce8\u5165\u3002<\/p>\n<li>\n<p>\u666e\u901a\u6570\u636e\u7c7b\u578b\u7684\u6ce8\u5165<\/p>\n<p> public class UserDaoImpl implements UserDao{<br \/>\n    private String userName;<br \/>\n    private int age;<br \/>\n    public void setUserName(String userName){<br \/>\n        this.userName&#061;userName;<br \/>\n    }<br \/>\n    public void setAge(int age){<br \/>\n        this.age&#061;age;<br \/>\n    }<\/p>\n<p>    public void save(){<br \/>\n        sout(userName&#043;&#034;&#061;&#061;&#061;&#061;&#034;&#043;age);<br \/>\n        sout(&#034;save running&#8230;.&#034;);<br \/>\n    }<br \/>\n} &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;userName&#034; value&#061;&#034;\u5f20\u4e09&#034;&gt;&lt;\/property&gt;<br \/>\n    &lt;property name&#061;&#034;age&#034; value&#061;&#034;15&#034;&gt;&lt;\/property&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<li>\n<p>\u96c6\u5408\u6570\u636e\u7c7b\u578b(List&lt;String&gt;)\u7684\u6ce8\u5165<\/p>\n<p> public class UserDaoImpl implements UserDao{<br \/>\n    private List&lt;String&gt; strList;<br \/>\n    public void setStrList(List&lt;String&gt; strList){<br \/>\n        this.strList&#061;strList;<br \/>\n    }<br \/>\n    public void save(){<br \/>\n        sout(strList);<br \/>\n        sout(&#034;UserDao save method running&#8230;&#034;);<br \/>\n    }<br \/>\n} &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.dao.UserDaoImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;strList&#034;&gt;<br \/>\n        &lt;list&gt;<br \/>\n            &lt;value&gt;aaa&lt;\/value&gt;<br \/>\n            &lt;value&gt;bbb&lt;\/value&gt;<br \/>\n            &lt;value&gt;ccc&lt;\/value&gt;<br \/>\n        &lt;\/list&gt;<br \/>\n    &lt;\/property&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<li>\n<p>\u96c6\u5408\u6570\u636e\u7c7b\u578b(List&lt;User&gt;)\u7684\u6ce8\u5165<\/p>\n<p> public class UserDaoImpl implements UserDao{<br \/>\n    private List&lt;User&gt; userList;<br \/>\n    public void setUserList(List&lt;User&gt; userList){<br \/>\n        this.userList&#061;userList;<br \/>\n    }<br \/>\n    public void save(){<br \/>\n        sout(userList);<br \/>\n        sout(&#034;UserDao save method running&#8230;&#034;);<br \/>\n    }<br \/>\n} &lt;bean id&#061;&#034;u1&#034; class&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;name&#034; value&#061;&#034;\u5b89\u5b89&#034;\/&gt;<br \/>\n    &lt;property name&#061;&#034;age&#034; value&#061;&#034;11&#034;\/&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;bean id&#061;&#034;u2&#034; class&#061;&#034;com.itheima.domain.User&#034;\/&gt;<br \/>\n&lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;userList&#034;&gt;<br \/>\n        &lt;List&gt;<br \/>\n            &lt;bean class&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n                &lt;property name&#061;&#034;name&#034; value&#061;&#034;qq&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;age&#034; value&#061;&#034;22&#034;\/&gt;<br \/>\n            &lt;\/bean&gt;<br \/>\n            &lt;!&#8211;\u53ef\u5728\u91cc\u9762\u914d\u7f6e\u5bf9\u8c61 \u53ef\u7a7a\u53ef\u4e0d\u7a7a&#8211;&gt;<br \/>\n            &lt;bean class&#061;&#034;com.itheima.domain.User&#034;\/&gt;<br \/>\n            &lt;ref bean&#061;&#034;u1&#034;\/&gt;<br \/>\n            &lt;ref bean&#061;&#034;u2&#034;\/&gt;<br \/>\n        &lt;\/List&gt;<br \/>\n    &lt;\/property&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<li>\n<p>\u96c6\u5408\u6570\u636e\u7c7b\u578b(Map&lt;String,User&gt;)\u7684\u6ce8\u5165<\/p>\n<p> public class UserDaoImpl implements UserDao{<br \/>\n    private Map&lt;String,User&gt; userMap;<br \/>\n    public void setUserMap(Map&lt;String,User&gt; userMap){<br \/>\n        this.userMap&#061;userMap;<br \/>\n    }<br \/>\n    public void save(){<br \/>\n        sout(userMap);<br \/>\n        sout(&#034;UserDao save method running&#8230;&#034;);<br \/>\n    }<br \/>\n} &lt;bean id&#061;&#034;u1&#034; class&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;name&#034; value&#061;&#034;tom&#034;\/&gt;<br \/>\n    &lt;property name&#061;&#034;addr&#034; value&#061;&#034;beijing&#034;\/&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;bean id&#061;&#034;u2&#034; class&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;name&#034; value&#061;&#034;lucy&#034;\/&gt;<br \/>\n    &lt;property name&#061;&#034;addr&#034; value&#061;&#034;tianjing&#034;\/&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;userMap&#034;&gt;<br \/>\n        &lt;map&gt;<br \/>\n            &lt;entry key&#061;&#034;user1&#034; value-ref&#061;&#034;u1&#034;\/&gt;<br \/>\n            &lt;entry key&#061;&#034;user2&#034; value-ref&#061;&#034;u2&#034;\/&gt;<br \/>\n        &lt;\/map&gt;<br \/>\n    &lt;\/property&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<li>\n<p>\u96c6\u5408\u6570\u636e\u7c7b\u578b(Properties)\u7684\u6ce8\u5165<\/p>\n<p> public class UserDaoImpl implements UserDao{<br \/>\n    private Properties properties;<br \/>\n    public void setProperties(Properties properties){<br \/>\n        this.properties&#061;properties;<br \/>\n    }<br \/>\n    public void save(){<br \/>\n        sout(properties);<br \/>\n        sout(&#034;UserDao save method running&#8230;&#034;);<br \/>\n    }<br \/>\n} &lt;bean id&#061;&#034;userDao&#034; class&#061;&#034;com.itheima.impl.UserDaoImpl&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;properties&#034;&gt;<br \/>\n    &lt;props&gt;<br \/>\n        &lt;prop key&#061;&#034;p1&#034;&gt;aaa&lt;\/prop&gt;<br \/>\n        &lt;prop key&#061;&#034;p2&#034;&gt;bbb&lt;\/prop&gt;<br \/>\n        &lt;prop key&#061;&#034;p3&#034;&gt;ccc&lt;\/prop&gt;<br \/>\n        &lt;\/props&gt;<br \/>\n    &lt;\/property&gt;<br \/>\n&lt;\/bean&gt; <\/li>\n<h4>3.9 \u5f15\u5165\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6(\u5206\u6a21\u5757\u5f00\u53d1)<\/h4>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;Spring\u7684\u914d\u7f6e\u5185\u5bb9\u975e\u5e38\u591a&#xff0c;\u8fd9\u5c31\u5bfc\u81f4Spring\u914d\u7f6e\u5f88\u7e41\u6742\u4e14\u4f53\u79ef\u5f88\u5927&#xff0c;\u6240\u4ee5&#xff0c;\u53ef\u4ee5\u5c06\u90e8\u5206\u914d\u7f6e\u62c6\u89e3\u5230\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u800c\u5728Spring\u4e3b\u914d\u7f6e\u6587\u4ef6\u901a\u8fc7import\u6807\u7b7e\u8fdb\u884c\u52a0\u8f7d<\/p>\n<p>&lt;import resourse&#061;&#034;applicationContext-xxx.xml&#034;\/&gt; <\/p>\n<h4>3.10 \u603b\u7ed3<\/h4>\n<p>&lt;bean&gt;\u6807\u7b7e<\/p>\n<ul>\n<li>\n<p>id\u5c5e\u6027&#xff1a;\u5728\u5bb9\u5668\u4e2dBean\u5b9e\u4f8b\u7684\u552f\u4e00\u6807\u8bc6&#xff0c;\u4e0d\u5141\u8bb8\u91cd\u590d<\/p>\n<\/li>\n<li>\n<p>class\u5c5e\u6027&#xff1a;\u8981\u5b9e\u4f8b\u5316\u7684Bean\u7684\u5168\u9650\u5b9a\u540d<\/p>\n<\/li>\n<li>\n<p>scope\u5c5e\u6027&#xff1a;Bean\u7684\u4f5c\u7528\u8303\u56f4&#xff0c;\u5e38\u7528\u662fSingleton(\u9ed8\u8ba4)\u548cprototype<\/p>\n<\/li>\n<\/ul>\n<p>&lt;property&gt;\u6807\u7b7e&#xff1a;\u5c5e\u6027\u6ce8\u5165<\/p>\n<ul>\n<li>\n<p>name\u5c5e\u6027&#xff1a;\u5c5e\u6027\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>value\u5c5e\u6027&#xff1a;\u6ce8\u5165\u7684\u666e\u901a\u5c5e\u6027\u503c<\/p>\n<\/li>\n<li>\n<p>ref\u5c5e\u6027&#xff1a;\u6ce8\u5165\u7684\u5bf9\u8c61\u5f15\u7528\u503c<\/p>\n<\/li>\n<\/ul>\n<p>&lt;list&gt;\u6807\u7b7e<\/p>\n<p>&lt; map &gt; \u6807\u7b7e<\/p>\n<p>&lt;properties&gt;\u6807\u7b7e<\/p>\n<p>&lt;constructor-arg&gt;\u6807\u7b7e<\/p>\n<p>&lt;import&gt;\u6807\u7b7e&#xff1a;\u5bfc\u5165\u5176\u4ed6\u7684Spring\u7684\u5206\u6587\u4ef6<\/p>\n<h3>4 Spring\u76f8\u5173API<\/h3>\n<h4>4.1ApplicationContext\u7684\u7ee7\u627f\u4f53\u7cfb<\/h4>\n<p>applicationContext&#xff1a;\u63a5\u53e3\u7c7b\u578b&#xff0c;\u4ee3\u8868\u5e94\u7528\u4e0a\u4e0b\u6587&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u5176\u5b9e\u4f8b\u83b7\u5f97Spring\u5bb9\u5668\u4e2d\u7684Bean\u5bf9\u8c61<\/p>\n<\/p>\n<li>\n<p>ClassPathXmlApplicationContext<\/p>\n<p>\u5b83\u662f\u4ece\u7c7b\u7684\u6839\u8def\u5f84\u4e0b\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6(\u6839\u8def\u5f84\u4e0b\u7684\u6587\u4ef6\u540d) \u63a8\u8350\u4f7f\u7528\u8fd9\u79cd<\/p>\n<p>(ApplicationContext application Context&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;));<\/p>\n<\/li>\n<li>\n<p>FileSystemXmlApplicationContext<\/p>\n<p>\u5b83\u662f\u4ece\u78c1\u76d8\u8def\u5f84\u4e0a\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6&#xff0c;\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u5728\u78c1\u76d8\u7684\u4efb\u610f\u4f4d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>AnnotationConfigApplicationContext<\/p>\n<p>\u5f53\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u5bb9\u5668\u5bf9\u8c61\u65f6&#xff0c;\u9700\u8981\u4f7f\u7528\u6b64\u7c7b\u6765\u521b\u5efaspring\u5bb9\u5668\u3002\u5b83\u7528\u6765\u8bfb\u53d6\u6ce8\u89e3\u3002<\/p>\n<\/li>\n<h4>4.3 getBean()\u65b9\u6cd5\u4f7f\u7528<\/h4>\n<p>public Object getBean(String name)throws BeansException{<br \/>\n    assertBeanFactoryActive();<br \/>\n    return getBeanFactory().getBean(name);<br \/>\n}<\/p>\n<p>public &lt;T&gt; T getBean(Class&lt;T&gt; requiredType)throws BeansException{<br \/>\n    assertBeanFactoryActive();<br \/>\n    return getBeanFactory().getBean(requiredType);<br \/>\n} <\/p>\n<p>\u5176\u4e2d&#xff0c;\u5f53\u53c2\u6570\u7684\u6570\u636e\u7c7b\u578b\u662f\u5b57\u7b26\u4e32\u65f6&#xff0c;\u8868\u793a\u6839\u636eBean\u7684id\u4ece\u5bb9\u5668\u4e2d\u83b7\u5f97Bean\u5b9e\u4f8b&#xff0c;\u8fd4\u56de\u662fObject&#xff0c;\u9700\u8981\u5f3a\u8f6c\u3002\u5f53\u53c2\u6570\u7684\u6570\u636e\u7c7b\u578b\u662fClass\u7c7b\u578b\u65f6&#xff0c;\u8868\u793a\u6839\u636e\u7c7b\u578b\u4ece\u5bb9\u5668\u4e2d\u5339\u914dBean\u5b9e\u4f8b&#xff0c;\u5f53\u5bb9\u5668\u4e2d\u76f8\u540c\u7c7b\u578b\u7684Bean\u6709\u591a\u4e2a\u65f6&#xff0c;\u5219\u6b64\u65b9\u6cd5\u4f1a\u62a5\u9519\u3002<\/p>\n<li>\n<p>\u7b2c\u4e00\u79cd<\/p>\n<p> \u4ee3\u7801\u5982\u4e0b&#xff1a;<br \/>\nUserService userService&#061;(UserService)applicationContext.getBean(userService); <\/p>\n<p>\u533a\u522b&#xff1a;<\/p>\n<p>1&#xff09;\u5b83\u662f\u8c03\u7528xml\u7684id\u503c\u8fdb\u884c\u58f0\u660e\u5bf9\u8c61&#xff0c;\u4f7f\u7528\u8303\u56f4\u6700\u597d\u662f\u591a\u4f8b\u6a21\u5f0f\u4e0b&#xff0c;\u56e0\u4e3a\u5355\u4f8b\u6a21\u5f0f\u53e6\u4e00\u79cd\u65b9\u6cd5\u4f1a\u62a5\u9519<\/p>\n<p>2&#xff09;\u58f0\u660e\u5bf9\u8c61\u65f6\u9700\u8981\u5f3a\u8f6c\u5bf9\u8c61&#xff0c;\u9ed8\u8ba4\u4e3aObject<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u79cd<\/p>\n<p> \u4ee3\u7801\u5982\u4e0b&#xff1a;<br \/>\nUserService userService&#061;ApplicationContext.getBean(UserService.class); <\/p>\n<p>\u533a\u522b&#xff1a;<\/p>\n<p>1&#xff09;\u5b83\u662f\u76f4\u63a5\u8c03\u7528\u7c7b\u540d\u8fdb\u884c\u58f0\u660e\u5bf9\u8c61&#xff0c;\u4f46\u591a\u4f8b\u6a21\u5f0f\u4e0b\u591a\u4e2a\u540c\u7c7b\u578b\u7684Bean\u65f6&#xff0c;\u4f1a\u62a5\u9519<\/p>\n<p>2&#xff09;\u58f0\u660e\u5bf9\u8c61\u65f6\u4e0d\u9700\u8981\u5f3a\u8f6c\u5bf9\u8c61<\/p>\n<\/li>\n<h4>4.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>Spring\u7684\u91cd\u70b9API<\/p>\n<p>ApplicationContext app&#061;new ClasspathXmlApplicationContext(&#034;xml\u6587\u4ef6&#034;);<br \/>\napp.getBean(&#034;id&#034;);<br \/>\napp.getBean(Class) <\/p>\n<h2>02_SpringloC\u548cDI\u6ce8\u89e3\u5f00\u53d1<\/h2>\n<h3>1. Spring\u914d\u7f6e\u6570\u636e\u6e90<\/h3>\n<h4>1.1 \u6570\u636e\u6e90(\u8fde\u63a5\u6c60)\u7684\u4f5c\u7528<\/h4>\n<ul>\n<li>\n<p>\u6570\u636e\u6e90(\u8fde\u63a5\u6c60)\u662f\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u51fa\u73b0\u7684<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u5148\u5b9e\u4f8b\u5316\u6570\u636e\u6e90&#xff0c;\u521d\u59cb\u5316\u90e8\u5206\u8fde\u63a5\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u8fde\u63a5\u8d44\u6e90\u65f6\u4ece\u6570\u636e\u6e90\u4e2d\u83b7\u53d6<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5b8c\u6bd5\u540e\u5c06\u8fde\u63a5\u8d44\u6e90\u5f52\u8fd8\u6570\u636e\u6e90<\/p>\n<\/li>\n<\/ul>\n<p>\u5e38\u89c1\u7684\u6570\u636e\u6e90(\u8fde\u63a5\u6c60)&#xff1a;DBCP\u3001C3P0\u3001BoneCP\u3001Druid\u7b49<\/p>\n<h4>1.2 \u6570\u636e\u6e90\u7684\u5f00\u53d1\u6b65\u9aa4<\/h4>\n<li>\n<p>\u5bfc\u5165\u6570\u636e\u6e90\u7684\u5750\u6807\u548c\u6570\u636e\u5e93\u9a71\u52a8\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u6570\u636e\u6e90\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u6570\u636e\u6e90\u7684\u57fa\u672c\u8fde\u63a5\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6570\u636e\u6e90\u83b7\u53d6\u8fde\u63a5\u8d44\u6e90\u548c\u5f52\u8fd8\u8fde\u63a5\u8d44\u6e90<\/p>\n<\/li>\n<h4>1.3 \u6570\u636e\u6e90\u7684\u624b\u52a8\u521b\u5efa<\/h4>\n<li>\n<p>\u5bfc\u5165C3P0\u548cDruid\u7684\u5750\u6807 pom.xml<\/p>\n<p> &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;com.mchange&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;c3p0&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;0.9.5.5&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n            &lt;groupId&gt;junit&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;4.12&lt;\/version&gt;<br \/>\n            &lt;scope&gt;test&lt;\/scope&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n            &lt;groupId&gt;com.alibaba&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;druid&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.2.4&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u5bfc\u5165mysql\u6570\u636e\u5e93\u9a71\u52a8\u5750\u6807<\/p>\n<p> &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;mysql&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;8.0.22&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u521b\u5efaC3P0\u8fde\u63a5\u6c60<\/p>\n<p> public class DataSourceTest {<br \/>\n    &#064;Test<br \/>\n    \/\/\u6d4b\u8bd5\u624b\u52a8\u521b\u5efac3p0\u6570\u636e\u6e90<br \/>\n    public void test1() throws Exception {<br \/>\n        ComboPooledDataSource dataSource&#061;new ComboPooledDataSource();<br \/>\n        dataSource.setDriverClass(&#034;com.mysql.cj.jdbc.Driver&#034;);<br \/>\n        dataSource.setJdbcUrl(&#034;jdbc:mysql:\/\/localhost:3306\/how2java?useSSL&#061;false&amp;useUnicode&#061;true&amp;characterEncoding&#061;utf-8&amp;serverTimeZone&#061;GMT&#034;);<br \/>\n        dataSource.setUser(&#034;root&#034;);<br \/>\n        dataSource.setPassword(&#034;admin&#034;);<br \/>\n        Connection connection &#061; dataSource.getConnection();<br \/>\n        System.out.println(connection);<br \/>\n        connection.close();<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u521b\u5efaDruid\u8fde\u63a5\u6c60<\/p>\n<p> &#064;Test<br \/>\npublic void testDruid()throws Exception{<br \/>\n    \/\/\u521b\u5efa\u6570\u636e\u6e90<br \/>\n    DruidDataSource dataSource&#061;new DruidDataSource();<br \/>\n    \/\/\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570<br \/>\n    dataSource.setDriverClassName(&#034;com.mysql.cj.jdbc.Driver&#034;);<br \/>\n    dataSource.setUrl(&#034;jdbc:mysql:\/\/localhost:3306\/how2java?useSSL&#061;false&amp;useUnicode&#061;true&amp;characterEncoding&#061;utf-8&amp;serverTimeZone&#061;GMT&#034;);<br \/>\n    dataSource.setUserName(&#034;root&#034;);<br \/>\n    dataSource.setPassword(&#034;admin&#034;);<br \/>\n    \/\/\u83b7\u5f97\u8fde\u63a5\u5bf9\u8c61<br \/>\n    Connection connection&#061;dataSource.getConnection();<br \/>\n    sout(connection);<br \/>\n} <\/li>\n<li>\n<p>\u63d0\u53d6jdbc.properties\u914d\u7f6e\u6587\u4ef6<\/p>\n<p> jdbc.driver&#061;com.mysql.jdbc.Driver<br \/>\njdbc.url&#061;jdbc:mysql:\/\/localhost:3306\/how2java?useSSL&#061;false&amp;useUnicode&#061;true&amp;characterEncoding&#061;utf-8&amp;serverTimeZone&#061;GMT<br \/>\njdbc.username&#061;root<br \/>\njdbc.password&#061;admin <\/li>\n<li>\n<p>\u8bfb\u53d6jdbc.properties\u914d\u7f6e\u6587\u4ef6\u521b\u5efa\u8fde\u63a5\u6c60<\/p>\n<p> &#064;Test<br \/>\npublic void testC3P0ByProperties() throws Exception{<br \/>\n    \/\/\u52a0\u8f7d\u7c7b\u8def\u5f84\u4e0b\u7684jdbc.properties<br \/>\n    ResourceBundle rb&#061;ResourceBundle.getBundle(&#034;jdbc&#034;);<br \/>\n    ComboPooledDataSource dataSource&#061;new ComboPooledDataSource();<br \/>\n    dataSource.setDriverClass(rb.getString(&#034;jdbc.driver&#034;));<br \/>\n    dataSource.setJdbcUrl(rb.getString(&#034;jdbc.url&#034;));<br \/>\n    dataSource.setUser(rb.getString(&#034;jdbc.username&#034;));<br \/>\n    dataSource.setPassword(rb.getString(&#034;jdbc.password&#034;));<br \/>\n    Connection connection&#061;dataSource.getConnection();<br \/>\n    sout(connection);<br \/>\n} <\/li>\n<h4>1.3 Spring\u914d\u7f6e\u6570\u636e\u6e90<\/h4>\n<p>\u53ef\u4ee5\u5c06DataSource\u7684\u521b\u5efa\u6743\u4ea4\u7531Spring\u5bb9\u5668\u53bb\u5b8c\u6210<\/p>\n<ul>\n<li>\n<p>DataSource\u6709\u65e0\u60e8\u6784\u9020\u65b9\u6cd5&#xff0c;\u800cSpring\u9ed8\u8ba4\u5c31\u662f\u901a\u8fc7\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684<\/p>\n<\/li>\n<li>\n<p>DataSource\u8981\u60f3\u4f7f\u7528\u9700\u8981\u901a\u8fc7set\u65b9\u6cd5\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f&#xff0c;\u800cSpring\u53ef\u4ee5\u901a\u8fc7set\u65b9\u6cd5\u8fdb\u884c\u5b57\u7b26\u4e32\u6ce8\u5165<\/p>\n<p>     &lt;bean id&#061;&#034;dataSourse&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;driverClass&#034; value&#061;&#034;com.mysql.cj.jdbc.Driver&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;jdbcUrl&#034; value&#061;&#034;jdbc:mysql:\/\/localhost:3306\/how2java?useSSL&#061;false&amp;amp;useUnicode&#061;true&amp;amp;characterEncoding&#061;utf-8&amp;amp;serverTimeZone&#061;GMT&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;user&#034; value&#061;&#034;root&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;password&#034; value&#061;&#034;admin&#034;\/&gt;<br \/>\n    &lt;\/bean&gt; <\/p>\n<p>\u6d4b\u8bd5\u4ece\u5bb9\u5668\u5f53\u4e2d\u83b7\u53d6\u6570\u636e\u6e90<\/p>\n<p>     &#064;Test<br \/>\n    public void test04() throws SQLException {<br \/>\n        ApplicationContext applicationContext&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        DataSource dataSourse &#061; (DataSource) applicationContext.getBean(&#034;dataSourse&#034;);<br \/>\n        Connection connection &#061; dataSourse.getConnection();<br \/>\n        System.out.println(connection);<br \/>\n        connection.close();<br \/>\n    } <\/li>\n<\/ul>\n<h4>1.4\u62bd\u53d6jdbc\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p>applicationContext.xml\u52a0\u8f7djdbc.properties\u914d\u7f6e\u6587\u4ef6\u83b7\u5f97\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u9700\u8981\u5f15\u5165context\u547d\u540d\u7a7a\u95f4\u548c\u7ea6\u675f\u8def\u5f84&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u547d\u540d\u7a7a\u95f4&#xff1a;xmlns:context&#061;&#034;Index of \/schema\/context&#034;&#xff08;\u590d\u5236beans\u90a3\u4e2a \u52a0context\u548c\u6539context&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7ea6\u675f\u8def\u5f84&#xff1a;Index of \/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd<\/p>\n<\/li>\n<\/ul>\n<p>&lt;context:property-placeholder location&#061;&#034;classpath:jdbc.properties&#034;\/&gt;<\/p>\n<p>    &lt;bean id&#061;&#034;dataSourse&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;driverClass&#034; value&#061;&#034;${jdbc.driver}&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;jdbcUrl&#034; value&#061;&#034;${jdbc.url}&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;user&#034; value&#061;&#034;${jdbc.username}&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;password&#034; value&#061;&#034;${jdbc.password}&#034;\/&gt;<br \/>\n    &lt;\/bean&gt;<br \/>\n    &#064;Test<br \/>\n    public void test04() throws SQLException {<br \/>\n        ApplicationContext applicationContext&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        DataSource dataSourse &#061; (DataSource) applicationContext.getBean(&#034;dataSourse&#034;);<br \/>\n        Connection connection &#061; dataSourse.getConnection();<br \/>\n        System.out.println(connection);<br \/>\n        connection.close();<br \/>\n    } <\/p>\n<h4>1.5 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>Spring\u5bb9\u5668\u52a0\u8f7dproperties\u6587\u4ef6<\/p>\n<p>&lt;context:propety-placeholder location&#061;&#034;xx.properties&#034;\/&gt;<br \/>\n&lt;property name&#061;&#034;&#034; value&#061;&#034;${key}&#034;\/&gt; <\/p>\n<h3>2. Spring\u6ce8\u89e3\u5f00\u53d1<\/h3>\n<h4>2.1 Spring\u539f\u59cb\u6ce8\u89e3<\/h4>\n<p>Spring\u662f\u8f7b\u4ee3\u7801\u800c\u91cd\u914d\u7f6e\u7684\u6846\u67b6&#xff0c;\u914d\u7f6e\u7b14\u8bb0\u7e41\u91cd&#xff0c;\u5f71\u54cd\u5f00\u53d1\u6548\u7387&#xff0c;\u6240\u4ee5\u6ce8\u89e3\u5f00\u53d1\u662f\u4e00\u79cd\u8d8b\u52bf&#xff0c;\u6ce8\u89e3\u4ee3\u66ffxml\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u7b80\u5316\u914d\u7f6e&#xff0c;\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p>Spring\u539f\u59cb\u6ce8\u89e3\u4e3b\u8981\u662f\u66ff\u4ee3&lt;Bean&gt;\u7684\u914d\u7f6e<\/p>\n<table>\n<tr>\u6ce8\u89e3\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>&#064;Component<\/td>\n<td>\u4f7f\u7528\u5728\u7c7b\u4e0a\u7528\u4e8e\u5b9e\u4f8b\u5316Bean<\/td>\n<\/tr>\n<tr>\n<td>&#064;Controller<\/td>\n<td>\u4f7f\u7528\u5728web\u5c42\u7c7b\u4e0a\u7528\u4e8e\u5b9e\u4f8b\u5316Bean<\/td>\n<\/tr>\n<tr>\n<td>&#064;Service<\/td>\n<td>\u4f7f\u7528\u5728service\u5c42\u7c7b\u4e0a\u7528\u4e8e\u5b9e\u4f8b\u5316Bean<\/td>\n<\/tr>\n<tr>\n<td>&#064;Repository<\/td>\n<td>\u4f7f\u7528\u5728dao\u5c42\u7c7b\u4e0a\u7528\u4e8e\u5b9e\u4f8b\u5316Bean<\/td>\n<\/tr>\n<tr>\n<td>&#064;Autowired<\/td>\n<td>\u4f7f\u7528\u5728\u5b57\u6bb5\u4e0a\u7528\u4e8e\u6839\u636e\u7c7b\u578b\u4f9d\u8d56\u6ce8\u5165<\/td>\n<\/tr>\n<tr>\n<td>&#064;Qualifier<\/td>\n<td>\u7ed3\u5408&#064;Autowired\u4e00\u8d77\u4f7f\u7528\u7528\u4e8e\u6839\u636e\u540d\u79f0\u8fdb\u884c\u4f9d\u8d56\u6ce8\u5165<\/td>\n<\/tr>\n<tr>\n<td>&#064;Resource<\/td>\n<td>\u76f8\u5f53\u4e8e&#064;Autowired&#043;&#064;Qualifiers&#xff0c;\u6309\u7167\u540d\u79f0\u8fdb\u884c\u6ce8\u5165<\/td>\n<\/tr>\n<tr>\n<td>&#064;Value<\/td>\n<td>\u6ce8\u5165\u666e\u901a\u5c5e\u6027<\/td>\n<\/tr>\n<tr>\n<td>&#064;Scope<\/td>\n<td>\u6807\u6ce8Bean\u7684\u4f5c\u7528\u8303\u56f4<\/td>\n<\/tr>\n<tr>\n<td>&#064;PostConstruct<\/td>\n<td>\u4f7f\u7528\u5728\u65b9\u6cd5\u4e0a\u6807\u6ce8\u8be5\u65b9\u6cd5\u662fBean\u7684\u521d\u59cb\u5316\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>&#064;PreDestroy<\/td>\n<td>\u4f7f\u7528\u5728\u65b9\u6cd5\u4e0a\u6807\u6ce8\u8be5\u65b9\u6cd5\u662fBean\u7684\u9500\u6bc1\u65b9\u6cd5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<p>\u4f7f\u7528\u6ce8\u89e3\u8fdb\u884c\u5f00\u53d1\u65f6&#xff0c;\u9700\u8981\u5728applicationContext.xml\u4e2d\u914d\u7f6e\u7ec4\u4ef6\u626b\u63cf&#xff0c;\u4f5c\u7528\u662f\u6307\u5b9a\u54ea\u4e2a\u5305\u53ca\u5176\u5b50\u5305\u4e0b\u7684Bean\u9700\u8981\u8fdb\u884c\u626b\u63cf\u4ee5\u4fbf\u8bc6\u522b\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u7684\u7c7b\u3001\u5b57\u6bb5\u548c\u65b9\u6cd5\u3002<\/p>\n<p>&lt;!&#8211;\u6ce8\u89e3\u7684\u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima&#034;&gt;&lt;\/context:component-scan&gt; <\/p>\n<p>\u4f7f\u7528&#064;Component\u7ed9UserDao\u548cUserService\u521b\u5efa\u5bf9\u8c61&#xff0c;\u5e76\u8c03\u7528UserCtroller\u770b\u770b\u662f\u5426\u6210\u529f<\/p>\n<p>&#064;Component(&#034;userDao&#034;)<br \/>\npublic class UserDaoImpl implements UserDao{<br \/>\n    &#064;Override<br \/>\n    public void save(){<br \/>\n        sout(&#034;save running&#8230;&#034;);<br \/>\n    }<br \/>\n}<br \/>\n&#064;Component(&#034;userService&#034;)<br \/>\n\/\/&#064;sScope(&#034;prototype&#034;) \u591a\u4f8b\u6a21\u5f0f\u548c\u5355\u4f8b\u6a21\u5f0f\u7684\u6ce8\u89e3<br \/>\npublic class UserServiceImpl implements UserService{<br \/>\n    \/\/\u5c06userDao\u5bf9\u8c61\u6ce8\u5165\u8fdb\u53bb<br \/>\n    \/\/\u5728xml\u914d\u7f6e\u5bf9\u8c61\u90a3\u79cd\u662f\u9700\u8981set\u65b9\u6cd5\u548c\u6709\u53c2\u6784\u9020\u65b9\u6cd5&#xff0c;\u800c\u4e3b\u952e\u901a\u8fc7\u53cd\u5c04&#xff0c;\u6240\u4ee5\u4e0d\u9700\u8981set\u65b9\u6cd5<br \/>\n    \/\/&#064;Autwired\/\/\u6309\u7167\u6570\u636e\u7c7b\u578b\u4eceSpring\u5bb9\u5668\u4e2d\u8fdb\u884c\u5339\u914d\u7684 \u770bbean\u91cc\u9762\u6709\u6ca1\u6709\u8ddfuserDao\u5dee\u4e0d\u591a\u7684&#xff0c;\u5355\u4e2a\u53ef\u4ee5\u4f7f\u7528&#xff0c;\u591a\u4e2a\u4e0d\u5efa\u8bae\u4f7f\u7528<br \/>\n    \/\/&#064;Qualifier(&#034;userDao&#034;)\/\/\u662f\u6839\u636eid\u503c\u4ece\u5bb9\u5668\u4e2d\u8fdb\u884c\u5339\u914d\u7684&#xff0c;\u4f46\u662f\u4e3b\u8981\u6b64\u5904\u8981\u7ed3\u5408&#064;Autwired\u4f7f\u7528<br \/>\n    &#064;Resourse(name&#061;&#034;userDao&#034;)\/\/&#064;Resourse\u76f8\u5f53\u4e8e&#064;Autwired&#043;&#064;Qualifier<br \/>\n    private UserDao userDao;<\/p>\n<p>    &#064;Override<br \/>\n    public void save(){<br \/>\n        userDao.save();<br \/>\n    }<\/p>\n<p>    &#064;PostConstruct<br \/>\n    public void init(){<br \/>\n        sout(&#034;\u521d\u59cb\u5316&#034;);<br \/>\n    }<\/p>\n<p>    &#064;PreDestory<br \/>\n    public void destory(){<br \/>\n        sout(&#034;\u9500\u6bc1&#034;);<br \/>\n    }<br \/>\n}<br \/>\n&lt;!&#8211;\u914d\u7f6exmln\u7684context\u548c\u4e0b\u9762\u7f51\u9875\u7684context&#8211;&gt;<br \/>\n&lt;!&#8211;\u914d\u7f6e\u4e3b\u952e\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt;<br \/>\npublic class UserContoller{<br \/>\n    main{<br \/>\n        ApplicationContext app&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        UserService bean&#061;app.getBean(UserService.class);<br \/>\n        bean.save();<br \/>\n    }<br \/>\n} <\/p>\n<li>\n<p>&#064;Component\u662f\u7c7b\u4e2d\u5b9e\u4f8b\u5316\u5bf9\u8c61&#xff0c;\u800c&#064;Service\u3001&#064;Repository\u3001&#064;Controller\u662f\u5728\u5bf9\u5e94\u5c42\u7684\u7c7b\u5b9e\u4f8b\u5316\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u5165\u666e\u901a\u5c5e\u6027<\/p>\n<p> &#064;Value(&#034;itcast&#034;)<br \/>\nprivate String name;<br \/>\n\/\/name&#061;itcast \u8f83\u9ebb\u70e6&#xff0c;\u4f46\u8fd9\u4e2a\u7528\u6cd5\u6700\u597d\u7684\u4f53\u73b0\u5982\u4e0b &lt;!&#8211;\u52a0\u8f7d\u5916\u90e8\u7684properties\u6587\u4ef6&#8211;&gt;<br \/>\n&lt;context:property-placeholder location&#061;&#034;classpath:jdbc.properties&#034;\/&gt; &#064;Value(&#034;${jdbc.driver}&#034;)<br \/>\nprivate String driver;<br \/>\n\/\/driver&#061;com.mysql.cj.jdbc.Driver <\/li>\n<h4>2.2 Spring\u65b0\u6ce8\u89e3<\/h4>\n<p>\u4f7f\u7528\u4e0a\u9762\u7684\u6ce8\u89e3\u8fd8\u4e0d\u80fd\u5168\u90e8\u66ff\u4ee3xml\u914d\u7f6e\u6587\u4ef6&#xff0c;\u8fd8\u9700\u8981\u4f7f\u7528\u6ce8\u89e3\u66ff\u4ee3\u7684\u914d\u7f6e\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u975e\u81ea\u5b9a\u4e49\u7684Bean\u7684\u914d\u7f6e&#xff1a;&lt;bean&gt;<\/p>\n<\/li>\n<li>\n<p>\u52a0\u8f7dproperties\u6587\u4ef6\u7684\u914d\u7f6e&#xff1a;&lt;context:property-placeholder&gt;<\/p>\n<\/li>\n<li>\n<p>\u7ec4\u4ef6\u626b\u63cf\u7684\u914d\u7f6e&#xff1a;&lt;context:component-scan&gt;<\/p>\n<\/li>\n<li>\n<p>\u5f15\u5165\u5176\u4ed6\u6587\u4ef6&#xff1a;&lt;import&gt;<\/p>\n<\/li>\n<\/ul>\n<table>\n<tr>\u6ce8\u89e3\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>&#064;Configuration<\/td>\n<td>\u7528\u4e8e\u6307\u5b9a\u5f53\u524d\u7c7b\u662f\u4e00\u4e2aSpring\u914d\u7f6e\u7c7b&#xff0c;\u5f53\u521b\u5efa\u5bb9\u5668\u65f6\u4f1a\u4ece\u8be5\u7c7b\u4e0a\u52a0\u8f7d\u6ce8\u89e3<\/td>\n<\/tr>\n<tr>\n<td>&#064;ComponentScan<\/td>\n<td>\u7528\u4e8e\u6307\u5b9aSpring\u5728\u521d\u59cb\u5316\u5bb9\u5668\u65f6\u8981\u626b\u63cf\u7684\u5305 \u4f5c\u7528\u548c\u5728spring\u7684xml\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684&lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt;\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>&#064;Bean<\/td>\n<td>\u4f7f\u7528\u5728\u65b9\u6cd5\u4e0a&#xff0c;\u6807\u6ce8\u5c06\u8be5\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u5b58\u50a8\u5230\u5230Spring\u5bb9\u5668\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>&#064;PropertySource<\/td>\n<td>\u7528\u4e8e\u52a0\u8f7d.properties\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e<\/td>\n<\/tr>\n<tr>\n<td>&#064;Import<\/td>\n<td>\u7528\u4e8e\u5bfc\u5165\u5176\u4ed6\u914d\u7f6e\u7c7b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\/\/\u8be5\u7c7b\u662fSpring\u7684\u6838\u5fc3\u914d\u7f6e\u7c7b<br \/>\n&#064;Configuration<br \/>\n\/*&lt;!&#8211;\u914d\u7f6e\u4e3b\u952e\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt;*\/<br \/>\n&#064;ComponentScan(&#034;com.itheima&#034;)<br \/>\n\/\/&lt;context:property-placeholder location&#061;&#034;classpath:jdbc.properties&#034;\/&gt;<br \/>\n&#064;PropertySource(&#034;classpath:jdbc.properties&#034;)<br \/>\n\/\/\u914d\u7f6e\u8fc7\u591a\u8fc7\u6742\u4e71&#xff0c;\u53ef\u4ee5\u5199\u591a\u4e2a&#xff0c;\u7136\u540e\u6ce8\u5165\u5728\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d<br \/>\n&#064;Import(DataSourceConfiguration.class)<br \/>\npublic class SpringConfiguration {<br \/>\n    &#064;Value(&#034;${jdbc.driver}&#034;)<br \/>\n    private String driver;<\/p>\n<p>    &#064;Value(&#034;${jdbc.jdbc.url}&#034;)<br \/>\n    private String url;<\/p>\n<p>    &#064;Value(&#034;${jdbc.username}&#034;)<br \/>\n    private String username;<\/p>\n<p>    &#064;Value(&#034;${jdbc.password}&#034;)<br \/>\n    private String password;<\/p>\n<p>    &#064;Bean(name&#061;&#034;dataSource&#034;) \/\/Spring\u4f1a\u5c06\u5f53\u524d\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4ee5\u6307\u5b9a\u540d\u79f0\u5b58\u50a8\u5230Spring\u5bb9\u5668\u4e2d<br \/>\n    public DataSource getDataSource() throws Exception {<br \/>\n        ComboPooledDataSource dataSource &#061; new ComboPooledDataSource();<br \/>\n        dataSource.setDriverClass(driver);<br \/>\n        dataSource.setJdbcUrl(url);<br \/>\n        dataSource.setUser(username);<br \/>\n        dataSource.setPassword(password);<br \/>\n        return dataSource;<br \/>\n    }<br \/>\n}<br \/>\npublic class UserContoller {<br \/>\n    public static void main(String[] args) throws SQLException {<br \/>\n        \/\/ApplicationContext app&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        ApplicationContext app&#061;new AnnotationConfigApplicationContext(SpringConfiguration.class);<br \/>\n        UserService bean &#061; app.getBean(UserService.class);<br \/>\n        bean.save();<br \/>\n        DataSource bean1 &#061; app.getBean(DataSource.class);<br \/>\n        Connection connection &#061; bean1.getConnection();<br \/>\n        System.out.println(connection);<br \/>\n    }<br \/>\n} <\/p>\n<h3>3. Spring\u96c6\u6210Junit<\/h3>\n<h4>3.1 \u539f\u59cbJunit\u6d4b\u8bd5Spring\u7684\u95ee\u9898<\/h4>\n<p>\u5728\u6d4b\u8bd5\u7c7b\u4e2d&#xff0c;\u6bcf\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u90fd\u6709\u4e00\u4e0b\u4e24\u884c\u4ee3\u7801&#xff1a;<\/p>\n<p>ApplicationContext ac&#061;new ClassPathXmlApplicationContext(&#034;bean.xml&#034;);<br \/>\nIAccountService as&#061;ac.getBean(&#034;accountService&#034;,IAccountService.class); <\/p>\n<p>\u8fd9\u4e24\u884c\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u83b7\u53d6\u5bb9\u5668&#xff0c;\u5982\u679c\u4e0d\u5199\u7684\u8bdd&#xff0c;\u76f4\u63a5\u4f1a\u63d0\u793a\u7a7a\u6307\u9488\u5f02\u5e38\u3002\u6240\u4ee5\u53c8\u4e0d\u80fd\u8f7b\u6613\u5220\u6389\u3002<\/p>\n<h4>3.2\u4e0a\u8ff0\u95ee\u9898\u89e3\u51b3\u601d\u8def<\/h4>\n<ul>\n<li>\n<p>\u8ba9SpringJunit\u8d1f\u8d23\u521b\u5efaSpring\u5bb9\u5668&#xff0c;\u4f46\u662f\u9700\u8981\u5c06\u914d\u7f6e\u6587\u4ef6\u7684\u540d\u79f0\u544a\u8bc9\u5b83<\/p>\n<\/li>\n<li>\n<p>\u5c06\u9700\u8981\u8fdb\u884c\u6d4b\u8bd5Bean\u76f4\u63a5\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u8fdb\u884c\u6ce8\u5165<\/p>\n<\/li>\n<\/ul>\n<h4>3.3 Spring\u96c6\u6210Junit\u6b65\u9aa4<\/h4>\n<li>\n<p>\u5bfc\u5165spring\u96c6\u6210Junit\u7684\u5750\u6807<\/p>\n<p> &lt;dependency&gt;<br \/>\n     &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n     &lt;artifactId&gt;spring-test&lt;\/artifactId&gt;<br \/>\n     &lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u4f7f\u7528&#064;Runwith\u6ce8\u89e3\u66ff\u6362\u539f\u6765\u7684\u8fd0\u884c\u671f<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528&#064;ContextConfiguration\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u6216\u914d\u7f6e\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528&#064;Autowired\u6ce8\u5165\u9700\u8981\u6d4b\u8bd5\u7684\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u6d4b\u8bd5\u65b9\u6cd5\u8fdb\u884c\u6d4b\u8bd5<\/p>\n<p> &#064;RunWith(SpringJUnit4ClassRunner.class)<br \/>\n\/\/&#064;ContextConfiguration(&#034;classpath:applicationContext.xml&#034;)\u5f53\u7528\u914d\u7f6e\u6587\u4ef6\u7528\u8fd9\u4e2a<br \/>\n&#064;ContextConfiguration(classes &#061; SpringConfiguration.class)<br \/>\npublic class SpringJunitTest {<br \/>\n    &#064;Autowired<br \/>\n    private DataSource dataSource;<\/p>\n<p>    &#064;Test<br \/>\n    public void test02() throws SQLException {<br \/>\n        System.out.println(dataSource.getConnection());<br \/>\n    }<br \/>\n} <\/li>\n<\/p>\n<h2>03_Spring\u7684AOP<\/h2>\n<h3>1. Spring\u7684AOP\u7b80\u4ecb<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662fAOP<\/h4>\n<p>AOP\u4e3a Aspect Oriented Programming \u7684\u7f29\u5199&#xff0c;\u610f\u601d\u4e3a\u9762\u5411\u5207\u9762\u7f16\u7a0b&#xff0c;\u662f\u901a\u8fc7\u9884\u7f16\u8bd1\u65b9\u5f0f\u548c\u8fd0\u884c\u671f\u52a8\u6001\u4ee3\u7406\u5b9e\u8bad\u7a0b\u5e8f\u529f\u80fd\u7edf\u4e00\u7ef4\u62a4\u7684\u4e00\u79cd\u6280\u672f\u3002<\/p>\n<p>AOP\u662fOOP\u7684\u5ef6\u7eed&#xff0c;\u662f\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u7684\u4e00\u4e2a\u70ed\u70b9&#xff0c;\u4e5f\u662fSpring\u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u5185\u5bb9&#xff0c;\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u4e00\u79cd\u884d\u751f\u8303\u578b\u3002\u5229\u7528AOP\u53ef\u4ee5\u5bf9\u4e1a\u52a1\u903b\u8f91\u7684\u5404\u4e2a\u90e8\u5206\u8fdb\u884c\u9694\u79bb&#xff0c;\u4ece\u800c\u4f7f\u5f97\u4e1a\u52a1\u903b\u8f91\u5404\u90e8\u5206\u4e4b\u95f4\u7684\u8026\u5408\u5ea6\u964d\u4f4e&#xff0c;\u63d0\u9ad8\u7a0b\u5e8f\u7684\u53ef\u91cd\u7528\u6027&#xff0c;\u540c\u65f6\u63d0\u9ad8\u7684\u5f00\u53d1\u7684\u6548\u7387\u3002<\/p>\n<h4>1.2 AOP\u7684\u4f5c\u7528\u53ca\u5176\u4f18\u52bf<\/h4>\n<ul>\n<li>\n<p>\u4f5c\u7528&#xff1a;\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4&#xff0c;\u5728\u4e0d\u4fee\u6539\u6e90\u7801\u7684\u60c5\u51b5\u4e0b\u5bf9\u65b9\u8fdb\u884c\u529f\u80fd\u589e\u5f3a<\/p>\n<\/li>\n<li>\n<p>\u4f18\u52bf&#xff1a;\u51cf\u5c11\u91cd\u590d\u4ee3\u7801&#xff0c;\u63d0\u9ad8\u5f00\u53d1\u6548\u7387&#xff0c;\u5e76\u4e14\u4fbf\u4e8e\u7ef4\u62a4<\/p>\n<\/li>\n<\/ul>\n<h4>1.3 AOP\u7684\u5e95\u5c42\u5b9e\u73b0<\/h4>\n<p>\u5b9e\u9645\u4e0a&#xff0c;AOP\u7684\u5e95\u5c42\u662f\u901a\u8fc7Spring\u63d0\u4f9b\u7684\u52a8\u6001\u4ee3\u7406\u6280\u672f\u5b9e\u73b0\u7684\u3002\u5728\u8fd0\u884c\u671f\u95f4&#xff0c;Spring\u901a\u8fc7\u52a8\u6001\u4ee3\u7406\u6280\u672f\u52a8\u6001\u7684\u751f\u6210\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u65b9\u6cd5\u6267\u884c\u65f6\u8fdb\u884c\u589e\u5f3a\u529f\u80fd\u7684\u4ecb\u5165&#xff0c;\u5728\u53bb\u8c03\u7528\u76ee\u6807\u5bf9\u8c61\u7684\u65b9\u6cd5&#xff0c;\u4ece\u800c\u5b8c\u6210\u529f\u80fd\u7684\u589e\u5f3a\u3002<\/p>\n<h4>1.4 AOP\u7684\u52a8\u6001\u4ee3\u7406\u6280\u672f<\/h4>\n<p>\u5e38\u7528\u7684\u52a8\u6001\u4ee3\u7406\u6280\u672f<\/p>\n<ul>\n<li>\n<p>JDK\u4ee3\u7406&#xff1a;\u57fa\u4e8e\u63a5\u53e3\u7684\u52a8\u6001\u4ee3\u7406\u6280\u672f<\/p>\n<\/li>\n<li>\n<p>cglib\u4ee3\u7406&#xff1a;\u57fa\u4e8e\u7236\u7c7b\u7684\u52a8\u6001\u4ee3\u7406\u6280\u672f<\/p>\n<\/li>\n<\/ul>\n<h4>1.5 JDK\u7684\u52a8\u6001\u4ee3\u7406&#xff08;\u7528\u7236\u7c7b\u63a5\u53e3&#xff09;<\/h4>\n<li>\n<p>\u76ee\u6807\u7c7b\u63a5\u53e3<\/p>\n<p> public interface TargetInterface{<br \/>\n    public void method();<br \/>\n} <\/li>\n<li>\n<p>\u76ee\u6807\u7c7b<\/p>\n<p> public class Target implements TargetInterface{<br \/>\n    &#064;Override<br \/>\n    public void method(){<br \/>\n        sout(&#034;Target running&#8230;&#034;);<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u52a8\u6001\u4ee3\u7406\u4ee3\u7801<\/p>\n<p> \/\/\u521b\u5efa\u76ee\u6807\u5bf9\u8c61<br \/>\nTarget target&#061;new Target();<\/p>\n<p>\/\/\u589e\u5f3a\u5bf9\u8c61<br \/>\nAdvice advice&#061;new Advice();<\/p>\n<p>\/\/\u8fd4\u56de\u503c \u5c31\u662f\u52a8\u6001\u751f\u6210\u7684\u4ee3\u7406\u5bf9\u8c61<br \/>\nTargetInterface proxy&#061; (TargetInterface) Proxy.newProxyInstance(<br \/>\n     target.getClass().getClassLoader(), \/\/\u76ee\u6807\u5bf9\u8c61\u52a0\u8f7d\u5668<br \/>\n     target.getClass().getInterfaces(), \/\/\u76ee\u6807\u5bf9\u8c61\u76f8\u540c\u7684\u63a5\u53e3\u5b57\u8282\u7801\u5bf9\u8c61\u6570\u7ec4<br \/>\n     new InvocationHandler() {<br \/>\n     \/\/\u8c03\u7528\u4ee3\u7406\u5bf9\u8c61\u7684\u4efb\u4f55\u65b9\u6cd5&#xff0c;\u5b9e\u8d28\u6267\u884c\u7684\u90fd\u662finvoke\u65b9\u6cd5<br \/>\n       &#064;Override<br \/>\n       public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {<br \/>\n          advice.before();\/\/\u524d\u7f6e\u589e\u5f3a<br \/>\n       Object invoke &#061; method.invoke(target, args);\/\/\u6267\u884c\u76ee\u6807\u65b9\u6cd5 \u8fd4\u56de\u4ee3\u7406\u5bf9\u8c61<br \/>\n          advice.afterReturning();\/\/\u540e\u7f6e\u589e\u5f3a<br \/>\n          return invoke;<br \/>\n        }<br \/>\n     }<br \/>\n); <\/li>\n<li>\n<p>\u8c03\u7528\u4ee3\u7406\u5bf9\u8c61\u7684\u65b9\u6cd5\u6d4b\u8bd5<\/p>\n<p> \/\/\u6d4b\u8bd5\u5f53\u8c03\u7528\u63a5\u53e3\u7684\u4efb\u4f55\u65b9\u6cd5\u65f6&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u7684\u4ee3\u7801\u90fd\u65e0\u5e8f\u4fee\u6539<br \/>\nproxy.method(); <\/li>\n<h4>1.6cglib\u7684\u52a8\u6001\u4ee3\u7406<\/h4>\n<li>\n<p>\u521b\u5efa\u589e\u5f3a\u5bf9\u8c61\u3001\u76ee\u6807\u5bf9\u8c61<\/p>\n<p> public class Advice {<br \/>\n    public void before(){<br \/>\n        System.out.println(&#034;\u524d\u7f6e\u589e\u5f3a&#8230;&#034;);<br \/>\n    }<\/p>\n<p>    public void afterReturning(){<br \/>\n        System.out.println(&#034;\u540e\u7f6e\u589e\u5f3a&#8230;&#034;);<br \/>\n    }<br \/>\n} public class Target{<br \/>\n    public void save() {<br \/>\n        System.out.println(&#034;save running&#8230;&#034;);<br \/>\n    }<br \/>\n    public void init(){<br \/>\n        System.out.println(&#034;\u5566\u5566\u5566\u5566\u5566&#034;);<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u8c03\u7528\u4ee3\u7406\u5bf9\u8c61\u7684\u65b9\u6cd5\u6d4b\u8bd5<\/p>\n<p> public class ProxyTest {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/\u521b\u5efa\u76ee\u6807\u5bf9\u8c61<br \/>\n        Target target&#061;new Target();<\/p>\n<p>        \/\/\u589e\u5f3a\u5bf9\u8c61<br \/>\n        Advice advice&#061;new Advice();<\/p>\n<p>        \/\/\u8fd4\u56de\u503c \u5c31\u662f\u52a8\u6001\u751f\u6210\u7684\u4ee3\u7406\u5bf9\u8c61 \u57fa\u4e8ecglib<br \/>\n        \/\/1.\u521b\u5efa\u589e\u5f3a\u5668<br \/>\n        Enhancer enhancer&#061;new Enhancer();<br \/>\n        \/\/2.\u8bbe\u7f6e\u7236\u7c7b&#xff08;\u76ee\u6807&#xff09;<br \/>\n        enhancer.setSuperclass(Target.class);<br \/>\n        \/\/3.\u8bbe\u7f6e\u56de\u8c03<br \/>\n        enhancer.setCallback(new MethodInterceptor() {<br \/>\n            &#064;Override<br \/>\n            public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {<br \/>\n                \/\/\u6267\u884c\u524d\u7f6e<br \/>\n                advice.before();<br \/>\n                \/\/\u6267\u884c\u76ee\u6807<br \/>\n                Object invoke &#061; method.invoke(target, args);<br \/>\n                \/\/\u6267\u884c\u540e\u7f6e<br \/>\n                advice.afterReturning();<br \/>\n                return invoke;<br \/>\n            }<br \/>\n        });<br \/>\n        \/\/4.\u521b\u5efa\u4ee3\u7406\u5bf9\u8c61<br \/>\n        Target o &#061; (Target) enhancer.create();<br \/>\n        o.save();<br \/>\n        o.init();<br \/>\n    }<br \/>\n} <\/p>\n<\/li>\n<h4>1.7 AOP\u76f8\u5173\u6982\u5ff5<\/h4>\n<p>Spring\u7684AOP\u5b9e\u73b0\u5e95\u5c42\u5c31\u662f\u5bf9\u4e0a\u9762\u7684\u52a8\u6001\u4ee3\u7406\u7684\u4ee3\u7801\u8fdb\u884c\u4e86\u5c01\u88c5&#xff0c;\u5c01\u88c5\u540e\u6211\u4eec\u53ea\u9700\u8981\u5173\u6ce8\u7684\u90e8\u5206\u8fdb\u884c\u4ee3\u7801\u7f16\u5199&#xff0c;\u5e76\u901a\u8fc7\u914d\u7f6e\u7684\u65b9\u5f0f\u5b8c\u6210\u6307\u5b9a\u76ee\u6807\u7684\u65b9\u6cd5\u589e\u5f3a\u3002<\/p>\n<p>\u5728\u6b63\u5f0f\u8bb2\u89e3AOP\u7684\u64cd\u4f5c\u4e4b\u524d&#xff0c;\u6211\u4eec\u5fc5\u987b\u7406\u89e3AOP\u7684\u76f8\u5173\u672f\u8bed&#xff0c;\u5e38\u7528\u7684\u672f\u8bed\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>Target(\u76ee\u6807\u5bf9\u8c61)&#xff1a;\u4ee3\u7406\u7684\u76ee\u6807\u5bf9\u8c61&#xff08;\u8981\u88ab\u589e\u5f3a\u7684\u65b9\u6cd5\u5bf9\u8c61&#xff09;<\/p>\n<\/li>\n<li>\n<p>Proxy(\u4ee3\u7406)&#xff1a;\u4e00\u4e2a\u7c7b\u88abAOP\u7ec7\u5165\u589e\u5f3a\u540e&#xff0c;\u5c31\u4ea7\u751f\u4e00\u4e2a\u7ed3\u679c\u4ee3\u7406\u7c7b<\/p>\n<\/li>\n<li>\n<p>Joinpoint(\u8fde\u63a5\u70b9)&#xff1a;\u6240\u8c13\u8fde\u63a5\u70b9\u662f\u6307\u90a3\u4e9b\u88ab\u62e6\u622a\u5230\u7684\u70b9\u3002\u5728spring\u4e2d&#xff0c;\u8fd9\u4e9b\u70b9\u6307\u7684\u662f\u65b9\u6cd5&#xff0c;\u56e0\u4e3aspring\u53ea\u652f\u6301\u65b9\u6cd5\u7c7b\u578b\u7684\u8fde\u63a5\u70b9&#xff08;\u5c31\u662f\u53ef\u4ee5\u88ab\u589e\u5f3a\u7684\u65b9\u6cd5&#xff0c;\u4f46\u662f\u8fd8\u6ca1\u6709\u589e\u5f3a&#xff0c;\u65b9\u6cd5\u8303\u56f4\u5e7f&#xff09;<\/p>\n<\/li>\n<li>\n<p>Pointcut(\u5207\u5165\u70b9)&#xff1a;\u6240\u8c13\u5207\u5165\u70b9\u662f\u6307\u6211\u4eec\u8981\u5bf9\u54ea\u4e9bJoinpoint\u8fdb\u884c\u62e6\u622a\u7684\u5b9a\u4e49<\/p>\n<\/li>\n<li>\n<p>Advice(\u901a\u77e5\/\u589e\u5f3a)&#xff1a;\u6240\u8c13\u901a\u77e5\u662f\u6307\u62e6\u622a\u5230Joinpoint\u4e4b\u540e\u6240\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u662f\u901a\u77e5<\/p>\n<\/li>\n<li>\n<p>Aspect(\u5207\u9762)&#xff1a;\u662f\u5207\u5165\u70b9\u548c\u901a\u8fc7(\u5f15\u4ecb)\u7684\u7ed3\u5408<\/p>\n<\/li>\n<li>\n<p>Weaving(\u7ec7\u5165)&#xff1a;\u662f\u6307\u628a\u589e\u5f3a\u5e94\u7528\u5230\u76ee\u6807\u5bf9\u8c61\u6765\u521b\u5efa\u65b0\u7684\u4ee3\u7406\u5bf9\u8c61\u7684\u8fc7\u7a0b\u3002spring\u91c7\u7528\u52a8\u6001\u4ee3\u7406\u7ec7\u5165&#xff0c;\u800cAspectJ\u91c7\u7528\u7f16\u8bd1\u671f\u7ec7\u5165\u548c\u7c7b\u88c5\u8f7d\u671f\u7ec7\u5165<\/p>\n<\/li>\n<\/ul>\n<h4>1.8AOP\u5f00\u53d1\u660e\u786e\u7684\u4e8b\u9879<\/h4>\n<li>\n<p>\u9700\u8981\u7f16\u5199\u7684\u5185\u5bb9<\/p>\n<ul>\n<li>\n<p>\u7f16\u5199\u6838\u5fc3\u4e1a\u52a1\u4ee3\u7801(\u76ee\u6807\u7c7b\u7684\u76ee\u6807\u65b9\u6cd5)<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u5207\u9762\u7c7b&#xff0c;\u5207\u9762\u7c7b\u4e2d\u6709\u901a\u77e5(\u589e\u5f3a\u529f\u80fd\u65b9\u6cd5)<\/p>\n<\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u914d\u7f6e\u7ec7\u5165\u5173\u7cfb&#xff0c;\u5373\u5c06\u54ea\u4e9b\u901a\u77e5\u4e0e\u54ea\u4e9b\u8fde\u63a5\u70b9\u8fdb\u884c\u7ed3\u5408<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>AOP\u6280\u672f\u5b9e\u73b0\u7684\u5185\u5bb9<\/p>\n<p>Spring\u6846\u67b6\u76d1\u63a7\u5207\u5165\u70b9\u65b9\u6cd5\u7684\u6267\u884c\u3002\u4e00\u65e6\u76d1\u63a7\u5230\u5207\u5165\u70b9\u65b9\u6cd5\u88ab\u8fd0\u884c&#xff0c;\u4f7f\u7528\u4ee3\u7406\u673a\u5236&#xff0c;\u52a8\u6001\u521b\u5efa\u76ee\u6807\u5bf9\u8c61\u7684\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u6839\u636e\u901a\u77e5\u7c7b\u522b&#xff0c;\u5728\u4ee3\u7406\u5bf9\u8c61\u7684\u5bf9\u5e94\u4f4d\u7f6e&#xff0c;\u5c06\u901a\u77e5\u5bf9\u5e94\u7684\u529f\u80fd\u7ec7\u5165&#xff0c;\u5b8c\u6210\u5b8c\u6574\u7684\u4ee3\u7801\u903b\u8f91\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>AOP\u5e95\u5c42\u4f7f\u7528\u90a3\u79cd\u4ee3\u7406\u65b9\u5f0f<\/p>\n<p>\u5728spring\u4e2d&#xff0c;\u6846\u67b6\u4f1a\u6839\u636e\u76ee\u6807\u7c7b\u662f\u5426\u5b9e\u73b0\u4e86\u63a5\u53e3\u6765\u51b3\u5b9a\u91c7\u7528\u90a3\u79cd\u52a8\u6001\u4ee3\u7406\u7684\u65b9\u5f0f<\/p>\n<\/li>\n<h4>1.9 \u77e5\u8bc6\u8981\u70b9&#xff01;&#xff01;<\/h4>\n<ul>\n<li>\n<p>aop&#xff1a;\u9762\u5411\u5207\u9762\u7f16\u7a0b<\/p>\n<\/li>\n<li>\n<p>aop\u5e95\u5c42\u5b9e\u73b0&#xff1a;\u57fa\u4e8eJDK\u7684\u52a8\u6001\u4ee3\u7406\u548c\u57fa\u4e8eCglib\u7684\u52a8\u6001\u4ee3\u7406<\/p>\n<\/li>\n<li>\n<p>aop\u7684\u91cd\u70b9\u6982\u5ff5&#xff1a;<\/p>\n<p>Pointcut(\u5207\u5165\u70b9)&#xff1a;\u88ab\u589e\u5f3a\u7684\u65b9\u6cd5<\/p>\n<p>Advice(\u901a\u77e5\/\u589e\u5f3a)&#xff1a;\u5c01\u88c5\u589e\u5f3a\u4e1a\u52a1\u903b\u8f91\u7684\u65b9\u6cd5<\/p>\n<p>Weaving(\u7ec7\u5165)&#xff1a;\u5c06\u5207\u70b9\u4e0e\u901a\u77e5\u7ed3\u5408\u7684\u8fc7\u7a0b<\/p>\n<\/li>\n<li>\n<p>\u5f00\u53d1\u660e\u786e\u4e8b\u9879&#xff1a;<\/p>\n<p>\u8c01\u662f\u5207\u70b9(\u5207\u70b9\u8868\u8fbe\u5f0f\u914d\u7f6e)<\/p>\n<p>\u8c01\u662f\u901a\u77e5(\u5207\u9762\u7c7b\u4e2d\u7684\u589e\u5f3a\u65b9\u6cd5)<\/p>\n<p>\u5c06\u5207\u70b9\u548c\u901a\u77e5\u8fdb\u884c\u7ec7\u5165\u914d\u7f6e<\/p>\n<\/li>\n<\/ul>\n<h3>2. \u57fa\u4e8eXML\u7684AOP\u5f00\u53d1<\/h3>\n<h4>2.1 \u5feb\u901f\u5165\u95e8<\/h4>\n<li>\n<p>\u5bfc\u5165AOP\u76f8\u5173\u5750\u6807<\/p>\n<p> &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.aspectj&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;aspectjweaver&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.8.13&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u521b\u5efa\u76ee\u6807\u63a5\u53e3\u548c\u76ee\u6807\u7c7b(\u5185\u90e8\u6709\u5207\u70b9)<\/p>\n<p> public interface TargetInterface {<br \/>\n    public void save();<br \/>\n} public class Target implements TargetInterface {<br \/>\n    &#064;Override<br \/>\n    public void save() {<br \/>\n        System.out.println(&#034;save running&#8230;&#034;);<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u521b\u5efa\u5207\u9762\u7c7b(\u5185\u90e8\u6709\u589e\u5f3a\u65b9\u6cd5)<\/p>\n<p> public class MyAspect {<br \/>\n    public void before(){<br \/>\n        System.out.println(&#034;\u524d\u7f6e\u589e\u5f3a&#8230;.&#034;);<br \/>\n    }<\/p>\n<p>    public void after(){<br \/>\n        System.out.println(&#034;\u540e\u7f6e\u589e\u5f3a&#8230;.&#034;);<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u5c06\u76ee\u6807\u7c7b\u548c\u5207\u9762\u7c7b\u7684\u5bf9\u8c61\u521b\u5efa\u6743\u4ea4\u7ed9spring<\/p>\n<p> &lt;!&#8211;\u76ee\u6807\u5bf9\u8c61&#8211;&gt;<br \/>\n&lt;bean id&#061;&#034;target&#034; class&#061;&#034;com.itheima.aop.Target&#034;\/&gt;<br \/>\n&lt;!&#8211;\u5207\u9762\u5bf9\u8c61&#8211;&gt;<br \/>\n&lt;bean id&#061;&#034;myAspect&#034; class&#061;&#034;com.itheima.aop.MyAspect&#034;\/&gt; <\/li>\n<li>\n<p>\u5728applicationContext.xml\u4e2d\u914d\u7f6e\u7ec7\u5165\u5173\u7cfb<\/p>\n<p> &lt;!&#8211;\u914d\u7f6e\u7ec7\u5165&#xff1a;\u544a\u8bc9spring\u6846\u67b6&#xff0c;\u54ea\u4e9b\u65b9\u6cd5&#xff08;\u5207\u70b9&#xff09;\u9700\u8981\u8fdb\u884c\u54ea\u4e9b\u589e\u5f3a&#8211;&gt;<br \/>\n    &lt;aop:config&gt;<br \/>\n        &lt;!&#8211;\u58f0\u660e\u5207\u9762&#8211;&gt;<br \/>\n        &lt;aop:aspect ref&#061;&#034;myAspect&#034;&gt;<br \/>\n            &lt;!&#8211;\u5207\u9762&#xff0c;\u5207\u70b9&#043;\u901a\u77e5&#8211;&gt;<br \/>\n            &lt;aop:before method&#061;&#034;before(\u524d\u7f6e\u65b9\u6cd5\u540d)&#034; pointcut&#061;&#034;execution(public void com.itheima.aop.Target.save())&#034;\/&gt;<br \/>\n        &lt;\/aop:aspect&gt;<br \/>\n    &lt;\/aop:config&gt; <\/li>\n<li>\n<p>\u6d4b\u8bd5\u4ee3\u7801<\/p>\n<p> &#064;RunWith(SpringJUnit4ClassRunner.class)<br \/>\n&#064;ContextConfiguration(&#034;classpath:applicationContext.xml&#034;)<br \/>\npublic class AopTest {<br \/>\n    &#064;Autowired<br \/>\n    private TargetInterface target;<\/p>\n<p>    &#064;Test<br \/>\n    public void test01(){<br \/>\n        target.save();<br \/>\n    }<br \/>\n} <\/li>\n<h4>2.2 XML\u914d\u7f6eAOP\u8be6\u89e3<\/h4>\n<li>\n<p>\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u5199\u6cd5<\/p>\n<p>\u8868\u8fbe\u5f0f\u8bed\u6cd5&#xff1a;<\/p>\n<p> execution([\u4fee\u9970\u7b26] \u8fd4\u56de\u503c\u7c7b\u578b \u5305\u578b.\u7c7b\u540d.\u65b9\u6cd5\u540d(\u53c2\u6570)) <\/p>\n<ul>\n<li>\n<p>\u8bbf\u95ee\u4fee\u9970\u7b26\u53ef\u4ee5\u7701\u7565<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u503c\u7c7b\u578b\u3001\u5305\u540d\u3001\u7c7b\u540d\u3001\u65b9\u6cd5\u540d\u53ef\u4ee5\u4f7f\u7528\u661f\u53f7*\u4ee3\u8868\u4efb\u610f<\/p>\n<\/li>\n<li>\n<p>\u5305\u540d\u4e0e\u7c7b\u540d\u4e4b\u95f4\u4e00\u4e2a\u70b9&#xff0c;\u4ee3\u8868\u5f53\u524d\u5305\u4e0b\u7684\u7c7b&#xff0c;\u4e24\u4e2a\u70b9..\u8868\u793a\u5f53\u524d\u5305\u53ca\u5176\u5b50\u5305\u4e0b\u7684\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u53c2\u6570\u5217\u8868\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u70b9..\u8868\u793a\u4efb\u610f\u4e2a\u6570&#xff0c;\u4efb\u610f\u7c7b\u578b\u7684\u53c2\u6570\u5217\u8868<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p> \/\/\u589e\u5f3a\u6307\u5b9a\u65b9\u6cd5<br \/>\nexecution(public void com.itheima.aop.Target.method())<br \/>\n\/\/\u589e\u5f3aaop\u5305\u4e0b\u7684Target\u7c7b\u7684\u65e0\u8fd4\u56de\u503c\u7684\u5168\u90e8\u65b9\u6cd5<br \/>\nexecution(void com.itheima.aop.Target.*(..))<br \/>\n\/\/\u589e\u5f3aaop\u5305\u4e0b\u7684\u5168\u90e8\u7c7b\u7684\u5168\u90e8\u65b9\u6cd5<br \/>\nexecution(* com.itheima.aop.*.*(..))<br \/>\n\/\/\u589e\u5f3aaop\u6240\u5728\u5305\u548c\u5b50\u5305\u4e0b\u7684\u5168\u90e8\u7c7b\u7684\u5168\u90e8\u65b9\u6cd5<br \/>\nexecution(* com.itheima.aop..*.*(..))<br \/>\n\/\/\u589e\u5f3a\u6574\u4e2a\u8be5\u9879\u76ee\u7684\u7c7b\u7684\u65b9\u6cd5<br \/>\nexecution(* *..*.*(..)) <\/li>\n<li>\n<p>\u901a\u77e5\u7684\u7c7b\u578b<\/p>\n<p>\u901a\u77e5\u7684\u914d\u7f6e\u8bed\u6cd5<\/p>\n<p> &lt;aop:\u901a\u77e5\u7c7b\u578b method&#061;&#034;\u5207\u9762\u7c7b\u4e2d\u65b9\u6cd5\u540d&#034; pointcut&#061;&#034;\u5207\u70b9\u8868\u8fbe\u5f0f&#034;&gt;&lt;\/aop:\u901a\u77e5\u7c7b\u578b&gt; <\/p>\n<table>\n<tr>\u540d\u79f0\u6807\u7b7e\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u524d\u7f6e\u901a\u77e5<\/td>\n<td>&lt; aop:before &gt;<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u524d\u7f6e\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u65b9\u6cd5\u4e4b\u524d\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u540e\u7f6e\u901a\u77e5<\/td>\n<td>&lt; aop:after-returning &gt;<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u540e\u7f6e\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u65b9\u6cd5\u4e4b\u540e\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u73af\u7ed5\u901a\u77e5<\/td>\n<td>&lt; aop:around &gt;<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u73af\u7ed5\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u65b9\u6cd5\u4e4b\u524d\u548c\u4e4b\u540e\u90fd\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u5f02\u5e38\u629b\u51fa\u901a\u77e5<\/td>\n<td>&lt; aop:throwing &gt;<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u5f02\u5e38\u629b\u51fa\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u51fa\u73b0\u5f02\u5e38\u65f6\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u6700\u7ec8\u901a\u77e5<\/td>\n<td>&lt; aop:after &gt;<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u6700\u7ec8\u901a\u77e5\u3002\u65e0\u8bba\u589e\u5f3a\u65b9\u5f0f\u6267\u884c\u662f\u5426\u6709\u5f02\u5e38\u90fd\u4f1a\u6267\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> public class MyAspect {<br \/>\n    public void before(){ System.out.println(&#034;\u524d\u7f6e\u589e\u5f3a&#8230;.&#034;); }<\/p>\n<p>    public void afterRunning(){ System.out.println(&#034;\u540e\u7f6e\u589e\u5f3a&#8230;.&#034;); }<\/p>\n<p>    \/\/Proceeding JoinPoint:\u6b63\u5728\u6267\u884c\u7684\u8fde\u63a5\u70b9&#061;&#061;&#061;\u5207\u70b9<br \/>\n    public Object around(ProceedingJoinPoint pjp) throws Throwable {<br \/>\n        System.out.println(&#034;\u73af\u7ed5\u524d\u589e\u5f3a&#8230;&#034;);<br \/>\n        Object proceed &#061; pjp.proceed();\/\/\u5207\u70b9\u65b9\u6cd5<br \/>\n        System.out.println(&#034;\u73af\u7ed5\u540e\u589e\u5f3a&#8230;&#034;);<br \/>\n        return proceed;<br \/>\n    }<\/p>\n<p>    public void afterThrowing(){ System.out.println(&#034;\u5f02\u5e38\u629b\u51fa\u589e\u5f3a&#8230;&#034;); }<\/p>\n<p>    public void after(){ System.out.println(&#034;\u6700\u7ec8\u589e\u5f3a&#8230;&#034;); }<br \/>\n} &lt;!&#8211;\u914d\u7f6e\u7ec7\u5165&#xff1a;\u544a\u8bc9spring\u6846\u67b6&#xff0c;\u54ea\u4e9b\u65b9\u6cd5&#xff08;\u5207\u70b9&#xff09;\u9700\u8981\u8fdb\u884c\u54ea\u4e9b\u589e\u5f3a&#8211;&gt;<br \/>\n &lt;aop:config&gt;<br \/>\n &lt;!&#8211;\u58f0\u660e\u5207\u9762&#8211;&gt;<br \/>\n &lt;aop:aspect ref&#061;&#034;myAspect&#034;&gt;<br \/>\n &lt;!&#8211;\u5207\u9762&#xff0c;\u5207\u70b9&#043;\u901a\u77e5&#8211;&gt;<br \/>\n &lt;!&#8211;&lt;aop:before method&#061;&#034;before&#034; pointcut&#061;&#034;execution(public void\u3002com.itheima.aop.Target.save())&#034;\/&gt;<br \/>\n &lt;aop:after method&#061;&#034;after&#034; pointcut&#061;&#034;execution(public void com.itheima.aop.Target.save())&#034;\/&gt;&#8211;&gt;<br \/>\n &lt;aop:before method&#061;&#034;before&#034; pointcut&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;<br \/>\n &lt;aop:after-returning method&#061;&#034;afterRunning&#034; pointcut&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;<br \/>\n &lt;aop:around method&#061;&#034;around&#034; pointcut&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;<br \/>\n &lt;aop:after-throwing method&#061;&#034;afterThrowing&#034; pointcut&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;<br \/>\n &lt;aop:after method&#061;&#034;after&#034; pointcut&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;  &lt;\/aop:aspect&gt;<br \/>\n&lt;\/aop:config&gt; <\/p>\n<p> public class Target implements TargetInterface {<br \/>\n    &#064;Override<br \/>\n    public void save() {<br \/>\n        int i&#061;1\/0;<br \/>\n        System.out.println(&#034;save running&#8230;&#034;);<br \/>\n    }<\/p>\n<p>} <\/p>\n<\/li>\n<li>\n<p>\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u62bd\u53d6<\/p>\n<p>\u5f53\u591a\u4e2a\u589e\u5f3a\u7684\u5207\u70b9\u8868\u8fbe\u5f0f\u76f8\u540c\u65f6&#xff0c;\u53ef\u4ee5\u5c06\u5207\u70b9\u8868\u8fbe\u5f0f\u8fdb\u884c\u62bd\u53d6&#xff0c;\u5728\u589e\u5f3a\u4e2d\u4f7f\u7528pointcut-ref\u5c5e\u6027\u4ee3\u66ffpointcut\u5c5e\u6027\u6765\u5f15\u7528\u62bd\u53d6\u540e\u7684\u5207\u70b9\u8868\u8fbe\u5f0f<\/p>\n<p> &lt;aop:config&gt;<br \/>\n        &lt;!&#8211;\u58f0\u660e\u5207\u9762&#8211;&gt;<br \/>\n        &lt;aop:aspect ref&#061;&#034;myAspect&#034;&gt;<br \/>\n            &lt;!&#8211;\u62bd\u53d6\u5207\u70b9\u8868\u8fbe\u5f0f&#8211;&gt;<br \/>\n            &lt;aop:pointcut id&#061;&#034;myPointcut&#034; expression&#061;&#034;execution(* com.itheima.aop.*.*(..))&#034;\/&gt;<br \/>\n            &lt;!&#8211;\u5207\u9762&#xff0c;\u5207\u70b9&#043;\u901a\u77e5&#8211;&gt;<br \/>\n            &lt;aop:around method&#061;&#034;around&#034; pointcut-ref&#061;&#034;myPointcut&#034;\/&gt;<br \/>\n            &lt;aop:before method&#061;&#034;before&#034; pointcut-ref&#061;&#034;myPointcut&#034;\/&gt;<br \/>\n        &lt;\/aop:aspect&gt;<br \/>\n    &lt;\/aop:config&gt; <\/li>\n<h4>2.3 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<ul>\n<li>\n<p>aop\u7ec7\u5165\u7684\u914d\u7f6e<\/p>\n<p> &lt;aop:config&gt;<br \/>\n    &lt;aop:aspect ref&#061;&#034;\u5207\u9762\u7c7b&#034;&gt;<br \/>\n        &lt;aop:before method&#061;&#034;\u901a\u77e5\u65b9\u6cd5\u540d\u79f0&#034; pointcut&#061;&#034;\u5207\u70b9\u8868\u8fbe\u5f0f&#034;&gt;&lt;\/aop:before&gt;<br \/>\n    &lt;\/aop:aspect&gt;<br \/>\n&lt;\/aop:config&gt; <\/li>\n<li>\n<p>\u901a\u77e5\u7684\u7c7b\u578b&#xff1a;\u524d\u7f6e\u901a\u77e5\u3001\u540e\u7f6e\u901a\u77e5\u3001\u73af\u7ed5\u901a\u77e5\u3001\u5f02\u5e38\u629b\u51fa\u901a\u77e5\u3001\u6700\u7ec8\u901a\u77e5<\/p>\n<\/li>\n<li>\n<p>\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u5199\u6cd5&#xff1a;<\/p>\n<p> execution([\u4fee\u9970\u7b26] \u8fd4\u56de\u503c\u7c7b\u578b \u5305\u540d.\u7c7b\u540d.\u65b9\u6cd5\u540d(\u53c2\u6570)) <\/li>\n<\/ul>\n<h3>3. \u57fa\u4e8e\u6ce8\u89e3\u7684AOP\u5f00\u53d1<\/h3>\n<h4>3.1 \u5feb\u901f\u5165\u95e8<\/h4>\n<p>\u57fa\u4e8e\u6ce8\u89e3\u7684aop\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u521b\u5efa\u76ee\u6807\u63a5\u53e3\u548c\u76ee\u6807\u7c7b(\u5185\u90e8\u6709\u5207\u70b9)<\/p>\n<p> public interface TargetInterface{<br \/>\n    public void save();<br \/>\n} &#064;Component(&#034;target&#034;)<br \/>\npublic class Target implements TargetInterface{<br \/>\n    &#064;Override<br \/>\n    public void save(){<br \/>\n        sout(&#034;save running&#034;);<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u521b\u5efa\u5207\u9762\u7c7b(\u5185\u90e8\u6709\u589e\u5f3a\u65b9\u6cd5)<\/p>\n<p> &#064;Component(&#034;myAspect&#034;)<br \/>\n&#064;Aspect \/\/\u6807\u6ce8\u5f53\u524dMyAspect\u662f\u4e00\u4e2a\u5207\u9762\u7c7b<br \/>\npublic class MyAspect{<br \/>\n    \/\/\u914d\u7f6e\u524d\u7f6e\u901a\u77e5<br \/>\n    &#064;Before(&#034;execution(* com.itheima.anno.*.*(..))&#034;)<br \/>\n    public void before(){ sout(&#034;\u524d\u7f6e\u589e\u5f3a&#8230;&#034;) }<br \/>\n} <\/li>\n<li>\n<p>\u5c06\u76ee\u6807\u7c7b\u548c\u5207\u9762\u7c7b\u7684\u5bf9\u8c61\u521b\u5efa\u6743\u4ea4\u7ed9spring<\/p>\n<p>\u7ed9Target\u548cMyAspect\u7c7b\u52a0&#064;Component<\/p>\n<\/li>\n<li>\n<p>\u5728\u5207\u9762\u7c7b\u4e2d\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u7ec7\u5165\u5173\u7cfb<\/p>\n<p>\u7ed9\u5207\u9762\u7c7b\u52a0&#064;Aspect\u548c&#064;Before(&#034;execution(* com.itheima.anno..(..))&#034;)<\/p>\n<\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5f00\u542f\u7ec4\u4ef6\u626b\u63cf\u548cAOP\u7684\u81ea\u52a8\u4ee3\u7406<\/p>\n<p> &lt;!&#8211;\u6ce8\u89e3\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima.aop&#034;\/&gt;<br \/>\n&lt;!&#8211;aop\u7684\u81ea\u52a8\u4ee3\u7406&#8211;&gt;<br \/>\n&lt;aop:aspectj-autoproxy&gt;&lt;\/aop:aspectj-autoproxy&gt; <\/li>\n<li>\n<p>\u6d4b\u8bd5<\/p>\n<p> &#064;RunWith(SpringJUnit4ClassRunner.class)<br \/>\n&#064;ContextConfiguration(&#034;classpath:applicationContext.xml&#034;)<br \/>\npublic class AopTest{<br \/>\n    &#064;Autowired<br \/>\n    private TargetInterface target;<br \/>\n    &#064;Test<br \/>\n    public void test1(){<br \/>\n        target.method();<br \/>\n    }<br \/>\n} <\/p>\n<\/li>\n<h4>3.2 \u6ce8\u89e3\u914d\u7f6eAOP\u8be6\u89e3<\/h4>\n<li>\n<p>\u6ce8\u89e3\u901a\u77e5\u7684\u7c7b\u578b<\/p>\n<p>\u901a\u77e5\u7684\u914d\u7f6e\u8bed\u6cd5&#xff1a;&#064;\u901a\u77e5\u6ce8\u89e3(&#034;\u5207\u70b9\u8868\u8fbe\u5f0f&#034;)<\/p>\n<table>\n<tr>\u540d\u79f0\u6ce8\u89e3\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u524d\u7f6e\u901a\u77e5<\/td>\n<td>&#064;Before<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u4e4b\u524d\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u540e\u7f6e\u901a\u77e5<\/td>\n<td>&#064;AfterReturning<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u540e\u7f6e\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u65b9\u6cd5\u4e4b\u540e\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u73af\u7ed5\u901a\u77e5<\/td>\n<td>&#064;Around<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u73af\u7ed5\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u5207\u5165\u70b9\u4e4b\u524d\u548c\u4e4b\u540e\u90fd\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u5f02\u5e38\u629b\u51fa\u901a\u77e5<\/td>\n<td>&#064;After-Throwing<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u5f02\u5e38\u629b\u51fa\u901a\u77e5\u3002\u6307\u5b9a\u589e\u5f3a\u7684\u65b9\u6cd5\u5728\u51fa\u73b0\u5f02\u5e38\u65f6\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u6700\u7ec8\u901a\u77e5<\/td>\n<td>&#064;After<\/td>\n<td>\u7528\u4e8e\u914d\u7f6e\u6700\u7ec8\u901a\u77e5\u3002\u65e0\u8bba\u589e\u5f3a\u65b9\u5f0f\u6267\u884c\u662f\u5426\u6709\u5f02\u5e38\u90fd\u4f1a\u6267\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p>\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u62bd\u53d6<\/p>\n<p>\u901axml\u914d\u7f6eaop\u4e00\u6837&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06\u5207\u70b9\u8868\u8fbe\u5f0f\u62bd\u53d6\u3002\u62bd\u53d6\u65b9\u5f0f\u662f\u5728\u5207\u9762\u5185\u5b9a\u4e49\u65b9\u6cd5&#xff0c;\u5728\u8be5\u65b9\u6cd5\u4e0a\u4f7f\u7528&#064;Pointcut\u6ce8\u89e3\u5b9a\u4e49\u5207\u70b9\u8868\u8fbe\u5f0f&#xff0c;\u7136\u540e\u518d\u589e\u5f3a\u6ce8\u89e3\u4e2d\u8fdb\u884c\u5f15\u7528&#xff0c;\u5177\u4f53\u5982\u4e0b&#xff1a;<\/p>\n<p> &#064;Component(&#034;myAspect&#034;)<br \/>\n&#064;Aspect<br \/>\npublic class MyAspect{<br \/>\n    &#064;Before(&#034;myPoint()&#034;)<br \/>\n    public void before(){<br \/>\n        sout(&#034;\u524d\u7f6e\u4ee3\u7801\u589e\u5f3a&#8230;.&#034;)<br \/>\n    }<\/p>\n<p>    &#064;Pointcut(&#034;execution(execution(* com.itheima.aop.*.*(..))&#034;)<br \/>\n    public void myPoint(){}<br \/>\n} <\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e5f\u53ef\u4ee5\u8f6c\u6362<\/p>\n<p> &lt;!&#8211;\u6ce8\u89e3\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima.aop&#034;\/&gt;<br \/>\n&lt;!&#8211;aop\u7684\u81ea\u52a8\u4ee3\u7406&#8211;&gt;<br \/>\n&lt;aop:aspectj-autoproxy&gt;&lt;\/aop:aspectj-autoproxy&gt; &#064;ContextConfiguration<br \/>\n\/\/\u6ce8\u89e3\u626b\u63cf<br \/>\n&#064;ComponentScan(&#034;com.itheima.anno&#034;)<br \/>\n\/\/aop\u7684\u81ea\u52a8\u4ee3\u7406<br \/>\n&#064;EnableAspectJAutoProxy<br \/>\npublic class SpringConfig { } <\/li>\n<h4>3.3 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<ul>\n<li>\n<p>\u6ce8\u89e3aop\u5f00\u53d1\u6b65\u9aa4<\/p>\n<li>\n<p>\u4f7f\u7528&#064;Aspect\u6807\u6ce8\u5207\u9762\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528&#064;\u901a\u77e5\u6ce8\u89e3\u6807\u6ce8\u901a\u77e5\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6eaop\u81ea\u52a8\u4ee3\u7406&lt; aop:aspectj-autoproxy &gt;&lt; \/aop:aspectj-autoproxy &gt;\u548c\u6ce8\u89e3\u626b\u63cf<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u901a\u77e5\u6ce8\u89e3\u7c7b\u578b<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<h2>04_Spring jdbcTemplate\u57fa\u672c\u4f7f\u7528<\/h2>\n<h3>1. Spring jdbcTemplate\u57fa\u672c\u4f7f\u7528<\/h3>\n<h4>1.1 jdbcTemplate\u6982\u8ff0<\/h4>\n<p>\u5b83\u662fspring\u6846\u67b6\u4e2d\u63d0\u4f9b\u7684\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u662f\u5bf9\u539f\u59cb\u7e41\u7410\u7684jdbc API\u5bf9\u8c61\u7684\u7b80\u5355\u5c01\u88c5\u3002spring\u6846\u67b6\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f88\u591a\u7684\u64cd\u4f5c\u6a21\u677f\u7c7b\u3002\u4f8b\u5982&#xff1a;\u64cd\u4f5c\u5173\u7cfb\u578b\u6570\u636e\u7684jdbcTemplate\u548cHibernateTemplate&#xff0c;\u64cd\u4f5cnosql\u6570\u636e\u5e93RedisTemplate&#xff0c;\u64cd\u4f5c\u6d88\u606f\u961f\u5217\u7684Jms Template\u7b49\u7b49\u3002<\/p>\n<h4>1.2 JdbcTemplate\u5f00\u53d1\u6b65\u9aa4<\/h4>\n<li>\n<p>\u5bfc\u5165spring-jdbc\u548cspring-tx\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u8868\u548c\u5b9e\u4f53<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaJdbcTemplate\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/p>\n<\/li>\n<h4>1.3 JdbcTemplate\u5feb\u901f\u5165\u95e8<\/h4>\n<li>\n<p>\u5bfc\u5165\u5750\u6807(\u8981\u4f7f\u7528\u8fd9\u4e2a \u4e0d\u7136\u5bb9\u6613\u62a5\u9519)<\/p>\n<p> &lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-tx&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u521b\u5efaaccount\u8868\u548c\u5b9e\u4f53<\/p>\n<\/p>\n<p> public class Account{<br \/>\n    private String name;<br \/>\n    private double money;<br \/>\n    getter&#043;setter<br \/>\n} <\/li>\n<li>\n<p>\u521b\u5efajdbcTemplate\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/p>\n<p> public class JdbcTemplateTest {<br \/>\n \u00a0 \u00a0&#064;Test<br \/>\n \u00a0 \u00a0public void test1() throws Exception {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0\/\/\u521b\u5efa\u6570\u636e\u6e90\u5bf9\u8c61<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0ComboPooledDataSource dataSource&#061;new ComboPooledDataSource();<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0dataSource.setDriverClass(&#034;com.mysql.cj.jdbc.Driver&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0dataSource.setJdbcUrl(&#034;jdbc:mysql:\/\/localhost:3306\/test?useUnicode&#061;true&amp;characterEncoding&#061;utf-8&amp;serverTimezone&#061;UTC&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0dataSource.setUser(&#034;root&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0dataSource.setPassword(&#034;admin&#034;);<br \/>\n\u200b<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0\/\/\u8bbe\u7f6e\u6570\u636e\u6e90\u5bf9\u8c61 \u77e5\u9053\u6570\u636e\u5e93\u5728\u54ea<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0JdbcTemplate jdbcTemplate&#061;new JdbcTemplate();<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0jdbcTemplate.setDataSource(dataSource);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0\/\/\u6267\u884c\u64cd\u4f5c<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0Object[] objects&#061;new Object[]{&#034;kiki&#034;,5000};<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0int tom &#061; jdbcTemplate.update(&#034;insert into account values(?,?)&#034;,objects);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0System.out.println(tom);<br \/>\n \u00a0  }<br \/>\n} <\/li>\n<h4>1.4 Spring\u4ea7\u751fjdbcTemplate\u5bf9\u8c61<\/h4>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06jdbcTemplate\u76842\u521b\u5efa\u6743\u4ea4\u7ed9spring&#xff0c;\u5c06\u6570\u636e\u6e90datasource\u7684\u521b\u5efa\u6743\u4e5f\u4ea4\u7ed9spring&#xff0c;\u5728spring\u5bb9\u5668\u5185\u90e8\u5c06\u6570\u636e\u6e90DataSource\u6ce8\u5165\u5230jdbcTemplate\u6a21\u677f\u5bf9\u8c61\u4e2d&#xff0c;\u914d\u7f6e\u5982\u4e0b&#xff1a;<\/p>\n<p>jdbc.properties<\/p>\n<p>jdbc.driver&#061;com.mysql.cj.jdbc.Driver<br \/>\njdbc.url&#061;jdbc:mysql:\/\/localhost:3306\/test?useUnicode&#061;true&amp;characterEncoding&#061;utf-8&amp;serverTimezone&#061;UTC<br \/>\njdbc.username&#061;root<br \/>\njdbc.password&#061;admin <\/p>\n<p>applicationContext.xml<\/p>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;beans xmlns&#061;&#034;http:\/\/www.springframework.org\/schema\/beans&#034;<br \/>\n \u00a0 \u00a0 \u00a0 xmlns:context&#061;&#034;http:\/\/www.springframework.org\/schema\/context&#034;<br \/>\n \u00a0 \u00a0 \u00a0 xmlns:xsi&#061;&#034;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#034;<br \/>\n \u00a0 \u00a0 \u00a0 xsi:schemaLocation&#061;&#034;http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd<br \/>\n \u00a0 \u00a0 \u00a0 http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd&#034;<br \/>\n&gt;<br \/>\n&lt;!&#8211;\u914d\u7f6e\u6570\u636e\u6e90\u5bf9\u8c61&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;!&#8211;\u8981\u52a0\u8f7d\u5916\u90e8\u6587\u4ef6&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;context:property-placeholder location&#061;&#034;classpath:jdbc.properties&#034;\/&gt;<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;dataSource&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;driverClass&#034; value&#061;&#034;${jdbc.driver}&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;jdbcUrl&#034; value&#061;&#034;${jdbc.url}&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;user&#034; value&#061;&#034;${jdbc.username}&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;password&#034; value&#061;&#034;${jdbc.password}&#034;\/&gt;<br \/>\n \u00a0 \u00a0&lt;\/bean&gt;<br \/>\n \u00a0 \u00a0&lt;!&#8211;jdbc\u6a21\u677f\u5bf9\u8c61&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;jdbcTemplate&#034; class&#061;&#034;org.springframework.jdbc.core.JdbcTemplate&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;dataSource&#034; ref&#061;&#034;dataSource&#034;\/&gt;<br \/>\n \u00a0 \u00a0&lt;\/bean&gt;<br \/>\n&lt;\/beans&gt; <\/p>\n<h4>1.5 jdbcTemplate\u7684\u5e38\u7528\u64cd\u4f5c<\/h4>\n<p>\u64cd\u4f5c<\/p>\n<p>&#064;RunWith(SpringJUnit4ClassRunner.class)<br \/>\n&#064;ContextConfiguration(&#034;classpath:applicationContext.xml&#034;)<br \/>\npublic class jdbcTemplateCRUDTest {<br \/>\n    &#064;Autowired<br \/>\n    private JdbcTemplate jdbcTemplate;<\/p>\n<p>    &#064;Test<br \/>\n    public void testUpdate(){<br \/>\n     Object object[]&#061;new Object[]{10000,&#034;kiki&#034;};<br \/>\n     int update &#061; jdbcTemplate.update(&#034;update account set money&#061;? where name&#061;?&#034;,object);<br \/>\n     System.out.println(update);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testDelete(){<br \/>\n        int tom &#061; jdbcTemplate.update(&#034;delete from account where name&#061;?&#034;, &#034;tom&#034;);<br \/>\n        System.out.println(tom);<br \/>\n    }<br \/>\n    \/\/\u67e5\u8be2\u5168\u90e8<br \/>\n    &#064;Test<br \/>\n    public void testQueryALL(){<br \/>\n        List&lt;Account&gt; accountList &#061; jdbcTemplate.query(&#034;select * from account&#034;, new BeanPropertyRowMapper&lt;Account&gt;(Account.class));<br \/>\n        System.out.println(accountList);<br \/>\n    }<br \/>\n    \/\/\u67e5\u8be2kiki\u7684\u8d26\u6237&#xff0c;\u8fd4\u56dekiki\u7684account\u5bf9\u8c61<br \/>\n    &#064;Test<br \/>\n    public void testQueryOne(){<br \/>\n        Account kiki &#061; jdbcTemplate.queryForObject(&#034;select * from account where name&#061;?&#034;, new BeanPropertyRowMapper&lt;Account&gt;(Account.class), &#034;kiki&#034;);<br \/>\n        System.out.println(kiki);<br \/>\n    }<br \/>\n    \/\/\u67e5\u8be2 \u8fd4\u56de\u666e\u901a\u7c7b\u578b\u5bf9\u8c61 \u8fd9\u91cc\u67e5\u8be2\u884c\u6570<br \/>\n    &#064;Test<br \/>\n    public void testQueryCount(){<br \/>\n        Long aLong &#061; jdbcTemplate.queryForObject(&#034;select count(*) from account&#034;, Long.class);<br \/>\n        System.out.println(aLong);<br \/>\n    }<br \/>\n}<\/p>\n<h4>1.6 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<li>\n<p>\u5bfc\u5165spring-jdbc\u548csprng-tx\u5750\u6807(\u7b2c\u4e00\u4e2a\u5c01\u88c5\u4e86jdbc\u6a21\u677f&#xff0c;\u7b2c\u4e8c\u4e2a\u505a\u4e8b\u52a1)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u8868\u548c\u5b9e\u4f53<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efadataSource\u548cjdbcTemplate\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/p>\n<ul>\n<li>\n<p>\u589e\u6539\u5220\u64cd\u4f5c<\/p>\n<p>jdbcTemplate.update(sql,params) params\u662fObejct[] \u5bf9\u5e94sql\u7684\u95ee\u53f7<\/p>\n<\/li>\n<li>\n<p>\u67e5\u8be2\u64cd\u4f5c<\/p>\n<p>\u67e5\u8be2\u5168\u90e8<\/p>\n<p>jdbcTemplate.query(sql,new Mapper&lt;\u5b9e\u4f53\u5bf9\u8c61\u7c7b&gt;(\u5b9e\u4f53\u5bf9\u8c61\u7c7b.class),params)<\/p>\n<p>\u67e5\u8be2\u4e00\u4e2a<\/p>\n<p>jdbcTemplate.queryForObject(sql,Mapper,parame)<\/p>\n<p>\u67e5\u8be2\u8fd4\u56de\u666e\u901a\u7c7b\u578b<\/p>\n<p>jdbcTemplate.queryForObject(sql,class&lt;T&gt;)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h2>05_\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h2>\n<h3>1. \u7f16\u7a0b\u5f0f\u4e8b\u52a1\u63a7\u5236\u76f8\u5173\u5bf9\u8c61<\/h3>\n<h4>1.1 PlatformTransactionManager<\/h4>\n<p>PlatformTransactionManager\u63a5\u53e3\u662fspring\u7684\u4e8b\u52a1\u7ba1\u7406\u5668&#xff0c;\u5b83\u91cc\u9762\u63d0\u4f9b\u4e86\u6211\u4eec\u5e38\u7528\u7684\u64cd\u4f5c\u4e8b\u52a1\u7684\u65b9\u6cd5<\/p>\n<table>\n<tr>\u65b9\u6cd5\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>TransactionStatus getTransaction(TransactionDefination defination)<\/td>\n<td>\u83b7\u53d6\u4e8b\u52a1\u7684\u72b6\u6001\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>void commit(TransactionStatus status)<\/td>\n<td>\u63d0\u4ea4\u4e8b\u52a1<\/td>\n<\/tr>\n<tr>\n<td>void rollback(TransactionStatus status)<\/td>\n<td>\u56de\u6eda\u4e8b\u52a1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<p>PlatformTransactionManager\u662f\u63a5\u53e3\u7c7b\u578b&#xff0c;\u4e0d\u540c\u7684dao\u5c42\u6280\u672f\u5219\u6709\u4e0d\u540c\u7684\u5b9e\u73b0\u7c7b&#xff0c;\u4f8b\u5982Dao\u5c42\u6280\u672f\u662fjdbc\u6216mybatis\u65f6&#xff1a;org.springframework.jdbc.datasource.DataSourceTransactionManager<\/p>\n<p>Dao\u5c42\u6280\u672f\u662fhibernate\u65f6&#xff1a;org,springframwork.orm.hibernate5.HibernateTransactionManager<\/p>\n<h4>1.2 TransactionDefinition<\/h4>\n<p>TransactionDefinition\u662f\u4e8b\u52a1\u7684\u5b9a\u4e49\u4fe1\u606f\u5bf9\u8c61&#xff0c;\u91cc\u9762\u6709\u5982\u4e0b\u65b9\u6cd5&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>int getIsolationLevel()<\/td>\n<td>\u83b7\u5f97\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b<\/td>\n<\/tr>\n<tr>\n<td>int getPropogationBehavior()<\/td>\n<td>\u83b7\u5f97\u4e8b\u52a1\u7684\u4f20\u64ad\u884c\u4e3a<\/td>\n<\/tr>\n<tr>\n<td>int getTimeout()<\/td>\n<td>\u83b7\u5f97\u8d85\u65f6\u65f6\u95f4<\/td>\n<\/tr>\n<tr>\n<td>boolean isReadOnly()<\/td>\n<td>\u662f\u5426\u53ea\u8bfb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<li>\n<p>\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/p>\n<p>\u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b&#xff0c;\u53ef\u4ee5\u89e3\u51b3\u4e8b\u52a1\u5e76\u53d1\u4ea7\u751f\u7684\u95ee\u9898&#xff0c;\u5982\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u548c\u865a\u8bfb<\/p>\n<ul>\n<li>\n<p>ISOLATION_DEFAULT<\/p>\n<\/li>\n<li>\n<p>ISOLATION_READ_UNCOMMITTED<\/p>\n<\/li>\n<li>\n<p>ISOLATION_READ_COMMITTED<\/p>\n<\/li>\n<li>\n<p>ISOLATION_REPEATABLE_READ<\/p>\n<\/li>\n<li>\n<p>ISOLATION_SERIALAIZABLE<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u4f20\u64ad\u884c\u4e3a<\/p>\n<ul>\n<li>\n<p>REQUIRED&#xff1a;\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u5c31\u65b0\u5efa\u4e00\u4e2a\u4e8b\u52a1&#xff0c;\u5982\u679c\u5df2\u7ecf\u5b58\u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d&#xff0c;\u52a0\u5165\u5230\u8fd9\u4e2a\u4e8b\u52a1\u4e2d\u3002\u4e00\u822c\u7684\u9009\u62e9(\u9ed8\u8ba4\u503c)<\/p>\n<p>&#xff08;A\u8c03\u7528B&#xff0c;B\u770bA\u6709\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u6ca1\u6709\u5c31\u65b0\u5efa&#xff0c;\u6709\u5c31\u52a0\u5165\u5b83&#xff09;<\/p>\n<\/li>\n<li>\n<p>SUPPORTS&#xff1a;\u652f\u6301\u5f53\u524d\u4e8b\u52a1&#xff0c;\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u5c31\u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u6267\u884c(\u6ca1\u6709\u4e8b\u52a1)<\/p>\n<p>&#xff08;A\u8c03\u7528B&#xff0c;B\u770b\u770bA\u6709\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u6709\u5c31\u4e00\u8d77\u7528&#xff0c;\u6ca1\u6709\u5c31\u975e\u4e8b\u52a1\u8fd0\u884c&#xff09;<\/p>\n<\/li>\n<li>\n<p>MANDATORY&#xff1a;\u4f7f\u7528\u5f53\u524d\u7684\u4e8b\u52a1&#xff0c;\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u5c31\u629b\u51fa\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>REQUERS_NEW&#xff1a;\u65b0\u5efa\u4e8b\u52a1&#xff0c;\u5982\u679c\u5f53\u524d\u5728\u4e8b\u52a1\u4e2d&#xff0c;\u628a\u5f53\u524d\u4e8b\u52a1\u6302\u8d77<\/p>\n<\/li>\n<li>\n<p>NOT_SUPPORTED&#xff1a;\u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u6267\u884c\u64cd\u4f5c&#xff0c;\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1&#xff0c;\u5c31\u628a\u5f53\u524d\u4e8b\u52a1\u6302\u8d77<\/p>\n<\/li>\n<li>\n<p>MEVER&#xff1a;\u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u8fd0\u884c&#xff0c;\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1&#xff0c;\u629b\u51fa\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u8d85\u65f6\u65f6\u95f4&#xff1a;\u9ed8\u8ba4\u503c\u662f-1&#xff0c;\u6ca1\u6709\u8d85\u65f6\u9650\u5236\u3002\u5982\u679c\u6709&#xff0c;\u4ee5\u79d2\u4e3a\u5355\u4f4d\u8fdb\u884c\u8bbe\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u662f\u5426\u53ea\u8bfb&#xff1a;\u5efa\u8bae\u67e5\u8be2\u65f6\u8bbe\u7f6e\u4e3a\u53ea\u8bfb<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h4>1.3 TransactionStatus<\/h4>\n<p>TransactionStatus\u63a5\u53e3\u63d0\u4f9b\u7684\u662f\u4e8b\u52a1\u5177\u4f53\u7684\u8fd0\u884c\u72b6\u6001&#xff0c;\u65b9\u6cd5\u4ecb\u7ecd\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>boolean hasSavepoint()<\/td>\n<td>\u662f\u5426\u5b58\u50a8\u56de\u6eda\u70b9<\/td>\n<\/tr>\n<tr>\n<td>boolean isCompleted()<\/td>\n<td>\u4e8b\u52a1\u662f\u5426\u5b8c\u6210<\/td>\n<\/tr>\n<tr>\n<td>boolean isNewTransaction()<\/td>\n<td>\u662f\u5426\u6709\u65b0\u4e8b\u52a1<\/td>\n<\/tr>\n<tr>\n<td>boolean isRollbackOnly()<\/td>\n<td>\u4e8b\u52a1\u662f\u5426\u56de\u6eda<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>\u7f16\u7a0b\u5f0f\u4e8b\u52a1\u63a7\u5236\u4e09\u5927\u5bf9\u8c61&#xff08;\u8981\u7406\u89e3\u4ed6\u4eec\u7684\u4f5c\u7528&#xff09;<\/p>\n<ul>\n<li>\n<p>PlatformTransactionManager(\u4e8b\u52a1\u5b9a\u4e49\u884c\u4e3a \u4e8b\u52a1\u7ba1\u7406\u5bf9\u8c61 \u6839\u636e\u4e0d\u540c\u7684\u6570\u636e\u5e93\u8fd0\u7528\u4e0d\u540c\u7684\u5305)<\/p>\n<\/li>\n<li>\n<p>TransactionDefintion(\u4e8b\u52a1\u5b9a\u4e49\u5bf9\u8c61 \u5b9a\u4e49\u4e8b\u52a1\u76f8\u5173\u53c2\u6570)<\/p>\n<\/li>\n<li>\n<p>TransactionStatus(\u88ab\u52a8\u5c01\u88c5\u72b6\u6001\u4fe1\u606f \u4e0d\u9700\u8981\u6307\u5b9a\u523b\u610f\u53bb\u5f04)<\/p>\n<\/li>\n<\/ul>\n<h3>2.\u57fa\u4e8eXML\u7684\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h3>\n<h4>2.1 \u4ec0\u4e48\u662f\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h4>\n<p>spring\u7684\u58f0\u660e\u5f0f\u4e8b\u52a1\u987e\u540d\u601d\u4e49\u5c31\u662f\u91c7\u7528\u58f0\u660e\u7684\u65b9\u5f0f\u6765\u5904\u7406\u4e8b\u52a1&#xff0c;\u8fd9\u91cc\u6240\u8bf4\u7684\u58f0\u660e&#xff0c;\u5c31\u662f\u6307\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u58f0\u660e&#xff0c;\u7528\u5728spring\u914d\u7f6e\u6587\u4ef6\u4e2d\u58f0\u660e\u5f0f\u7684\u5904\u7406\u4e8b\u52a1\u6765\u4ee3\u66ff\u4ee3\u7801\u5f0f\u7684\u5904\u7406\u4e8b\u52a1\u3002<\/p>\n<p>\u58f0\u660e\u5f0f\u4e8b\u52a1\u5904\u7406\u7684\u4f5c\u7528<\/p>\n<ul>\n<li>\n<p>\u4e8b\u52a1\u7ba1\u7406\u4e0d\u4fb5\u5165\u5f00\u53d1\u7684\u7ec4\u4ef6\u3002\u5177\u4f53\u6765\u8bf4&#xff0c;\u4e1a\u52a1\u903b\u8f91\u5bf9\u8c61\u5c31\u4e0d\u4f1a\u610f\u8bc6\u5230\u6b63\u5728\u4e8b\u52a1\u7ba1\u7406\u4e4b\u4e2d&#xff0c;\u4e8b\u5b9e\u4e0a\u4e5f\u5e94\u8be5\u5982\u6b64&#xff0c;\u56e0\u4e3a\u4e8b\u52a1\u7ba1\u7406\u662f\u5c5e\u4e8e\u7cfb\u7edf\u5c42\u9762\u7684\u670d\u52a1&#xff0c;\u800c\u4e0d\u662f\u4e1a\u52a1\u903b\u8f91\u7684\u4e00\u90e8\u5206&#xff0c;\u5982\u679c\u60f3\u8981\u6539\u53d8\u4e8b\u52a1\u7ba1\u7406\u7b56\u5212\u7684\u8bdd&#xff0c;\u4e5f\u53ea\u9700\u8981\u5728\u5b9a\u4e49\u6587\u4ef6\u4e2d\u91cd\u65b0\u914d\u7f6e\u5373\u53ef<\/p>\n<\/li>\n<li>\n<p>\u5728\u4e0d\u9700\u8981\u4e8b\u52a1\u7ba1\u7406\u7684\u65f6\u5019&#xff0c;\u53ea\u8981\u5728\u8bbe\u5b9a\u6587\u4ef6\u4e0a\u4fee\u6539\u4e00\u4e0b&#xff0c;\u5373\u53ef\u79fb\u53bb\u4e8b\u52a1\u7ba1\u7406\u670d\u52a1&#xff0c;\u65e0\u9700\u8be5\u8868\u4ee3\u7801\u91cd\u65b0\u7f16\u8bd1&#xff0c;\u8fd9\u6837\u7ef4\u62a4\u8d77\u6765\u6781\u5176\u65b9\u4fbf<\/p>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff1a;Spring\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236\u5e95\u5c42\u5c31\u662fAOP\u3002<\/p>\n<h4>2.2 \u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236\u7684\u5b9e\u73b0<\/h4>\n<p>\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236\u660e\u786e\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8c01\u662f\u5207\u70b9&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u8c01\u662f\u901a\u77e5&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u5207\u9762&#xff1f;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>\u5bfc\u5305<\/p>\n<p> &lt;dependencies&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-context&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.aspectj&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;aspectjweaver&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;1.8.13&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-test&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;com.mchange&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;c3p0&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;0.9.5.5&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-tx&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;mysql&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;8.0.22&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;junit&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;junit&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;4.13.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n&lt;\/dependencies&gt; <\/li>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6&#xff0c;\u4e8b\u52a1\u5e95\u5c42\u539f\u7406\u7528\u5230aop&#xff0c;\u5c5e\u4e8e\u9700\u8981\u5f15\u5165aop\u548ctx<\/p>\n<p> xmlns:context&#061;&#034;http:\/\/www.springframework.org\/schema\/context&#034;<br \/>\n       xmlns:p&#061;&#034;http:\/\/www.springframework.org\/schema\/p&#034;<br \/>\n       xmlns:tx&#061;&#034;http:\/\/www.springframework.org\/schema\/tx&#034;<br \/>\n       xmlns:aop&#061;&#034;http:\/\/www.springframework.org\/schema\/aop&#034;<\/p>\n<p> http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd<\/p>\n<p>                http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx.xsd<\/p>\n<p>                http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop.xsd &lt;!&#8211;\u8f7d\u5165\u5916\u90e8\u6587\u4ef6&#8211;&gt;<br \/>\n&lt;context:property-placeholder location&#061;&#034;jdbc.properties&#034;\/&gt;<br \/>\n&lt;!&#8211;\u914d\u7f6e\u6570\u636e\u6e90&#8211;&gt;<br \/>\n&lt;bean id&#061;&#034;dataSource&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;<br \/>\n          p:driverClass&#061;&#034;${jdbc.driver}&#034; p:jdbcUrl&#061;&#034;${jdbc.url}&#034;<br \/>\n          p:user&#061;&#034;${jdbc.username}&#034; p:password&#061;&#034;${jdbc.password}&#034;\/&gt;<br \/>\n&lt;!&#8211;\u914d\u7f6e\u6570\u636e\u6a21\u677f\u5bf9\u8c61&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;jdbcTemplate&#034; class&#061;&#034;org.springframework.jdbc.core.JdbcTemplate&#034; p:dataSource-ref&#061;&#034;dataSource&#034;\/&gt;<\/p>\n<p>    &lt;bean id&#061;&#034;accountDao&#034; class&#061;&#034;com.itheima.dao.impl.AccountDaoImpl&#034; p:jdbcTemplate-ref&#061;&#034;jdbcTemplate&#034;\/&gt;<\/p>\n<p>    &lt;bean id&#061;&#034;accountService&#034; class&#061;&#034;com.itheima.service.impl.AccountServiceImpl&#034; p:accountDao-ref&#061;&#034;accountDao&#034;\/&gt;<\/p>\n<p>    &lt;!&#8211;\u914d\u7f6e\u5e73\u53f0\u4e8b\u52a1\u7ba1\u7406\u5668 \u544a\u8bc9\u4e8b\u52a1\u6570\u636e\u5e93\u662f\u4ec0\u4e48&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;transactionManager&#034; class&#061;&#034;org.springframework.jdbc.datasource.DataSourceTransactionManager&#034; p:dataSource-ref&#061;&#034;dataSource&#034; \/&gt;<\/p>\n<p>    &lt;!&#8211;\u901a\u77e5 \u4e8b\u52a1\u7684\u589e\u5f3a&#8211;&gt;<br \/>\n    &lt;tx:advice id&#061;&#034;txAdvice&#034; transaction-manager&#061;&#034;transactionManager&#034;&gt;<br \/>\n        &lt;!&#8211;\u8bbe\u7f6e\u4e8b\u52a1\u5c5e\u6027\u4fe1\u606f&#8211;&gt;<br \/>\n        &lt;tx:attributes&gt;<br \/>\n            &lt;tx:method name&#061;&#034;*&#034;\/&gt;<br \/>\n        &lt;\/tx:attributes&gt;<br \/>\n    &lt;\/tx:advice&gt;<\/p>\n<p>    &lt;!&#8211;1.\u914d\u7f6e\u4e8b\u52a1\u7684aop\u7ec7\u5165&#8211;&gt;<br \/>\n    &lt;aop:config&gt;<br \/>\n        &lt;aop:advisor advice-ref&#061;&#034;txAdvice&#034; pointcut&#061;&#034;execution(* com.itheima.service.impl.*.*(..))&#034;\/&gt;<br \/>\n    &lt;\/aop:config&gt;<\/p>\n<p>&lt;!&#8211;2.\u4e8b\u52a1\u7684aop\u589e\u5f3a&#8211;&gt;<br \/>\n&lt;aop:config&gt;<br \/>\n    &lt;aop:pointcut id&#061;&#034;myPointcut&#034; expression&#061;&#034;execution(* com.itheima.service.impl.*.*(..))&#034;\/&gt;<br \/>\n    &lt;aop:advisor advice-ref&#061;&#034;txAdvice&#034; pointcut-ref&#061;&#034;myPointcut&#034;&gt;&lt;\/aop:advisor&gt;<br \/>\n&lt;\/aop:config&gt;\n <\/li>\n<li>\n<p>\u6d4b\u8bd5<\/p>\n<p> public class AccountDaoImpl implements AccountDao {<br \/>\n    private JdbcTemplate jdbcTemplate;<\/p>\n<p>    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {<br \/>\n        this.jdbcTemplate &#061; jdbcTemplate;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void out(String outMan, double money) {<br \/>\n        jdbcTemplate.update(&#034;update account set money&#061;money-? where name&#061;?&#034;,money,outMan);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void in(String inMan, double money) {<br \/>\n        jdbcTemplate.update(&#034;update account set money&#061;money&#043;? where name&#061;?&#034;,money,inMan);<br \/>\n    }<\/p>\n<p>} public class AccountServiceImpl implements AccountService {<br \/>\n    private AccountDao accountDao;<\/p>\n<p>    public void setAccountDao(AccountDao accountDao) {<br \/>\n        this.accountDao &#061; accountDao;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void transfer(String outMan, String inMan, double money) {<br \/>\n        accountDao.out(outMan,money);<br \/>\n        int i&#061;1\/0;\/\/\u9519\u8bef \u67e5\u770b\u6570\u636e\u5e93\u662f\u5426\u53d8\u5316<br \/>\n        accountDao.in(inMan,money);<br \/>\n    }<\/p>\n<p>} public class AccountController {<br \/>\n    public static void main(String[] args) {<br \/>\n        ApplicationContext app&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        AccountService accountService&#061;app.getBean(AccountService.class);<br \/>\n        accountService.transfer(&#034;kiki&#034;,&#034;to&#034;,500);<br \/>\n    }<br \/>\n} <\/li>\n<h4>2.3 \u5207\u70b9\u65b9\u6cd5\u7684\u4e8b\u52a1\u53c2\u6570\u7684\u914d\u7f6e<\/h4>\n<p>&lt;!&#8211;1.\u914d\u7f6e\u4e8b\u52a1\u7684aop\u7ec7\u5165&#8211;&gt;<br \/>\n&lt;aop:config&gt;<br \/>\n    &lt;aop:advisor advice-ref&#061;&#034;txAdvice&#034; pointcut&#061;&#034;execution(* com.itheima.service.impl.*.*(..))&#034;\/&gt;<br \/>\n&lt;\/aop:config&gt; <\/p>\n<p>\u5176\u4e2d&#xff0c;&lt; tx:method &gt;\u4ee3\u8868\u5207\u70b9\u65b9\u6cd5\u7684\u4e8b\u52a1\u53c2\u6570\u7684\u914d\u7f6e&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>&lt;tx:method name&#061;&#034;transfer&#034; isolation&#061;&#034;REPEATABLE_READ&#034; propagation&#061;&#034;REQUIRED&#034; timeout&#061;&#034;-1&#034; read-only&#061;&#034;false&#034;\/&gt; <\/p>\n<p>name&#xff1a;\u5207\u70b9\u65b9\u6cd5\u540d\u79f0<\/p>\n<p>isolation&#xff1a;\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/p>\n<p>propogation&#xff1a;\u4e8b\u52a1\u4f20\u64ad\u884c\u4e3a<\/p>\n<p>timeout&#xff1a;\u8d85\u8fc7\u65f6\u95f4<\/p>\n<p>read-only&#xff1a;\u662f\u5426\u53ea\u8bfb<\/p>\n<h4>2.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>\u58f0\u660e\u5f0f\u662fu\u6211\u63a7\u5236\u7684\u914d\u7f6e\u8981\u70b9<\/p>\n<li>\n<p>\u5e73\u53f0\u4e8b\u52a1\u7ba1\u7406\u5668\u914d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u901a\u77e5\u7684\u914d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u52a1aop\u7ec7\u5165\u7684\u914d\u7f6e<\/p>\n<\/li>\n<h3>3. \u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h3>\n<h4>3.1 \u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h4>\n<li>\n<p>xml\u914d\u7f6e&#xff08;\u81ea\u5b9a\u4e49\u914d\u7f6e\u53ef\u4f7f\u7528\u6ce8\u89e3&#xff0c;\u975e\u81ea\u5b9a\u4e49\u5efa\u8baexml\u914d\u7f6e&#xff09;<\/p>\n<p> &lt;context:property-placeholder location&#061;&#034;jdbc.properties&#034;\/&gt;<\/p>\n<p>    &lt;bean id&#061;&#034;dataSource&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;<br \/>\n          p:driverClass&#061;&#034;${jdbc.driver}&#034; p:jdbcUrl&#061;&#034;${jdbc.url}&#034;<br \/>\n          p:user&#061;&#034;${jdbc.username}&#034; p:password&#061;&#034;${jdbc.password}&#034;\/&gt;<\/p>\n<p>    &lt;bean id&#061;&#034;jdbcTemplate&#034; class&#061;&#034;org.springframework.jdbc.core.JdbcTemplate&#034; p:dataSource-ref&#061;&#034;dataSource&#034;\/&gt;<\/p>\n<p> &lt;!&#8211;\u6ce8\u89e3\u626b\u63cf&#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt;<\/p>\n<p>&lt;!&#8211;\u914d\u7f6e\u5e73\u53f0\u4e8b\u52a1\u7ba1\u7406\u5668&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;transactionManager&#034; class&#061;&#034;org.springframework.jdbc.datasource.DataSourceTransactionManager&#034; p:dataSource-ref&#061;&#034;dataSource&#034; \/&gt;<\/p>\n<p>&lt;!&#8211;\u4e8b\u52a1\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;tx:annotation-driven transaction-manager&#061;&#034;transactionManager&#034;\/&gt; <\/li>\n<li>\n<p>\u7f16\u5199AccountDao<\/p>\n<p> &#064;Repository(&#034;accountDao&#034;)<br \/>\npublic class AccountDaoImpl implements AccountDao {<br \/>\n    &#064;Autowired<br \/>\n    private JdbcTemplate jdbcTemplate;<\/p>\n<p>    &#064;Override<br \/>\n    public void out(String outMan, double money) {<br \/>\n        jdbcTemplate.update(&#034;update account set money&#061;money-? where name&#061;?&#034;,money,outMan);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void in(String inMan, double money) {<br \/>\n        jdbcTemplate.update(&#034;update account set money&#061;money&#043;? where name&#061;?&#034;,money,inMan);<br \/>\n    }<\/p>\n<p>} <\/li>\n<li>\n<p>\u7f16\u5199AccountService<\/p>\n<p> &#064;Service(&#034;accountService&#034;)<br \/>\npublic class AccountServiceImpl implements AccountService {<br \/>\n    &#064;Autowired<br \/>\n    private AccountDao accountDao;<\/p>\n<p>    &#064;Override<br \/>\n    &#064;Transactional(isolation &#061; Isolation.DEFAULT,propagation &#061; Propagation.REQUIRED)<br \/>\n    public void transfer(String outMan, String inMan, double money) {<br \/>\n        accountDao.out(outMan,money);<br \/>\n        accountDao.in(inMan,money);<br \/>\n    }<\/p>\n<p>} <\/li>\n<li>\n<p>\u914d\u7f6eapplicationContext.xml\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>  &lt;!&#8211;\u6ce8\u89e3\u626b\u63cf&#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt;<br \/>\n&lt;!&#8211;\u4e8b\u52a1\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;tx:annotation-driven transaction-manager&#061;&#034;transactionManager&#034;\/&gt; <\/li>\n<h4>3.2 \u6ce8\u89e3\u914d\u7f6e\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236\u89e3\u6790<\/h4>\n<li>\n<p>\u4f7f\u7528&#064;Transactional\u5728\u9700\u8981\u8fdb\u884c\u4e8b\u52a1\u63a7\u5236\u7684\u7c7b\u6216\u662f\u65b9\u6cd5\u4e0a\u4fee\u9970&#xff0c;\u6ce8\u89e3\u53ef\u7528\u7684\u5c5e\u6027\u540cxml\u914d\u7f6e\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u9694\u79bb\u7ea7\u522b\u3001\u4f20\u64ad\u884c\u4e3a\u7b49\u3002<\/p>\n<p>&#064;Transactional(isolation &#061; Isolation.DEFAULT,propagation &#061; Propagation.REQUIRED)<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u89e3\u4f7f\u7528\u5728\u7c7b\u4e0a&#xff0c;\u90a3\u4e48\u8be5\u7c7b\u4e0b\u7684\u6240\u6709\u65b9\u6cd5\u90fd\u4f7f\u7528\u540c\u4e00\u5957\u6ce8\u89e3\u53c2\u6570\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5728\u65b9\u6cd5\u4e0a&#xff0c;\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u7528\u91c7\u7528\u4e0d\u540c\u7684\u4e8b\u52a1\u53c2\u6570\u914d\u7f6e<\/p>\n<\/li>\n<li>\n<p>xml\u914d\u7f6e\u6587\u4ef6\u4e2d\u8981\u5f00\u542f\u4e8b\u52a1\u7684\u6ce8\u89e3\u9a71\u52a8<\/p>\n<p>&lt;tx:annotation-driven transaction-manager&#061;&#034;transactionManager&#034;\/&gt;<\/p>\n<\/li>\n<h4>3.3 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>\u6ce8\u89e3\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236\u7684\u914d\u7f6e\u8981\u70b9<\/p>\n<ul>\n<li>\n<p>\u5e73\u53f0\u4e8b\u52a1\u7ba1\u7406\u5668\u914d\u7f6e&#xff08;xml&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u901a\u77e5\u7684\u914d\u7f6e&#xff08;&#064;Transaction\u6ce8\u89e3\u914d\u7f6e&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u6ce8\u89e3\u9a71\u52a8\u7684\u914d\u7f6e&lt; tx:annotation-driven\/&gt;<\/p>\n<\/li>\n<\/ul>\n<h2>3-2 SpringMVC<\/h2>\n<h2>01-springmvc\u5feb\u901f\u5165\u95e8\u3001\u7ec4\u4ef6\u89e3\u6790<\/h2>\n<h3>1.Spring\u96c6\u6210web\u73af\u5883<\/h3>\n<h4>1.1 ApplicationContext\u5e94\u7528\u4e0a\u4e0b\u6587\u83b7\u53d6\u65b9\u5f0f<\/h4>\n<p>\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61\u662f\u901a\u8fc7new ClasspathXmlApplicationContext(spring\u914d\u7f6e\u6587\u4ef6)\u65b9\u5f0f\u83b7\u53d6\u7684&#xff0c;\u4f46\u662f\u6bcf\u6b21\u4ece\u5bb9\u5668\u4e2d\u83b7\u5f97Bean\u65f6\u90fd\u8981\u7f16\u5199new ClasspathXmlApplicationContext(spring\u914d\u7f6e\u6587\u4ef6)&#xff0c;\u8fd9\u6837\u7684\u5f0a\u7aef\u662f\u914d\u7f6e\u6587\u4ef6\u52a0\u8f7d\u591a\u6b21&#xff0c;\u5e94\u7528\u4e0a\u4e0b\u6587\u521b\u5efa\u591a\u6b21\u3002<\/p>\n<p>\u5728web\u9879\u76ee\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528ServletContextListener\u76d1\u542cweb\u5e94\u7528\u7684\u542f\u52a8&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5728web\u5e94\u7528\u542f\u52a8\u65f6&#xff0c;\u5c31\u52a0\u8f7dspring\u7684\u914d\u7f6e\u6587\u4ef6&#xff0c;\u521b\u5efa\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61ApplicationContext&#xff0c;\u5728\u5c06\u5176\u5b58\u50a8\u5230\u6700\u5927\u7684\u57dfservletContext\u57df\u4e2d&#xff0c;\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u4ece\u57df\u4e2d\u83b7\u5f97\u5e94\u7528\u4e0a\u4e0b\u6587ApplicationContext\u5bf9\u8c61\u4e86\u3002<\/p>\n<p>\u603b\u7ed3\u5c31\u662f\u4e3a\u4e86\u4e0d\u8ba9\u914d\u7f6e\u6587\u4ef6\u88ab\u52a0\u8f7d\u592a\u591a\u6b21&#xff0c;\u51cf\u5c11\u91cd\u590d\u4ee3\u7801&#xff0c;\u56e0\u6b64\u505a\u4e00\u4e2alistener\u76f4\u63a5\u521d\u59cb\u5316\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>public class ContextLoaderListener implements ServletContextListener {<br \/>\n    &#064;Override<br \/>\n    public void contextInitialized(ServletContextEvent servletContextEvent) {<br \/>\n        \/\/\u8bfb\u53d6web.xml\u4e2d\u7684\u5168\u5c40\u53c2\u6570 \u5c06\u914d\u7f6e\u6587\u4ef6\u63d0\u53d6\u51fa\u6765<br \/>\n        ServletContext servletContext &#061; servletContextEvent.getServletContext();<br \/>\n        String contextConfigLocation &#061; servletContext.getInitParameter(&#034;contextConfigLocation&#034;);<br \/>\n        ApplicationContext app&#061;new ClassPathXmlApplicationContext(contextConfigLocation);<br \/>\n        \/\/\u5c06spring\u7684\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61\u5b58\u50a8\u5230ServletContext\u57df\u5f53\u4e2d<br \/>\n        servletContext.setAttribute(&#034;app&#034;,app);<br \/>\n    }<br \/>\n&lt;listener&gt;<br \/>\n    &lt;listener-class&gt;com.itheima.listener.ContextLoaderListener&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<br \/>\n&lt;!&#8211;\u5168\u5c40\u53d8\u91cf&#8211;&gt;<br \/>\n&lt;context-param&gt;<br \/>\n    &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n    &lt;param-value&gt;applicationContext.xml&lt;\/param-value&gt;<br \/>\n&lt;\/context-param&gt;<br \/>\npublic class WebApplicationContextUtils {<br \/>\n    public static ApplicationContext getApplicationContext(ServletContext servletContext){<br \/>\n        \/\/\u5728servlet\u4e66\u5199app\u65f6 \u4e07\u4e00\u5bf9\u65b9\u4e0d\u662fapp\u5565\u7684&#xff0c;\u6240\u4ee5\u7528\u4e00\u4e2a\u5de5\u5177\u7c7b\u83b7\u53d6\u4e0a\u4e0b\u6587\u5bf9\u8c61<br \/>\n        return (ApplicationContext) servletContext.getAttribute(&#034;app&#034;);<br \/>\n    }<br \/>\n}<br \/>\npublic class UserServlet extends HttpServlet {<br \/>\n    &#064;Override<br \/>\n    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {<br \/>\n\/\/        ApplicationContext app&#061;new ClassPathXmlApplicationContext(&#034;applicationContext.xml&#034;);<br \/>\n        ServletContext servletContext &#061; this.getServletContext();<br \/>\n        \/\/ApplicationContext app &#061; (ApplicationContext) servletContext.getAttribute(&#034;app&#034;);<br \/>\n        ApplicationContext app &#061; WebApplicationContextUtils.getApplicationContext(servletContext);<br \/>\n        UserService u &#061; app.getBean(UserService.class);<br \/>\n        u.save();<br \/>\n    }<br \/>\n} <\/p>\n<h4>1.2 Spring\u63d0\u4f9b\u83b7\u53d6\u5e94\u7528\u4e0a\u4e0b\u6587\u7684\u5de5\u5177<\/h4>\n<p>\u4e0a\u9762\u7684\u5206\u6790\u4e0d\u7528\u624b\u52a8\u5b9e\u73b0&#xff0c;spring\u63d0\u4f9b\u4e86\u4e00\u4e2a\u76d1\u542c\u5668ContextLoaderListener\u5c31\u662f\u5bf9\u4e0a\u8ff0\u529f\u80fd\u7684\u5c01\u88c5&#xff0c;\u8be5\u76d1\u542c\u5668\u5185\u90e8\u52a0\u8f7dSpring\u914d\u7f6e\u6587\u4ef6&#xff0c;\u521b\u5efa\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61&#xff0c;\u5e76\u5b58\u50a8\u5230ServletContext\u57df\u4e2d&#xff0c;\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5ba2\u6237\u7aef\u5de5\u5177WebApplicationContextUtils\u4f9b\u4f7f\u7528\u8005\u83b7\u5f97\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u9700\u8981\u505a\u7684\u53ea\u6709\u4e24\u4ef6\u4e8b&#xff1a;<\/p>\n<li>\n<p>\u5728web.xml\u4e2d\u914d\u7f6eContextLoaderListener\u76d1\u542c\u5668&#xff08;\u5bfc\u5165spring-web\u5750\u6807&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528WebApplicationContextUtils\u83b7\u5f97\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61ApplicationContext<\/p>\n<\/li>\n<h4>1.3 \u5bfc\u5165Spring\u96c6\u6210web\u7684\u5750\u6807<\/h4>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-web&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<h4>1.4 \u914d\u7f6eContextLoaderListener\u76d1\u542c\u5668<\/h4>\n<p>&lt;listener&gt;<br \/>\n&lt;!&#8211;Spring\u7684\u76d1\u542c\u5668&#8211;&gt;<br \/>\n&lt;listener-class&gt;<br \/>\n    org.springframework.web.context.ContextLoaderListener<br \/>\n&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<br \/>\n&lt;!&#8211;\u5168\u5c40\u53c2\u6570&#8211;&gt;<br \/>\n&lt;context-param&gt;<br \/>\n    &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n    &lt;param-value&gt;classpath:applicationContext.xml&lt;\/param-value&gt;<br \/>\n&lt;\/context-param&gt; <\/p>\n<h4>1.5 \u901a\u8fc7\u5de5\u5177\u83b7\u5f97\u5e94\u7528\u4e0a\u4e0b\u6587\u5bf9\u8c61<\/h4>\n<p>ServletContext servletContext &#061; this.getServletContext();<br \/>\nWebApplicationContext app &#061; WebApplicationContextUtils.getWebApplicationContext(servletContext);<br \/>\nUserService u &#061; app.getBean(UserService.class);<br \/>\nu.save(); <\/p>\n<h4>1.6 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>spring\u96c6\u6210web\u73af\u5883\u6b65\u9aa4<\/p>\n<li>\n<p>\u914d\u7f6eContextLoaderListener\u76d1\u542c\u5668<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528WebApplicationContextUtils\u83b7\u5f97\u5e94\u7528\u4e0a\u4e0b\u6587<\/p>\n<\/li>\n<h3>2. SpringMVC\u7b80\u4ecb<\/h3>\n<h4>2.1 SpringMVC\u6982\u8ff0<\/h4>\n<p>SpringMVC\u662f\u4e00\u79cd\u57fa\u4e8eJava\u7684\u5b9e\u73b0MVC\u8bbe\u8ba1\u6a21\u578b\u7684\u8bf7\u6c42\u9a71\u52a8\u7c7b\u578b\u7684\u8f7b\u91cf\u7ea7web\u6846\u67b6&#xff0c;\u5c5e\u4e8eSpringFrameWork\u7684\u540e\u7eed\u4ea7\u54c1&#xff0c;\u5df2\u7ecf\u878d\u5408\u5728Spring Web Flow\u4e2d\u3002<\/p>\n<p>SpringMVC\u5df2\u7ecf\u6210\u4e3a\u76ee\u524d\u6700\u4e3b\u6d41\u7684MVC\u6846\u67b6\u4e4b\u4e00&#xff0c;\u5e76\u4e14\u968f\u7740Spring3.0\u7684\u53d1\u5e03&#xff0c;\u5168\u9762\u8d85\u8d8aStruts2&#xff0c;\u6210\u4e3a\u6700\u4f18\u79c0\u7684MVC\u6846\u67b6\u3002\u5b83\u901a\u8fc7\u4e00\u5957\u6ce8\u89e3&#xff0c;\u8ba9\u4e00\u4e2a\u7b80\u5355\u7684Java\u7c7b\u6210\u4e3a\u5904\u7406\u8bf7\u6c42\u7684\u63a7\u5236\u5668&#xff0c;\u800c\u65e0\u987b\u5b9e\u73b0\u4efb\u4f55\u63a5\u53e3\u3002\u540c\u65f6\u5b83\u8fd8\u652f\u6301RESTful\u7f16\u7a0b\u98ce\u683c\u7684\u8bf7\u6c42\u3002<\/p>\n<\/p>\n<p>2.2 SpringMVC\u5feb\u901f\u5165\u95e8<\/p>\n<p>\u9700\u6c42&#xff1a;\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u7aef\u63a5\u6536\u8bf7\u6c42&#xff0c;\u6267\u884c\u903b\u8f91\u5e76\u8fdb\u884c\u89c6\u56fe\u8df3\u8f6c\u3002<\/p>\n<p>\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u5bfc\u5165SpringMVC\u76f8\u5173\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6eSpringMVC\u6838\u5fc3\u63a7\u5236\u5668DispathcerServlet<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaController\u7c7b\u548c\u89c6\u56fe\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6eController\u7c7b\u4e2d\u4e1a\u52a1\u65b9\u6cd5\u7684\u6620\u5c04\u5730\u5740<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6eSpringMVC\u6838\u5fc3\u6587\u4ef6spring-mvc.xml<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42\u6d4b\u8bd5<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165Servlet\u548cJSP\u5750\u6807<\/p>\n<p> &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;servlet-api&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.5&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;javax.servlet.jsp&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;javax.servlet.jsp-api&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.3.3&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt; <\/li>\n<li>\n<p>\u5728web.xml\u914d\u7f6eSpringMVC\u7684\u6838\u5fc3\u63a7\u5236\u5668<\/p>\n<p> &lt;servlet&gt;<br \/>\n    &lt;servlet-name&gt;DisapatcherServlet&lt;\/servlet-name&gt;<br \/>\n    &lt;servlet-class&gt;<br \/>\n        org.springframework.web.servlet.DispatcherServlet<br \/>\n    &lt;\/servlet-class&gt;<br \/>\n    &lt;init-param&gt;<br \/>\n        &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n        &lt;param-value&gt;classpath:spring-mvc.xml&lt;\/param-value&gt;<br \/>\n    &lt;\/init-param&gt;<br \/>\n    &lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;<br \/>\n&lt;\/servlet&gt;<br \/>\n&lt;servlet-mapping&gt;<br \/>\n    &lt;servlet-name&gt;DispatcherServlet&lt;\/servlet-name&gt;<br \/>\n    &lt;url-pattern&gt;\/&lt;\/url-pattern&gt;<br \/>\n&lt;\/servlet-mapping&gt; <\/p>\n<p>spring-mvc.xml<\/p>\n<p> &lt;!&#8211;Controller\u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.itheima.controller&#034;\/&gt; <\/li>\n<li>\n<p>\u521b\u5efaController\u548c\u4e1a\u52a1\u65b9\u6cd5<\/p>\n<p> &#064;Controller<br \/>\npublic class UserController {<br \/>\n    &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\n    public String save(){<br \/>\n        System.out.println(&#034;controller save running&#8230;&#034;);<br \/>\n        return &#034;success.jsp&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5728webapp\u521b\u5efasuccess.jsp&#xff0c;\u5728\u9996\u9875\u540e\u9762\u8f93\u5165\/quick\u5b8c\u6210<\/p>\n<\/li>\n<h4>2.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>SpringMVC\u7684\u5f00\u53d1\u6b65\u9aa4<\/p>\n<li>\n<p>\u5bfc\u5165SpringMVC\u76f8\u5173\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6eSpringMVC\u6838\u5fc3\u63a7\u5236\u5668DispathcerServlet<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaController\u7c7b\u548c\u89c6\u56fe\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6eController\u7c7b\u4e2d\u4e1a\u52a1\u65b9\u6cd5\u7684\u6620\u5c04\u5730\u5740<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6eSpringMVC\u6838\u5fc3\u6587\u4ef6spring-mvc.xml<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42\u6d4b\u8bd5<\/p>\n<\/li>\n<h3>3.SpringMVC\u7ec4\u4ef6\u89e3\u6790<\/h3>\n<h4>3.1 SpringMVC\u7684\u6267\u884c\u8fc7\u7a0b<\/h4>\n<\/p>\n<li>\n<p>\u7528\u6237\u53d1\u9001\u8bf7\u6c42\u81f3\u524d\u7aef\u63a7\u5236\u5668DiapatcherServlet<\/p>\n<\/li>\n<li>\n<p>DiapatcherServlet\u6536\u5230\u8bf7\u6c42\u8c03\u7528HandlerMapping\u5904\u7406\u5668\u6620\u5c04\u5668<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668\u6620\u5c04\u5668\u627e\u5230\u5177\u4f53\u7684\u5904\u7406\u5668&#xff08;\u53ef\u4ee5\u6839\u636exml\u914d\u7f6e\u3001\u6ce8\u89e3\u8fdb\u884c\u67e5\u627e&#xff09;&#xff0c;\u751f\u6210\u5904\u7406\u5bf9\u8c61\u53ca\u5904\u7406\u5668\u62e6\u622a\u5668&#xff08;\u5982\u679c\u6709\u5219\u751f\u6210&#xff09;\u4e00\u5e76\u8fd4\u56de\u7ed9DispatcherServlet<\/p>\n<\/li>\n<li>\n<p>DiapatcherServlet\u8c03\u7528HandlerAdapter\u5904\u7406\u5668\u9002\u914d\u5668<\/p>\n<\/li>\n<li>\n<p>HandlerAdapter\u7ecf\u8fc7\u9002\u914d\u8c03\u7528\u5177\u4f53\u7684\u5904\u7406\u5668&#xff08;Controller&#xff0c;\u4e5f\u53eb\u540e\u7aef\u63a7\u5236\u5668&#xff09;<\/p>\n<\/li>\n<li>\n<p>Controller\u6267\u884c\u5b8c\u6210\u8fd4\u56deModelAndView<\/p>\n<\/li>\n<li>\n<p>HandlerAdapter\u5c06controller\u6267\u884c\u7ed3\u679cModelAndView\u8fd4\u56de\u7ed9DispatcherServlet<\/p>\n<\/li>\n<li>\n<p>DispatcherServlet\u5c06ModelAndView\u4f20\u7ed9ViewReslover\u89c6\u56fe\u89e3\u6790\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>ViewReslover\u89e3\u6790\u540e\u8fd4\u56de\u5177\u4f53View<\/p>\n<\/li>\n<li>\n<p>DispatcherServlet\u6839\u636eView\u8fdb\u884c\u6e32\u67d3\u89c6\u56fe(\u5373\u5c06\u6a21\u578b\u6570\u636e\u586b\u5145\u81f3\u89c6\u56fe\u4e2d)\u3002DisapatcherServlet\u54cd\u5e94\u7528\u6237\u3002<\/p>\n<\/li>\n<li>\n<p>fdsdsd<\/p>\n<\/li>\n<h4>3.2 SpringMVC\u7ec4\u4ef6\u89e3\u6790<\/h4>\n<li>\n<p>\u524d\u7aef\u63a7\u5236\u5668&#xff1a;DispatcherServlet<\/p>\n<p>\u7528\u6237\u8bf7\u6c42\u5230\u8fbe\u524d\u7aef\u63a7\u5236\u5668&#xff0c;\u5b83\u5c31\u76f8\u5f53\u4e8eMVC\u6a21\u5f0f\u4e2d\u7684C&#xff0c;DispatcherServlet\u662f\u6574\u4e2a\u6d41\u7a0b\u63a7\u5236\u7684\u4e2d\u5fc3&#xff0c;\u7531\u5b83\u8c03\u7528\u5176\u4ed6\u7ec4\u4ef6\u5904\u7406\u7528\u6237\u7684\u8bf7\u6c42&#xff0c;DispatcherServlet\u7684\u5b58\u5728\u964d\u4f4e\u4e86\u7ec4\u4ef6\u4e4b\u95f4\u7684\u8026\u5408\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668\u6620\u5c04\u5668&#xff1a;HandlerMapping<\/p>\n<p>HandlerMapping\u8d1f\u8d23\u6839\u636e\u7528\u6237\u8bf7\u6c42\u627e\u5230Handler\u5373\u5904\u7406\u5668&#xff0c;SpringMVC\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u6620\u5c04\u5668\u5b9e\u73b0\u4e0d\u540c\u6620\u5c04\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u914d\u7f6e\u6587\u4ef6\u65b9\u5f0f&#xff0c;\u5b9e\u73b0\u63a5\u53e3\u65b9\u5f0f&#xff0c;\u6ce8\u89e3\u65b9\u5f0f\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668\u9002\u914d\u5668&#xff1a;HandlerAdapter<\/p>\n<p>\u901a\u8fc7HandlerAdapter\u5bf9\u5904\u7406\u5668\u8fdb\u884c\u6267\u884c&#xff0c;\u8fd9\u662f\u9002\u914d\u5668\u6a21\u5f0f\u7684\u5e94\u7528&#xff0c;\u901a\u8fc7\u6269\u5c55\u9002\u914d\u5668\u53ef\u4ee5\u5bf9\u66f4\u591a\u7c7b\u578b\u7684\u5904\u7406\u5668\u8fdb\u884c\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668&#xff1a;Handler<\/p>\n<p>\u5b83\u5c31\u662f\u6211\u4eec\u5f00\u53d1\u4e2d\u8981\u7f16\u5199\u7684\u5177\u4f53\u4e1a\u52a1\u63a7\u5236\u5668\u3002\u7531DispatcherServlet\u628a\u7528\u6237\u8bf7\u6c42\u8f6c\u53d1\u5230Handler\u3002\u7531Handler\u5bf9\u5177\u4f53\u7684\u7528\u6237\u8bf7\u6c42\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe\u89e3\u6790\u5668&#xff1a;View Resolver<\/p>\n<p>View Resolver\u8d1f\u8d23\u5c06\u5904\u7406\u7ed3\u679c\u751f\u6210View\u89c6\u56fe&#xff0c;View Resolver\u9996\u5148\u6839\u636e\u903b\u8f91\u89c6\u56fe\u540d\u89e3\u6790\u6210\u7269\u7406\u89c6\u56fe\u540d&#xff0c;\u5373\u5177\u4f53\u7684\u9875\u9762\u5730\u5740&#xff0c;\u518d\u751f\u6210View\u89c6\u56fe\u5bf9\u8c61&#xff0c;\u6700\u540e\u5bf9View\u8fdb\u884c\u6e32\u67d3\u5c06\u5904\u7406\u7ed3\u679c\u901a\u8fc7\u9875\u9762\u5c55\u793a\u7ed9\u7528\u6237\u3002<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe&#xff1a;View<\/p>\n<p>SpringMVC\u6846\u67b6\u63d0\u4f9b\u4e86\u5f88\u591a\u7684View\u89c6\u56fe\u7c7b\u578b\u7684\u652f\u6301&#xff0c;\u5305\u62ec&#xff1a;jstView\u3001freemarkerView\u3001pdfView\u7b49\u3002\u6700\u5e38\u7528\u7684\u89c6\u56fe\u5c31\u662fjsp\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u9700\u8981\u901a\u8fc7\u9875\u9762\u6807\u7b7e\u6216\u9875\u9762\u6a21\u677f\u6280\u672f\u5c06\u6a21\u578b\u6570\u636e\u901a\u8fc7\u9875\u9762\u5c55\u793a\u7ed9\u7528\u6237&#xff0c;\u9700\u8981\u7531\u7a0b\u5e8f\u5458\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u5f00\u53d1\u5177\u4f53\u9875\u9762<\/p>\n<\/li>\n<h4>3.3 \u6ce8\u89e3\u89e3\u6790<\/h4>\n<p>&#064;RequestMapping<\/p>\n<p>\u4f5c\u7528&#xff1a;\u7528\u4e8e\u5efa\u7acbURL\u548c\u5904\u7406\u8bf7\u6c42\u65b9\u6cd5\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb<\/p>\n<p>\u4f4d\u7f6e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7c7b\u4e0a&#xff0c;\u8bf7\u6c42URL\u7684\u7b2c\u4e00\u7ea7\u8bbf\u95ee\u76ee\u5f55\u3002\u6b64\u5904\u4e0d\u5199\u7684\u8bdd&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u5e94\u7528\u7684\u6839\u76ee\u5f55<\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u4e0a&#xff0c;\u8bf7\u6c42URL\u7684\u7b2c\u4e8c\u7ea7\u8bbf\u95ee\u76ee\u5f55&#xff0c;\u4e0e\u7c7b\u4e0a\u7684\u4f7f\u7528&#064;RequetMap\u6807\u6ce8\u7684\u4e00\u7ea7\u76ee\u5f55\u4e00\u8d77\u7ec4\u6210\u8bbf\u95ee\u865a\u62df\u8def\u5f84<\/p>\n<p> &#064;Controller<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController{<br \/>\n    \/\/\u8bf7\u6c42\u5730\u5740 Http:\/\/localhost:8080\/user\/quick<br \/>\n    &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\n    public String save(){<br \/>\n        System.out.println(&#034;controller save running&#8230;&#034;);<br \/>\n        \/\/\u52a0\/\u5219\u662f\u5728\u5f53\u524d\u5e94\u7528\u627e\u8be5\u6587\u4ef6&#xff0c;\u4e0d\u52a0\u5c31\u662f\u5728user\u76ee\u5f55\u4e0b\u627e\u8be5\u6587\u4ef6<br \/>\n        return &#034;\/success.jsp&#034;;<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>value&#xff1a;\u7528\u4e8e\u6307\u5b9a\u8bf7\u6c42\u7684URL&#xff0c;\u5b83\u548cpath\u5c5e\u6027\u7684\u4f5c\u7528\u4e00\u6837\u7684&#xff08;\u5f53\u53ea\u5199value&#xff0c;\u53ef\u4ee5\u7701\u7565value&#061;&#xff0c;\u591a\u4e2a\u5185\u5bb9&#xff0c;\u8981\u5e26\u4e0avalue&#061;\u201c\/quick\u201d&#xff09;<\/p>\n<\/li>\n<li>\n<p>method&#xff1a;\u7528\u4e8e\u6307\u5b9a\u8bf7\u6c42\u7684\u65b9\u5f0f \u4f8b\u5982&#xff1a;method&#061;RequestMethod.GET<\/p>\n<\/li>\n<li>\n<p>params&#xff1a;\u7528\u4e8e\u6307\u5b9a\u9650\u5236\u8bf7\u6c42\u53c2\u6570\u7684\u6761\u4ef6\u3002\u4ed6\u6307\u51fa\u7b80\u5355\u7684\u8868\u8fbe\u5f0f\u3002\u8981\u6c42\u8bf7\u6c42\u53c2\u6570\u7684key\u548cvalue\u5fc5\u987b\u548c\u914d\u7f6e\u7684\u4e00\u6a21\u4e00\u6837<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>params&#061;{&#034;accountName&#034;}&#xff0c;\u8868\u793a\u8bf7\u6c42\u53c2\u6570\u5fc5\u987b\u6709accountName<\/p>\n<\/li>\n<li>\n<p>params&#061;{&#034;money!100&#034;}&#xff0c;\u8868\u793a\u8bf7\u6c42\u53c2\u6570\u4e2d\u7684money\u4e0d\u80fd\u662f100<\/p>\n<p> &#064;Controller<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController{<br \/>\n    \/\/\u8bf7\u6c42\u5730\u5740 Http:\/\/localhost:8080\/user\/quick?username&#061;xxx \u624d\u6210\u529f<br \/>\n  &#064;RequestMapping(value&#061;&#034;\/quick&#034;,method&#061;RequestMethod.GET,params&#061;&#034;username&#034;)<br \/>\n    public String save(){<br \/>\n        System.out.println(&#034;controller save running&#8230;&#034;);<br \/>\n        \/\/\u52a0\/\u5219\u662f\u5728\u5f53\u524d\u5e94\u7528\u627e\u8be5\u6587\u4ef6&#xff0c;\u4e0d\u52a0\u5c31\u662f\u5728user\u76ee\u5f55\u4e0b\u627e\u8be5\u6587\u4ef6<br \/>\n        return &#034;\/success.jsp&#034;;<br \/>\n    }<br \/>\n} <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>spring-mvc.xml\u6ce8\u89e3\u626b\u63cf\u8be6\u89e3<\/p>\n<li>\n<p>mvc\u547d\u540d\u7a7a\u95f4\u5f15\u5165<\/p>\n<p> \u547d\u540d\u7a7a\u95f4&#xff1a;xmlns:context&#061;&#034;http:\/\/www.springframework.org\/schema\/context&#034;<br \/>\n                xmlns:mvc&#061;&#034;http:\/\/www.springframework.org\/schema\/mvc&#034;<br \/>\n\u7ea6\u675f\u5730\u5740&#xff1a;http:\/\/www.springframework.org\/schema\/context<br \/>\n         http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd<br \/>\n         http:\/\/www.springframework.org\/schema\/mvc<br \/>\n         http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\n <\/li>\n<li>\n<p>\u7ec4\u4ef6\u626b\u63cf<\/p>\n<p>SpringMVC\u57fa\u4e8espring\u5bb9\u5668&#xff0c;\u6240\u4ee5\u5728\u8fdb\u884cspringmvc\u64cd\u4f5c\u65f6&#xff0c;\u9700\u8981\u5c06Controller\u5b58\u50a8\u5230spring\u5bb9\u5668\u4e2d&#xff0c;\u5982\u679c\u4f7f\u7528&#064;Controller\u6ce8\u89e3\u6807\u6ce8\u7684\u8bdd&#xff0c;\u5c31\u9700\u8981\u4f7f\u7528&lt;context:component-scan base-package&#061;\u201ccom.itheima.controller\u201c\/&gt;\u8fdb\u884c\u7ec4\u4ef6\u626b\u63cf\u3002<\/p>\n<ul>\n<li>\n<p>\u53ea\u662f\u4f46\u626b\u63cf\u4e00\u4e2a\u5305\u7684\u8bdd\u53ef\u4ee5\u5199&lt;context:component-scan base-package&#061;\u201ccom.itheima.controller\u201c\/&gt;<\/p>\n<\/li>\n<li>\n<p>\u4f46\u8981\u626b\u63cf\u5168\u90e8\u5305\u4e0b\u7684controller&#xff0c;\u4f1a\u548capplication Context\u7684\u626b\u63cf\u76f8\u649e&#xff0c;\u5219\u4e0b\u9762\u662f\u5728\u90a3\u4e9b\u5305\u4e0b\u626b\u63cf\u5305\u4e0b\u7684\u54ea\u4e9b\u7ec4\u4ef6&#xff0c;exclude\u5c31\u662f\u4e0d\u626b\u63cf\u8be5\u7ec4\u4ef6\u7684\u610f\u601d<\/p>\n<p> &lt;!&#8211;Controller\u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;context:component-scan base-package&#061;&#034;com.itheima&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;context:include-filter type&#061;&#034;annotation&#034; expression&#061;&#034;org.springframework.stereotype.Controller&#034;\/&gt;<br \/>\n \u00a0 \u00a0&lt;\/context:component-scan&gt; <\/li>\n<\/ul>\n<\/li>\n<h4>3.4 SpringMVC\u7684XML\u914d\u7f6e\u89e3\u6790<\/h4>\n<li>\n<p>\u89c6\u56fe\u89e3\u6790\u5668<\/p>\n<p>SpringMVC\u6709\u9ed8\u8ba4\u7ec4\u4ef6\u914d\u7f6e&#xff0c;\u9ed8\u8ba4\u7ec4\u4ef6\u90fd\u662fDispatcherServlet.properties\u914d\u7f6e\u6587\u4ef6&#xff08;\u5728spring&#061;mvc\u5305\u4e0b\u7684view&#xff09;\u4e2d\u914d\u7f6e\u7684&#xff0c;\u8be5\u914d\u7f6e\u6587\u4ef6\u5730\u5740org\/springframework\/web\/servlet\/DispatcherServlet.properties&#xff0c;\u8be5\u6587\u4ef6\u4e2d\u914d\u7f6e\u4e86\u9ed8\u8ba4\u7684\u89c6\u56fe\u89e3\u6790\u5668&#xff0c;\u5982\u4e0b&#xff1a;<\/p>\n<p> org.springframework.web.servlet.ViewResolver&#061;org.springframework.web.servlet.view.InternalResourceViewResolver <\/p>\n<p>\u7ffb\u770b\u8be5\u89e3\u6790\u5668\u6e90\u7801&#xff0c;\u53ef\u4ee5\u770b\u5230\u8be5\u89e3\u6790\u5668\u7684\u9ed8\u8ba4\u8bbe\u7f6e&#xff0c;\u5982\u4e0b&#xff1a;<\/p>\n<p>REDIRECT_URL_PREFIX &#061; &#034;redirect:&#034; &#8211;\u91cd\u5b9a\u5411\u524d\u7f00<\/p>\n<p>FORWARD_URL_PREFIX &#061; &#034;forward:&#034; &#8211;\u8f6c\u53d1\u524d\u7f00&#xff08;\u9ed8\u8ba4\u503c&#xff09;<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p> &#064;Controller<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController{<br \/>\n  &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\n    public String save(){<br \/>\n        System.out.println(&#034;controller save running&#8230;&#034;);<br \/>\n        \/\/\u52a0\/\u5219\u662f\u5728\u5f53\u524d\u5e94\u7528\u627e\u8be5\u6587\u4ef6&#xff0c;\u4e0d\u52a0\u5c31\u662f\u5728user\u76ee\u5f55\u4e0b\u627e\u8be5\u6587\u4ef6<br \/>\n        \/\/\u5f53\u8fd4\u56de\u503c\u5565\u90fd\u6ca1\u5199&#xff0c;\u9ed8\u8ba4\u6709forward: \u4e14\u5730\u5740\u8bbf\u95ee\u65f6\u5730\u5740\u4e0d\u53d8<br \/>\n        \/\/\u5730\u5740&#xff1a;Http:\/\/localhost:8080\/user\/quick<br \/>\n        \/\/return &#034;(forward:)\/success.jsp&#034;;<\/p>\n<p>        \/\/\u5f53\u5199\u4e86redirect:\u5728\u524d\u9762&#xff0c;\u5219\u662f\u91cd\u5b9a\u5411<br \/>\n        \/\/\u8bbf\u95ee\u5730\u5740\u5219\u4f1a\u53d8\u6210http:\/\/localhost:8080\/success.jsp<br \/>\n        return &#034;redirect:\/success.jsp&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<p>prefix &#061; &#034;&#034;; &#8211;\u89c6\u56fe\u540d\u79f0\u524d\u7f00<\/p>\n<p>suffix &#061; &#034;&#034;; &#8211;\u89c6\u56fe\u540d\u79f0\u540e\u7f00<\/p>\n<p> &lt;bean id&#061;&#034;viewResolver&#034; class&#061;&#034;org.springframework.web.servlet.view.InternalResourceViewResolver&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;prefix&#034; value&#061;&#034;\/jsp\/&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;suffix&#034; value&#061;&#034;.jsp&#034;\/&gt;<br \/>\n&lt;\/bean&gt; <\/p>\n<p>\u5219Controller\u8fd4\u56de\u503c\u53ef\u4ee5\u5c11\u5199\u4e00\u70b9\u4e1c\u897f<\/p>\n<p> &#064;Controller<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController{<br \/>\n  &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\n    public String save(){<br \/>\n        System.out.println(&#034;controller save running&#8230;&#034;);<br \/>\n        return &#034;success&#034;;<br \/>\n        \/\/\u4f1a\u8bbf\u95eeweb\u4e0bjsp\u76ee\u5f55\u4e0b\u7684success.jsp\u6587\u4ef6<br \/>\n    }<br \/>\n} <\/li>\n<h4>3.5 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<ul>\n<li>\n<p>\u524d\u7aef\u63a7\u5236\u5668&#xff1a;DispatcherServlet<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668\u6620\u5c04\u5668&#xff1a;HandlerMapping<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u5668&#xff1a;Handler<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe\u89e3\u6790\u5668&#xff1a;View Resolver<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe&#xff1a;View<\/p>\n<\/li>\n<\/ul>\n<p>SpringMVC\u7684\u6ce8\u89e3\u548c\u914d\u7f6e<\/p>\n<ul>\n<li>\n<p>\u8bf7\u6c42\u6620\u5c04\u6ce8\u89e3&#xff1a;&#064;RequestMapping<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe\u89e3\u6790\u5668\u914d\u7f6e&#xff1a;<\/p>\n<p>REDIRECT_URL_PREFIX &#061; &#034;redirect:&#034;<\/p>\n<p>FORWARD_URL_PREFIX &#061; &#034;forward:&#034;<\/p>\n<p>prefix &#061; &#034;&#034;;<\/p>\n<p>suffix &#061; &#034;&#034;;<\/p>\n<\/li>\n<\/ul>\n<h2>02-SpringMVC\u7684\u8bf7\u6c42\u548c\u54cd\u5e94<\/h2>\n<h3>1. SpringMVC\u7684\u6570\u636e\u54cd\u5e94<\/h3>\n<h4>1.1 SpringMVC\u7684\u6570\u636e\u54cd\u5e94\u65b9\u5f0f<\/h4>\n<li>\n<p>\u9875\u9762\u8df3\u8f6c<\/p>\n<ul>\n<li>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7ModelAndView\u5bf9\u8c61\u8fd4\u56de<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u56de\u5199\u6570\u636e<\/p>\n<ul>\n<li>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u5bf9\u8c61\u6216\u96c6\u5408<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h4>1.2 \u9875\u9762\u8df3\u8f6c<\/h4>\n<li>\n<p>\u8fd4\u56de\u5b57\u7b26\u4e32\u5f62\u5f0f<\/p>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff1a;\u6b64\u79cd\u65b9\u5f0f\u4f1a\u5c06\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e0e\u89c6\u56fe\u89e3\u6790\u5668\u7684\u524d\u540e\u7f00\u62fc\u63a5\u540e\u8df3\u8f6c<\/p>\n<p> &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\npublic String quickMethod(){<br \/>\n    return &#034;index&#034;;<br \/>\n} &lt;property name&#061;&#034;prefix&#034; value&#061;&#034;\/WEB-INF\/views\/&#034; \/&gt;<br \/>\n&lt;property name&#061;&#034;suffix&#034; value&#061;&#034;.jsp&#034;\/&gt; <\/p>\n<p>\u8f6c\u53d1\u8d44\u6e90\u5730\u5740&#xff1a;\/WEB-INF\/views.jsp<\/p>\n<p>\u8fd4\u56de\u5e26\u6709\u524d\u7f00\u7684\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<p>\u8f6c\u53d1&#xff1a;forward:\/WEB-INF\/views\/index.jsp<\/p>\n<p>\u91cd\u5b9a\u5411&#xff1a;redirect:\/index.jsp<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56deModelAndView\u5bf9\u8c61<\/p>\n<p>View\u662f\u89c6\u56fe\u5bf9\u8c61 \u4e5f\u5c31\u662f\u8fd4\u56de\u89c6\u56fe\u7f51\u9875\u8df3\u8f6c\u6548\u679c<\/p>\n<p>Model\u662f\u6a21\u578b\u5bf9\u8c61 \u4e5f\u5c31\u662f\u5728\u7279\u5b9a\u7f51\u9875\u91cc\u9762\u8d4b\u503c&#xff0c;\u4ee5id\u6765\u533a\u5206<\/p>\n<p> &#064;RequestMapping(&#034;\/quick2&#034;)<br \/>\npublic ModelAndView save2(){<br \/>\n    \/*<br \/>\n    * Model&#xff1a;\u6a21\u578b \u4f5c\u7528\u5c01\u88c5\u6570\u636e<br \/>\n    * View&#xff1a;\u89c6\u56fe \u4f5c\u7528\u5c55\u793a\u6570\u636e<br \/>\n    * *\/<br \/>\n    ModelAndView modelAndView &#061; new ModelAndView();<br \/>\n    \/\/\u8bbe\u7f6e\u6a21\u578b\u5bf9\u8c61<br \/>\n    modelAndView.addObject(&#034;username&#034;,&#034;cxy&#034;);<br \/>\n    \/\/\u8bbe\u7f6e\u89c6\u56fe\u540d\u79f0<br \/>\n    modelAndView.setViewName(&#034;index&#034;);<br \/>\n    return modelAndView;<br \/>\n} &lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;title&gt;helloWorld&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;h1&gt;helloWorld!${username}&lt;\/h1&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt; <\/p>\n<p>\u8f93\u5165\u7f51\u9875\u6620\u5c04\u540d&#xff0c;\u51fa\u73b0helloworld&#xff01;cxy<\/p>\n<p>\u4e5f\u6709\u4e0d\u540c\u7684\u4e66\u5199ModelAndView\u65b9\u6cd5<\/p>\n<p> &#064;RequestMapping(&#034;\/quick3&#034;)<br \/>\npublic ModelAndView save3(ModelAndView modelAndView){<br \/>\n    \/*<br \/>\n    * Model&#xff1a;\u6a21\u578b \u4f5c\u7528\u5c01\u88c5\u6570\u636e<br \/>\n    * View&#xff1a;\u89c6\u56fe \u4f5c\u7528\u5c55\u793a\u6570\u636e<br \/>\n    spring\u8bc6\u522b\u81ea\u5df1\u6ce8\u5165\u5bf9\u8c61<br \/>\n    * *\/<br \/>\n    \/\/\u8bbe\u7f6e\u6a21\u578b\u5bf9\u8c61<br \/>\n    modelAndView.addObject(&#034;username&#034;,&#034;cxy3&#034;);<br \/>\n    \/\/\u8bbe\u7f6e\u89c6\u56fe\u540d\u79f0<br \/>\n    modelAndView.setViewName(&#034;index&#034;);<br \/>\n    return modelAndView;<br \/>\n} &#064;RequestMapping(&#034;\/quick4&#034;)<br \/>\npublic String save4(Model model){<br \/>\n    \/*<br \/>\n    \u628aModelAndView\u62c6\u5f00\u4f7f\u7528<br \/>\n    * *\/<br \/>\n    model.addAttribute(&#034;username&#034;,&#034;cxy4&#034;);<br \/>\n    return &#034;index&#034;;<br \/>\n} <\/li>\n<li>\n<p>\u5411request\u57df\u5b58\u50a8\u6570\u636e<\/p>\n<p>\u5728\u8fdb\u884c\u8f6c\u53d1\u65f6&#xff0c;javaweb\u90fd\u662f\u7528request\u57df\u4e2d\u5b58\u50a8\u6570\u636e\u5728jsp\u663e\u793a&#xff0c;\u90a3\u4e48\u4f7f\u7528Controoller\u5728&#xff0c;\u6709\u5b58\u50a8\u6570\u636e\u5462&#xff1f;&#xff08;\u4e00\u822c\u4e0d\u4f7f\u7528&#xff0c;\u56e0\u4e3aspring\u6846\u67b6\u5df2\u7ecf\u7ed9\u4f60\u4e00\u4e2aModelAndView\u5bf9\u8c61\u4e86&#xff0c;\u6ca1\u6709\u5fc5\u8981&#xff09;<\/p>\n<p> &#064;RequestMapping(&#034;\/quick&#034;)<br \/>\npublic String quickMethod(HttpServletRequest request){<br \/>\n    request.setAttribute(&#034;name&#034;,&#034;zhangsan&#034;);<br \/>\n    return &#034;index&#034;;<br \/>\n} <\/li>\n<h4>1.3 \u56de\u5199\u6570\u636e<\/h4>\n<li>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n<p>Web\u57fa\u7840\u9636\u6bb5&#xff0c;\u5ba2\u6237\u7aef\u8bbf\u95ee\u670d\u52a1\u5668\u7aef&#xff0c;\u5982\u679c\u60f3\u76f4\u63a5\u56de\u5199\u5b57\u7b26\u4e32\u4f5c\u4e3a\u54cd\u5e94\u4f53\u8fd4\u56de\u7684\u8bdd&#xff0c;\u53ea\u9700\u8981\u4f7f\u7528response.getWriter().print(&#034;Hello world&#034;)\u5373\u53ef&#xff0c;\u90a3\u4e48\u5728Controller\u4e2d\u60f3\u76f4\u63a5\u56de\u5199\u5b57\u7b26\u4e32\u8be5\u600e\u6837\u5462&#xff1f;<\/p>\n<li>\n<p>\u901a\u8fc7SpringMVC\u6846\u67b6\u6ce8\u5165\u7684response\u5bf9\u8c61&#xff0c;\u4f7f\u7528response.getWriter().print(&#034;Hello world&#034;)\u56de\u5199\u6570\u636e&#xff0c;\u6b64\u65f6\u4e0d\u9700\u8981\u89c6\u56fe\u8df3\u8f6c&#xff0c;\u4e1a\u52a1\u65b9\u6cd5\u8fd4\u56de\u503c\u4e3avoid<\/p>\n<p> &#064;RequestMapping(&#034;\/quick6&#034;)<br \/>\n    public void save6(HttpServletResponse response) throws IOException {<br \/>\n        response.getWriter().print(&#034;itcast&#034;);<br \/>\n    } <\/p>\n<\/li>\n<li>\n<p>\u5c06\u9700\u8981\u56de\u5199\u5b57\u7b26\u4e32\u76f4\u63a5\u8fd4\u56de&#xff0c;\u4f46\u6b64\u65f6\u9700\u8981\u901a\u8fc7&#064;ResponseBody\u6ce8\u89e3\u544a\u77e5SpringMVC\u6846\u67b6&#xff0c;\u8fd9\u662f\u4f7f\u7528response\u76f4\u63a5\u56de\u5199\u6570\u636e&#xff0c;\u800c\u4e0d\u662f\u8df3\u8f6c\u9875\u9762&#xff0c;\u65b9\u6cd5\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e0d\u662f\u8df3\u8f6c\u662f\u76f4\u63a5\u5728http\u54cd\u5e94\u4f53\u4e2d\u8fd4\u56de\u3002<\/p>\n<p> &#064;RequestMapping(&#034;\/quick7&#034;)<br \/>\n    &#064;ResponseBody \/\/\u544a\u77e5SpringMVC\u6846\u67b6\u4e0d\u662f\u8fdb\u884c\u9875\u9762\u8df3\u8f6c&#xff0c;\u662f\u76f4\u63a5\u8fdb\u884c\u6570\u636e\u54cd\u5e94<br \/>\n    public String save7(){<br \/>\n        return &#034;hello itheima&#034;;<br \/>\n    } <\/li>\n<li>\n<p>\u5728\u5f02\u6b65\u9879\u76ee\u4e2d&#xff0c;\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7aef\u5f80\u5f80\u8981\u8fdb\u884cjson\u683c\u5f0f\u5b57\u7b26\u4e32\u4ea4\u4e92&#xff0c;\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u62fc\u63a5json\u5b57\u7b26\u4e32\u8fd4\u56de\u3002<\/p>\n<p> &#064;RequestMapping(&#034;\/quick8&#034;)<br \/>\n    &#064;ResponseBody<br \/>\n    public String save8(){<br \/>\n        return &#034;{\\\\&#034;name\\\\&#034;:\\\\&#034;cxy\\\\&#034;,\\\\&#034;age\\\\&#034;:18}&#034;;<br \/>\n    } <\/p>\n<p>\u4e0a\u8ff0\u65b9\u5f0f\u624b\u52a8\u62fc\u63a5json\u683c\u5f0f\u5b57\u7b26\u4e32\u7684\u65b9\u5f0f\u5f88\u9ebb\u70e6&#xff0c;\u5f00\u53d1\u4e2d\u5f80\u5f80\u8981\u5c06\u590d\u6742\u7684Java\u5bf9\u8c61\u88c5\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528web\u9636\u6bb5\u5b66\u4e60\u8fc7\u7684json\u8f6c\u6362\u5de5\u5177jackson\u8fdb\u884c\u8f6c\u6362&#xff0c;\u5bfc\u5165jackson\u5750\u6807\u3002<\/p>\n<p>         &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;jackson-core&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.12.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.12.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;jackson-annotations&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.12.1&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt; <\/p>\n<p>\u901a\u8fc7jackson\u8f6c\u6362json\u683c\u5f0f\u5b57\u7b26\u4e32&#xff0c;\u56de\u5199\u5b57\u7b26\u4e32<\/p>\n<p> &#064;RequestMapping(&#034;\/quick9&#034;)<br \/>\n    &#064;ResponseBody<br \/>\n    public String save9() throws JsonProcessingException {<br \/>\n        User user &#061; new User();<br \/>\n        user.setName(&#034;lisi&#034;);<br \/>\n        user.setAge(39);<br \/>\n        \/\/\u4f7f\u7528json\u7684\u8f6c\u6362\u5de5\u5177\u5c06\u5bf9\u8c61\u8f6c\u6362\u6210json\u683c\u5f0f\u5b57\u7b26\u4e32\u5728\u8fd4\u56de<br \/>\n        ObjectMapper objectMapper&#061;new ObjectMapper();<br \/>\n        String s &#061; objectMapper.writeValueAsString(user);<br \/>\n        return s;<br \/>\n    } <\/li>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u5bf9\u8c61\u6216\u96c6\u5408<\/p>\n<p>\u901a\u8fc7SpringMVC\u5e2e\u52a9\u6211\u4eec\u5bf9\u5bf9\u8c61\u6216\u96c6\u5408\u8fdb\u884cjson\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u5e76\u56de\u5199&#xff0c;\u4e3a\u5904\u7406\u5668\u9002\u914d\u5668\u6d88\u606f\u8f6c\u6362\u53c2\u6570&#xff0c;\u6307\u5b9a\u4f7f\u7528Jackson\u8fdb\u884c\u5bf9\u8c61\u6216\u96c6\u5408\u7684\u8f6c\u6362&#xff0c;\u56e0\u6b64\u9700\u8981\u5728spring-mvc.xml\u8fdb\u884c\u5982\u4e0b\u914d\u7f6e&#xff1a;<\/p>\n<p> &lt;!&#8211;    \u914d\u7f6e\u5904\u7406\u5668\u6620\u5c04\u5668&#8211;&gt;<br \/>\n    &lt;bean class&#061;&#034;org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;messageConverters&#034;&gt;<br \/>\n            &lt;list&gt;<br \/>\n                &lt;bean class&#061;&#034;org.springframework.http.converter.json.MappingJackson2HttpMessageConverter&#034;\/&gt;<br \/>\n            &lt;\/list&gt;<br \/>\n        &lt;\/property&gt;<br \/>\n    &lt;\/bean&gt; &#064;RequestMapping(&#034;\/quick10&#034;)<br \/>\n&#064;ResponseBody<br \/>\n\/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\npublic User save10() throws JsonProcessingException {<br \/>\n    User user &#061; new User();<br \/>\n    user.setName(&#034;lisi&#034;);<br \/>\n    user.setAge(39);<br \/>\n    return user;<br \/>\n} <\/p>\n<p>\u5728\u65b9\u6cd5\u4e0a\u6dfb\u52a0&#064;ResponseBody\u5c31\u53ef\u4ee5\u8fd4\u56dejson\u683c\u5f0f\u7684\u5b57\u7b26\u4e32&#xff0c;\u4f46\u662f\u8fd9\u6837\u914d\u7f6e\u6bd4\u8f83\u9ebb\u70e6&#xff0c;\u914d\u7f6e\u7684\u4ee3\u7801\u6bd4\u8f83\u591a&#xff0c;\u56e0\u6b64&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7684\u6ce8\u89e3\u9a71\u52a8\u4ee3\u66ff\u4e0a\u8ff0\u914d\u7f6e\u3002<\/p>\n<p> &lt;!&#8211;    mvc\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;mvc:annotation-driven\/&gt; <\/p>\n<p>\u5728SpringMVC\u7684\u5404\u4e2a\u7ec4\u4ef6\u4e2d&#xff0c;\u5904\u7406\u5668\u6620\u5c04\u5668\u3001\u5904\u7406\u5668\u9002\u914d\u5668\u3001\u89c6\u56fe\u89e3\u6790\u5668\u79f0\u4e3aSpringMVC\u7684\u4e09\u5927\u7ec4\u4ef6\u3002\u4f7f\u7528&lt;mvc:annotation-driven &gt;\u81ea\u52a8\u52a0\u8f7dRequestMapping&#xff08;\u5904\u7406\u6620\u5c04\u5668&#xff09;\u548cRequestMappingHandlerAdapter&#xff08;\u5904\u7406\u9002\u914d\u5668&#xff09;&#xff0c;\u53ef\u7528\u5728Spring-xml.xml\u914d\u7f6e\u6587\u4ef6\u4e2d\u4f7f\u7528&lt;mvc:annotation-driven\/ &gt;\u66ff\u4ee3\u6ce8\u89e3\u5904\u7406\u5668\u548c\u9002\u914d\u5668\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u540c\u65f6\u4f7f\u7528&lt;mvc:annotation-driven\/ &gt;\u9ed8\u8ba4\u5e95\u5c42\u5c31\u4f1a\u96c6\u6210jackson\u8fdb\u884c\u5bf9\u8c61\u6216\u96c6\u5408\u7684json\u683c\u5f0f\u5b57\u7b26\u4e32\u7684\u8f6c\u6362\u3002<\/p>\n<\/li>\n<h4>1.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<li>\n<p>\u9875\u9762\u8df3\u8f6c<\/p>\n<ul>\n<li>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26&#xff08;\u89c6\u56fe\u8df3\u8f6c \u662f\u91cd\u5b9a\u5411\u8fd8\u662f\u8f6c\u53d1&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7ModelAndView\u5bf9\u8c61\u8fd4\u56de<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u56de\u5199\u6570\u636e<\/p>\n<ul>\n<li>\n<p>\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u5bf9\u8c61\u6216\u96c6\u5408<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h3>2. springMVC\u83b7\u5f97\u8bf7\u6c42\u6570\u636e<\/h3>\n<h4>2.1 \u83b7\u5f97\u8bf7\u6c42\u53c2\u6570<\/h4>\n<p>\u5ba2\u6237\u7aef\u8bf7\u6c42\u53c2\u6570\u7684\u683c\u5f0f\u662f&#xff1a;name&#061;value&amp;name&#061;value&#8230;&#8230;<\/p>\n<p>\u670d\u52a1\u5668\u7aef\u8981\u83b7\u5f97\u8bf7\u6c42\u7684\u53c2\u6570&#xff0c;\u6709\u65f6\u8fd8\u9700\u8981\u8fdb\u884c\u6570\u636e\u7684\u5c01\u88c5&#xff0c;SpringMVC\u53ef\u4ee5\u63a5\u6536\u5982\u4e0b\u7c7b\u578b\u7684\u53c2\u6570&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u57fa\u672c\u7c7b\u578b\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>POJO\u7c7b\u578b\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u6570\u7ec4\u7c7b\u578b\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u96c6\u5408\u7c7b\u578b\u53c2\u6570<\/p>\n<\/li>\n<\/ul>\n<h4>2.2 \u83b7\u5f97\u57fa\u672c\u7c7b\u578b\u53c2\u6570<\/h4>\n<p>Controller\u4e2d\u7684\u4e1a\u52a1\u65b9\u6cd5\u7684\u53c2\u6570\u540d\u79f0\u8981\u4e0e\u8bf7\u6c42\u53c2\u6570\u7684name\u4e00\u81f4&#xff0c;\u53c2\u6570\u503c\u4f1a\u81ea\u52a8\u6620\u5c04\u5339\u914d\u3002<\/p>\n<p>http:\/\/localhost:8080\/quick11?username&#061;zhangsan&#038;age&#061;12<br \/>\n    &#064;RequestMapping(&#034;\/quick11&#034;)<br \/>\n    &#064;ResponseBody<br \/>\n    \/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\n    public void save11(String username,int age) throws JsonProcessingException {<br \/>\n        System.out.println(username);<br \/>\n        System.out.println(age);<br \/>\n    } <\/p>\n<h4>2.3 \u83b7\u5f97POJO\u7c7b\u578b\u53c2\u6570&#xff08;\u5b9e\u4f53&#xff09;<\/h4>\n<p>Controller\u4e2d\u7684\u4e1a\u52a1\u65b9\u6cd5\u7684POJO\u53c2\u6570\u7684\u5c5e\u6027\u540d\u4e0e\u8bf7\u6c42\u53c2\u6570\u7684name\u4e00\u81f4&#xff0c;\u53c2\u6570\u503c\u4f1a\u81ea\u52a8\u6620\u5c04\u5339\u914d\u3002<\/p>\n<p>http:\/\/localhost:8080\/itheima_springmvc1\/quick9?username&#061;zhangsan&#038;age&#061;12<br \/>\n&#064;RequestMapping(&#034;\/quick12&#034;)<br \/>\n&#064;ResponseBody<br \/>\n\/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\npublic void save12(User user) throws JsonProcessingException {<br \/>\n    System.out.println(user);<br \/>\n} <\/p>\n<p>\u5219\u4f1a\u5728\u63a7\u5236\u53f0\u6253\u5370\u51fa\u6765<\/p>\n<h4>2.4 \u83b7\u5f97\u6570\u7ec4\u7c7b\u578b\u53c2\u6570<\/h4>\n<p>Controller\u4e2d\u7684\u4e1a\u52a1\u65b9\u6cd5\u6570\u7ec4\u540d\u79f0\u4e0e\u8bf7\u6c42\u53c2\u6570\u7684name\u4e00\u81f4&#xff0c;\u53c2\u6570\u503c\u4f1a\u81ea\u52a8\u6620\u5c04\u5339\u914d\u3002<\/p>\n<p>http:\/\/localhost:8080\/quick13?strs&#061;aaa&#038;strs&#061;bbb<\/p>\n<p>&#064;RequestMapping(&#034;\/quick13&#034;)<br \/>\n&#064;ResponseBody<br \/>\n\/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\npublic void save13(String[]strs) throws JsonProcessingException {<br \/>\n    System.out.println(Arrays.asList(strs));<br \/>\n} <\/p>\n<h4>2.5 \u83b7\u5f97\u96c6\u5408\u7c7b\u578b\u53c2\u6570<\/h4>\n<p>\u83b7\u5f97\u96c6\u5408\u53c2\u6570\u65f6&#xff0c;\u8981\u5c06\u96c6\u5408\u53c2\u6570\u5305\u88c5\u5230\u4e00\u4e2aPOJO\u624d\u53ef\u4ee5&#xff08;\u5c31\u662f\u5c06\u96c6\u5408\u7c7b\u578b\u53c2\u6570\u5f04\u6210\u83b7\u5f97pojo\u53c2\u6570&#xff0c;\u5c06\u96c6\u5408\u5c01\u88c5\u8d77\u6765&#xff0c;\u5728\u4f7f\u7528\u65f6\u8981\u5c01\u88c5\u96c6\u5408name\u548c\u8bf7\u6c42\u53c2\u6570\u7684name\u4e00\u81f4&#xff0c;\u7136\u540e\u88ab\u96c6\u5408\u7684\u5bf9\u8c61\u7684\u53c2\u6570\u540d\u79f0\u5728\u5c0f\u6570\u70b9\u540e\u4e00\u81f4&#xff09;<\/p>\n<p>&lt;form action&#061;&#034;${pageContext.request.contextPath}\/quick14&#034; method&#061;&#034;post&#034;&gt;<br \/>\n&lt;%&#8211;    \u8868\u660e\u662f\u7b2c\u51e0\u4e2auser\u5bf9\u8c61\u7684username age&#8211;%&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;userList[0].name&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;userList[0].age&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;userList[1].name&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;userList[1].age&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;submit&#034; value&#061;&#034;\u63d0\u4ea4&#034;&gt;<br \/>\n&lt;\/form&gt;<br \/>\npublic class VO {<br \/>\n    private List&lt;User&gt; userList;<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return &#034;VO{&#034; &#043;<br \/>\n                &#034;userList&#061;&#034; &#043; userList &#043;<br \/>\n                &#039;}&#039;;<br \/>\n    }<\/p>\n<p>    public List&lt;User&gt; getUserList() {<br \/>\n        return userList;<br \/>\n    }<\/p>\n<p>    public void setUserList(List&lt;User&gt; userList) {<br \/>\n        this.userList &#061; userList;<br \/>\n    }<br \/>\n}<br \/>\n&#064;RequestMapping(&#034;\/quick14&#034;)<br \/>\n&#064;ResponseBody<br \/>\n\/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\npublic void save14(VO vo) throws JsonProcessingException {<br \/>\n    System.out.println(vo);<br \/>\n} <\/p>\n<p>\u5f53\u4f7f\u7528ajax\u63d0\u4ea4\u65f6&#xff0c;\u53ef\u4ee5\u6307\u5b9acontentType\u4e3ajson\u5f62\u5f0f&#xff0c;\u90a3\u4e48\u5728\u65b9\u6cd5\u53c2\u6570\u4f4d\u7f6e\u4f7f\u7528&#064;RequestBody\u53ef\u4ee5\u76f4\u63a5\u63a5\u6536\u96c6\u5408\u6570\u636e\u800c\u65e0\u9700\u4f7f\u7528POJO\u8fdb\u884c\u5305\u88c5\u3002<\/p>\n<p>&lt;head&gt;<br \/>\n    &lt;title&gt;Title&lt;\/title&gt;<br \/>\n    &lt;script src&#061;&#034;${pageContext.request.contextPath}\/js\/jquery-3.3.1.js&#034;&gt;&lt;\/script&gt;<br \/>\n    &lt;script&gt;<br \/>\n        var userList&#061;new Array();<br \/>\n        userList.push({name:&#034;zhangsan&#034;,age:18});<br \/>\n        userList.push({name:&#034;lisi&#034;,age:20});<\/p>\n<p>        $.ajax({<br \/>\n            type:&#034;POST&#034;,<br \/>\n            url:&#034;${pageContext.request.contextPath}\/quick15&#034;,<br \/>\n            data:JSON.stringify(userList),<br \/>\n            contentType:&#034;application\/json;charset&#061;utf-8&#034;<br \/>\n        });<br \/>\n    &lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&#064;RequestMapping(&#034;\/quick15&#034;)<br \/>\n&#064;ResponseBody<br \/>\n\/\/\u671f\u671bSpringMVC\u81ea\u52a8\u5c06user\u8f6c\u6362\u6210json\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<br \/>\npublic void save15(&#064;RequestBody List&lt;User&gt; userList) throws JsonProcessingException {<br \/>\n    System.out.println(userList);<br \/>\n}<br \/>\n&lt;!&#8211;    \u5f00\u653e\u8d44\u6e90\u7684\u8bbf\u95ee&#8211;&gt;<br \/>\n    &lt;mvc:resources mapping&#061;&#034;\/js\/**&#034; location&#061;&#034;\/js\/&#034;\/&gt; <\/p>\n<p>\u6ce8\u610f&#xff1a;\u901a\u8fc7\u8c37\u6b4c\u5f00\u53d1\u8005\u5de5\u5177\u6293\u5305\u53d1\u73b0&#xff0c;\u6ca1\u6709\u52a0\u8f7d\u5230jquery\u6587\u4ef6&#xff0c;\u539f\u56e0\u662fSPringMVC\u7684\u524d\u7aef\u63a7\u5236\u5668DispatcherServlet\u7684url-pattern\u914d\u7f6e\u7684\u662f\/&#xff0c;\u4ee3\u8868\u5bf9\u6240\u6709\u7684\u8d44\u6e90\u90fd\u8fdb\u884c\u8fc7\u6ee4\u64cd\u4f5c&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u6307\u5b9a\u653e\u884c\u9759\u6001\u8d44\u6e90&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5728spring-mvc.xml\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u653e\u884c\u7684\u8d44\u6e90<\/p>\n<p>\u524d\u9762\u662f\u6620\u5c04\u8d44\u6e90\u8def\u5f84&#xff0c;\u540e\u9762\u662f\u8d44\u6e90\u8def\u5f84<\/p>\n<p>&lt;mvc:resources mapping&#061;&#034;\/js\/**&#034; location&#061;&#034;\/js\/&#034;\/&gt;<\/p>\n<p>&lt;mvc:resources mapping&#061;&#034;\/img\/**&#034; location&#061;&#034;\/img\/&#034;\/&gt;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528&lt;mvc:default-servlet-handler\/ &gt;\u6807\u7b7e&#xff08;\u4e0d\u9700\u8981\u5199\u591a\u4e2a\u9759\u6001\u8d44\u6e90&#xff0c;\u4e00\u884c\u4ee3\u7801\u641e\u5b9a&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h4>2.6 \u8bf7\u6c42\u6570\u636e\u4e71\u7801\u95ee\u9898<\/h4>\n<p>\u5f53post\u8bf7\u6c42\u65f6&#xff0c;\u6570\u636e\u4f1a\u51fa\u73b0\u4e71\u7801&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u8fc7\u6ee4\u5668\u6765\u8fdb\u884c\u7f16\u7801\u7684\u8fc7\u6ee4\u3002<\/p>\n<p>&lt;!&#8211;    \u914d\u7f6e\u5168\u5c40\u8fc7\u6ee4\u7684filter&#8211;&gt;<br \/>\n    &lt;filter&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;\/filter-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;encoding&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;UTF-8&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n    &lt;\/filter&gt;<br \/>\n    &lt;filter-mapping&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<br \/>\n    &lt;\/filter-mapping&gt; <\/p>\n<h4>2.7 \u53c2\u6570\u7ed1\u5b9a\u6ce8\u89e3&#064;requestParam<\/h4>\n<p>\u5f53\u8bf7\u6c42\u7684\u53c2\u6570\u540d\u79f0\u4e0eController\u7684\u4e1a\u52a1\u65b9\u6cd5\u53c2\u6570\u540d\u79f0\u4e0d\u4e00\u81f4\u65f6&#xff0c;\u5c31\u9700\u8981\u901a\u8fc7&#064;ErquestParam\u6ce8\u89e3\u663e\u793a\u7684\u7ed1\u5b9a\u3002<\/p>\n<p>Http:\/\/localhost:8080\/quick14?name&#061;zhangsan<br \/>\n&lt;form action&#061;&#034;${pageContext.request.contextPath}\/quick14&#034; method&#061;&#034;post&#034;&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;name&#034;&gt;&lt;br&gt;<br \/>\n    &lt;input type&#061;&#034;submit&#034; name&#061;&#034;\u63d0\u4ea4&#034;&gt;&lt;br&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&#064;RequestMapping(&#034;\/quick14&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod14(&#064;RequestParam(&#034;name&#034;) String username) throws IOException{<br \/>\n    sout(&#034;username&#034;);<br \/>\n} <\/p>\n<p>\u6ce8\u89e3&#064;RequestParam\u8fd8\u6709\u5982\u4e0b\u53c2\u6570\u53ef\u4ee5\u4f7f\u7528&#xff1a;<\/p>\n<ul>\n<li>\n<p>value&#xff1a;\u4e0e\u8bf7\u6c42\u53c2\u6570\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>required&#xff1a;\u6b64\u5728\u6307\u5b9a\u7684\u8bf7\u6c42\u53c2\u6570\u662f\u5426\u5fc5\u987b\u5305\u62ec&#xff0c;\u9ed8\u8ba4\u662ftrue&#xff0c;\u63d0\u4ea4\u65f6\u5982\u679c\u6ca1\u6709\u6b64\u53c2\u6570\u5c31\u4f1a\u62a5\u9519<\/p>\n<\/li>\n<li>\n<p>defaultValue&#xff1a;\u5f53\u6ca1\u6709\u6307\u5b9a\u8bf7\u6c42\u53c2\u6570\u65f6&#xff0c;\u5219\u4f7f\u7528\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c\u8d4b\u503c<\/p>\n<p> &#064;RequestMapping(&#034;\/quick14&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod14(&#064;RequestParam(value&#061;&#034;name&#034;,required&#061;false,defaultValue&#061;&#034;itcast&#034;) String username) throws IOException{<br \/>\n    sout(&#034;username&#034;);<br \/>\n} Http:\/\/localhost:8080\/quick14   \u4e0d\u62a5\u9519  \u6253\u5370itcast Http:\/\/localhost:8080\/quick14?name   \u4e0d\u62a5\u9519  \u6253\u5370itcast Http:\/\/localhost:8080\/quick14?name&#061;lisi   \u6253\u5370lisi <\/li>\n<\/ul>\n<h4>2.8 \u83b7\u5f97Restful\u98ce\u683c\u7684\u53c2\u6570<\/h4>\n<p>Restful\u662f\u4e00\u79cd\u8f6f\u4ef6\u67b6\u6784\u3001\u8bbe\u8ba1\u98ce\u683c&#xff0c;\u800c\u4e0d\u662f\u6807\u51c6&#xff0c;\u53ea\u662f\u63d0\u4f9b\u4e86\u4e00\u7ec4\u8bbe\u8ba1\u539f\u5219\u548c\u7ea6\u675f\u6761\u4ef6\u3002\u4e3b\u8981\u7528\u4e8e\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4ea4\u4e92\u7c7b\u5f97\u8f6f\u4ef6&#xff0c;\u57fa\u4e8e\u8fd9\u4e2a\u98ce\u683c\u8bbe\u8ba1\u5f97\u8f6f\u4ef6\u53ef\u4ee5\u66f4\u7b80\u6d01&#xff0c;\u66f4\u6709\u5c42\u6b21&#xff0c;\u66f4\u6613\u4e8e\u5b9e\u73b0\u7f13\u5b58\u673a\u5236\u7b49\u3002<\/p>\n<p>Restful\u98ce\u683c\u7684\u8bf7\u6c42\u662f\u4f7f\u7528&#034;url&#043;\u8bf7\u6c42\u65b9\u5f0f&#034;\u8868\u793a\u4e00\u6b21\u8bf7\u6c42\u76ee\u7684&#xff0c;HTTP\u534f\u8bae\u91cc\u9762\u56db\u4e2a\u8868\u793a\u64cd\u4f5c\u65b9\u5f0f\u7684\u52a8\u8bcd\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>get&#xff1a;\u7528\u4e8e\u83b7\u53d6\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>post&#xff1a;\u7528\u4e8e\u65b0\u5efa\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>put&#xff1a;\u7528\u4e8e\u66f4\u65b0\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>delete&#xff1a;\u7528\u4e8e\u5220\u9664\u8d44\u6e90<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>\/user\/1 get&#xff1a;\u5f97\u5230id&#061;1\u7684user<\/p>\n<\/li>\n<li>\n<p>\/user\/1 delete&#xff1a;\u5220\u9664id&#061;1\u7684user<\/p>\n<\/li>\n<li>\n<p>\/user\/1 put&#xff1a;\u66f4\u65b0id&#061;1\u7684user<\/p>\n<\/li>\n<li>\n<p>\/user\/1 post&#xff1a;\u65b0\u589euser<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0a\u8ff0url\u5730\u5740\/user\/1\u4e2d\u76841\u5c31\u662f\u8981\u83b7\u5f97\u7684\u8bf7\u6c42\u53c2\u6570&#xff0c;\u5728SpringMVC\u4e2d\u53ef\u4ee5\u4f7f\u7528\u5360\u4f4d\u7b26\u8fdb\u884c\u53c2\u6570\u7ed1\u5b9a\u3002\u5730\u5740\/user\/1\u53ef\u4ee5\u5199\u6210\/user\/{id}&#xff0c;\u5360\u4f4d\u7b26{id}\u5bf9\u5e94\u7684\u5c31\u662f1\u7684\u503c&#xff0c;\u5728\u4e1a\u52a1\u65b9\u6cd5\u4e2d\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528&#064;PathVarable\u6ce8\u89e3\u8fdb\u884c\u5360\u4f4d\u7b26\u7684\u5339\u914d\u83b7\u53d6\u5de5\u4f5c<\/p>\n<\/p>\n<h4>2.9 \u81ea\u5b9a\u4e49\u7c7b\u578b\u8f6c\u6362\u5668<\/h4>\n<ul>\n<li>\n<p>springMVC\u9ed8\u8ba4\u5df2\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5e38\u7528\u7684\u7c7b\u578b\u8f6c\u6362\u5668&#xff0c;\u4f8b\u5982\u5ba2\u6237\u7aef\u63d0\u4ea4\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210int\u578b\u8fdb\u884c\u53c2\u6570\u8bbe\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u4f46\u662f\u4e0d\u662f\u6240\u6709\u7684\u6570\u636e\u7c7b\u578b\u90fd\u63d0\u4f9b\u4e86\u8f6c\u6362\u5668&#xff0c;\u6ca1\u6709\u63d0\u4f9b\u7684\u5c31\u9700\u8981\u81ea\u5b9a\u4e49\u8f6c\u6362\u5668&#xff0c;\u4f8b\u5982&#xff1a;\u65e5\u671f\u7c7b\u578b\u7684\u6570\u636e\u5c31\u9700\u8981\u81ea\u5b9a\u4e49\u8f6c\u6362\u5668\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u81ea\u5b9a\u4e49\u7c7b\u578b\u8f6c\u6362\u5668\u7684\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u5b9a\u4e49\u8f6c\u6362\u5668\u5b9e\u73b0Converter\u63a5\u53e3<\/p>\n<\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u58f0\u660e\u8f6c\u6362\u5668<\/p>\n<\/li>\n<li>\n<p>\u5728&lt; annotation-driven &gt;\u4e2d\u5f15\u7528\u8f6c\u6362\u5668<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u4e49\u8f6c\u6362\u5668\u5b9e\u73b0Converter\u63a5\u53e3<\/p>\n<p> public class DateConverter implements Converter&lt;String,Date&gt; {<\/p>\n<p>    &#064;Override<br \/>\n    public Date convert(String dateStr) {<br \/>\n        \/\/\u5c06\u65e5\u671f\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u771f\u6b63\u7684\u65e5\u671f\u5bf9\u8c61\u8fd4\u56de<br \/>\n        SimpleDateFormat format&#061;new SimpleDateFormat(&#034;yyyy-mm-dd&#034;);<br \/>\n        Date date&#061;null;<br \/>\n        try {<br \/>\n            date &#061; format.parse(dateStr);<br \/>\n        } catch (ParseException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        return date;<br \/>\n    }<br \/>\n} <\/li>\n<li>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u58f0\u660e\u8f6c\u6362\u5668<\/p>\n<p> &lt;!&#8211;    \u58f0\u660e\u8f6c\u6362\u5668&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;ConversionService&#034; class&#061;&#034;org.springframework.context.support.ConversionServiceFactoryBean&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;converters&#034;&gt;<br \/>\n            &lt;list&gt;<br \/>\n                &lt;bean class&#061;&#034;com.itheima.converter.DateConverter&#034;\/&gt;<br \/>\n            &lt;\/list&gt;<br \/>\n        &lt;\/property&gt;<br \/>\n    &lt;\/bean&gt; <\/li>\n<li>\n<p>\u5728&lt; annotation-driven &gt;\u4e2d\u5f15\u7528\u8f6c\u6362\u5668<\/p>\n<p> &lt;!&#8211;    mvc\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;mvc:annotation-driven conversion-service&#061;&#034;ConversionService&#034;\/&gt; <\/li>\n<h4>2.10 \u83b7\u5f97Servlet\u76f8\u5173API<\/h4>\n<p>SpringMVC\u652f\u6301\u4f7f\u7528\u539f\u59cb\u7684ServletAPI\u5bf9\u8c61\u4f5c\u4e3a\u63a7\u5236\u5668\u65b9\u6cd5\u7684\u53c2\u6570\u8fdb\u884c\u6ce8\u5165&#xff0c;\u5e38\u7528\u7684\u5bf9\u8c61\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>HttpServletRequest<\/p>\n<\/li>\n<li>\n<p>HttpServletResponse<\/p>\n<\/li>\n<li>\n<p>HttpSession<\/p>\n<p> &#064;RequestMapping(&#034;\/quick16&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod16(HttpServletRequest request,HttpServletResponse response,HttpSession session){<br \/>\n    System.out.println(request);<br \/>\n    System.out.println(response);<br \/>\n    System.out.println(session);<br \/>\n} <\/li>\n<\/ul>\n<h4>2.11 \u83b7\u5f97\u8bf7\u6c42\u5934<\/h4>\n<h5>1. &#064;RequestHeader<\/h5>\n<p>\u4f7f\u7528&#064;RequestHeader\u53ef\u4ee5\u83b7\u5f97\u8bf7\u6c42\u5934\u4fe1\u606f&#xff0c;\u76f8\u5f53\u4e8eweb\u9636\u6bb5\u5b66\u4e60\u7684request.getHeader(name)<\/p>\n<p>&#064;RequestHeader\u6ce8\u89e3\u7684\u5c5e\u6027\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>value&#xff1a;\u8bf7\u6c42\u5934\u7684\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>required&#xff1a;\u662f\u5426\u5fc5\u987b\u643a\u5e26\u6b64\u8bf7\u6c42\u5934<\/p>\n<p> &#064;RequestMapping(&#034;\/quick19&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod19(&#064;RequestHeader(value &#061; &#034;User-agent&#034;,required &#061; false) String user_agent){<br \/>\n    System.out.println(user_agent);<br \/>\n} <\/p>\n<\/li>\n<\/ul>\n<h5>2. &#064;CookieValue<\/h5>\n<p>\u4f7f\u7528&#064;CookieValue\u53ef\u4ee5\u83b7\u5f97\u6307\u5b9aCookie\u7684\u503c<\/p>\n<p>&#064;CookieValue\u6ce8\u89e3\u7684\u5c5e\u6027\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>value&#xff1a;\u6307\u5b9acookie\u7684\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>required&#xff1a;\u662f\u5426\u5fc5\u987b\u643a\u5e26\u6b64cookie<\/p>\n<p> &#064;RequestMapping(&#034;\/quick20&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod20(&#064;CookieValue(value &#061; &#034;JSESSIONID&#034;) String session_id){<br \/>\n    System.out.println(session_id);<br \/>\n} <\/p>\n<\/li>\n<\/ul>\n<h4>2.12 \u6587\u4ef6\u4e0a\u4f20<\/h4>\n<h5>1.\u6587\u4ef6\u4e0a\u4f20\u5ba2\u6237\u7aef\u4e09\u8981\u7d20<\/h5>\n<ul>\n<li>\n<p>\u8868\u5355\u9879type&#061;\u201cfile\u201c<\/p>\n<\/li>\n<li>\n<p>\u8868\u5355\u7684\u63d0\u4ea4\u65b9\u5f0f\u662fpost<\/p>\n<\/li>\n<li>\n<p>\u8868\u5355\u7684enctype\u5c5e\u6027\u662f\u591a\u90e8\u5206\u8868\u5355\u5f62\u5f0f&#xff0c;\u53caenctype&#061;\u201dmultipart\/form-data\u201c<\/p>\n<p> &lt;form action&#061;&#034;${pageContext.request.contextPath}\/quick22&#034; method&#061;&#034;post&#034; enctype&#061;&#034;multipart\/form-data&#034;&gt;<br \/>\n    \u540d\u79f0&#xff1a;&lt;input type&#061;&#034;text&#034; name&#061;&#034;name&#034;&gt;&lt;br\/&gt;<br \/>\n    \u6587\u4ef6&#xff1a;&lt;input type&#061;&#034;file&#034; name&#061;&#034;upload&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;submit&#034; name&#061;&#034;\u63d0\u4ea4&#034;&gt;<br \/>\n&lt;\/form&gt; <\/li>\n<\/ul>\n<h5>2. \u6587\u4ef6\u4e0a\u4f20\u539f\u7406<\/h5>\n<ul>\n<li>\n<p>\u5f53form\u8868\u5355\u4fee\u6539\u4e3a\u591a\u90e8\u5206\u8868\u5355\u65f6&#xff0c;request.getParameter()\u5c06\u5931\u6548<\/p>\n<\/li>\n<li>\n<p>enctype&#061;&#034;application\/x-www-form-urlencoded&#034;\u65f6&#xff0c;form\u8868\u5355\u7684\u6b63\u6587\u5185\u5bb9\u683c\u5f0f\u662f&#xff1a;<\/p>\n<p>key&#061;value&amp;key&#061;value&amp;key&#061;value<\/p>\n<\/li>\n<li>\n<p>\u5f53form\u8868\u5355\u7684enctype\u53d6\u503c\u4e3aMutilpart\/form-data\u65f6&#xff0c;\u8bf7\u6c42\u6b63\u6587\u5185\u5bb9\u5c31\u53d8\u6210\u591a\u90e8\u5206\u5f62\u5f0f&#xff1a;<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<h4>2.13 \u5355\u6587\u4ef6\u4e0a\u4f20\u6b65\u9aa4<\/h4>\n<li>\n<p>\u5bfc\u5165fileupload\u548cio\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6\u4e0a\u4f20\u89e3\u6790\u5668<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6587\u4ef6\u4e0a\u4f20\u4ee3\u7801<\/p>\n<\/li>\n<h4>2.14 \u5355\u6587\u4ef6\u4e0a\u4f20\u5b9e\u73b0<\/h4>\n<li>\n<p>\u5bfc\u5165fileupload\u548cio\u5750\u6807<\/p>\n<p> &lt;dependency&gt;<br \/>\n    &lt;groupId&gt;commons-fileupload&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;commons-fileupload&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;1.4&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;commons-io&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;commons-io&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;2.5&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/li>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6\u4e0a\u4f20\u89e3\u6790\u5668<\/p>\n<p> &lt;!&#8211;   \u914d\u7f6e\u6587\u4ef6\u4e0a\u4f20\u89e3\u6790\u5668&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;multipartResolver&#034; class&#061;&#034;org.springframework.web.multipart.commons.CommonsMultipartResolver&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;defaultEncoding&#034; value&#061;&#034;UTF-8&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;maxInMemorySize&#034; value&#061;&#034;500000&#034;\/&gt;<br \/>\n    &lt;\/bean&gt; <\/li>\n<li>\n<p>\u7f16\u5199\u6587\u4ef6\u4e0a\u4f20\u4ee3\u7801<\/p>\n<p> &#064;RequestMapping(&#034;\/quick22&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod22(String name, MultipartFile uploadFile){<br \/>\n    System.out.println(name);<br \/>\n    System.out.println(uploadFile);<\/p>\n<p>    \/\/\u83b7\u53d6\u4e0a\u4f20\u6587\u4ef6\u540d\u79f0<br \/>\n        String originalFilename &#061; uploadFile.getOriginalFilename();<br \/>\n        uploadFile.transferTo(new File(&#034;C:\\\\\\\\upload\\\\\\\\&#034;&#043;originalFilename));<br \/>\n} <\/li>\n<h4>2.15 \u591a\u6587\u4ef6\u4e0a\u4f20\u5b9e\u73b0<\/h4>\n<p>\u591a\u6587\u4ef6\u4e0a\u4f20&#xff0c;\u53ea\u9700\u8981\u5c06\u9875\u9762\u4fee\u6539\u4e3a\u591a\u4e2a\u6587\u4ef6\u4e0a\u4f20\u9879&#xff0c;\u5c06\u65b9\u6cd5\u53c2\u6570MultipartFile\u7c7b\u578b\u4fee\u6539\u4e3aMultipartFile[]\u5373\u53ef<\/p>\n<p>&lt;form action&#061;&#034;${pageContext.request.contextPath}\/quick22&#034; method&#061;&#034;post&#034; enctype&#061;&#034;multipart\/form-data&#034;&gt;<br \/>\n    \u540d\u79f0&#xff1a;&lt;input type&#061;&#034;text&#034; name&#061;&#034;name&#034;&gt;&lt;br\/&gt;<br \/>\n    \u6587\u4ef6&#xff1a;&lt;input type&#061;&#034;file&#034; name&#061;&#034;uploadFile&#034;&gt;&lt;br\/&gt;<br \/>\n    \u6587\u4ef6&#xff1a;&lt;input type&#061;&#034;file&#034; name&#061;&#034;uploadFile2&#034;&gt;&lt;br\/&gt;<br \/>\n    &lt;input type&#061;&#034;submit&#034; name&#061;&#034;\u63d0\u4ea4&#034;&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&#064;RequestMapping(&#034;\/quick21&#034;)<br \/>\n&#064;ResponseBody<br \/>\npublic void quickMethod21(String name,MultipartFile[] uploadFiles) throws IOException {<br \/>\n    for (MultipartFile uploadFile : uploadFiles){<br \/>\n        String originalFilename &#061; uploadFile.getOriginalFilename();<br \/>\n        uploadFile.transferTo(new File(&#034;C:\\\\\\\\upload\\\\\\\\&#034;&#043;originalFilename));<br \/>\n    }<br \/>\n} <\/p>\n<h4>2.14 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>MVC\u5b9e\u73b0\u6570\u636e\u8bf7\u6c42\u65b9\u5f0f<\/p>\n<p>\u57fa\u672c\u7c7b\u578b\u53c2\u6570<\/p>\n<p>POJO\u7c7b\u578b\u53c2\u6570<\/p>\n<p>\u6570\u7ec4\u7c7b\u578b\u53c2\u6570<\/p>\n<p>\u96c6\u5408\u7c7b\u578b\u53c2\u6570<\/p>\n<p>MVC\u83b7\u53d6\u6570\u636e\u7ec6\u8282<\/p>\n<p>\u4e2d\u6587\u4e71\u7801\u95ee\u9898<\/p>\n<p>&#064;RequestParam \u548c &#064;PathVariable<\/p>\n<p>\u81ea\u5b9a\u4e49\u7c7b\u578b\u8f6c\u6362\u5668<\/p>\n<p>\u83b7\u5f97Servlet\u76f8\u5173API<\/p>\n<p>&#064;RequestHeader \u548c &#064;CookieValue<\/p>\n<p>\u6587\u4ef6\u4e0a\u4f20<\/p>\n<h3>03-SpringMVC\u62e6\u622a\u5668\u53ca\u5f02\u5e38\u5904\u7406<\/h3>\n<h4>1.1 \u62e6\u622a\u5668&#xff08;innterceptor&#xff09;\u7684\u4f5c\u7528<\/h4>\n<p>SpringMVC\u7684\u62e6\u622a\u5668\u7c7b\u4f3c\u4e8eServlet\u5f00\u53d1\u4e2d\u7684\u8fc7\u6ee4\u5668Filter&#xff0c;\u7528\u4e8e\u5bf9\u5904\u7406\u5668\u8fdb\u884c\u9884\u5904\u7406\u548c\u540e\u5904\u7406\u3002<\/p>\n<p>\u5c06\u62e6\u622a\u5668\u6309\u4e00\u5b9a\u7684\u987a\u5e8f\u8054\u7ed3\u6210\u4e00\u6761\u94fe&#xff0c;\u8fd9\u6761\u94fe\u79f0\u4e3a\u62e6\u622a\u5668\u94fe(Interceptor Chain)\u3002\u5728\u8bbf\u95ee\u88ab\u62e6\u622a\u7684\u65b9\u6cd5\u6216\u5b57\u6bb5\u65f6&#xff0c;\u62e6\u622a\u5668\u94fe\u4e2d\u7684\u62e6\u622a\u5668\u5c31\u4f1a\u6309\u5176\u4e4b\u524d\u5b9a\u4e49\u7684\u987a\u5e8f\u88ab\u8c03\u7528\u3002\u62e6\u622a\u5668\u4e5f\u662fAOP\u601d\u60f3\u7684\u5177\u4f53\u5b9e\u73b0\u3002<\/p>\n<h4>1.2 \u62e6\u622a\u5668\u548c\u8fc7\u6ee4\u5668\u7684\u533a\u522b<\/h4>\n<table>\n<tr>\u533a\u522b\u8fc7\u6ee4\u5668\u62e6\u622a\u5668<\/tr>\n<tbody>\n<tr>\n<td>\u4f7f\u7528\u8303\u56f4<\/td>\n<td>\u662fservlet\u89c4\u8303\u4e2d\u7684\u4e00\u90e8\u5206&#xff0c;\u4efb\u4f55java web\u5de5\u7a0b\u90fd\u53ef\u4ee5\u4f7f\u7528<\/td>\n<td>\u662fSpringMVC\u6846\u67b6\u81ea\u5df1\u7684&#xff0c;\u53ea\u6709\u4f7f\u7528\u4e86SpringMVC\u6846\u67b6\u7684\u5de5\u7a0b\u624d\u80fd\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u62e6\u622a\u8303\u56f4<\/td>\n<td>\u5728url-pattern\u4e2d\u914d\u7f6e\u4e86\/*\u4e4b\u540e&#xff0c;\u53ef\u4ee5\u5bf9\u6240\u6709\u8981\u8bbf\u95ee\u7684\u8d44\u6e90\u62e6\u622a<\/td>\n<td>\u53ea\u4f1a\u62e6\u622a\u8bbf\u95ee\u7684\u63a7\u5236\u5668\u65b9\u6cd5&#xff0c;\u5982\u679c\u8bbf\u95ee\u7684\u662fjsp&#xff0c;html&#xff0c;css&#xff0c;image\u6216\u8005js\u662f\u4e0d\u4f1a\u8fdb\u884c\u62e6\u622a\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.3 \u62e6\u622a\u5668\u7684\u5feb\u901f\u5165\u95e8<\/h4>\n<p>\u81ea\u5b9a\u4e49\u62e6\u622a\u5668\u5f88\u7b80\u5355&#xff0c;\u53ea\u6709\u5982\u4e0b\u4e09\u6b65&#xff1a;<\/p>\n<li>\n<p>\u521b\u5efa\u62e6\u622a\u5668\u7c7b\u5b9e\u73b0HandlerInterceptor\u63a5\u53e3<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u62e6\u622a\u5668<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u62e6\u622a\u5668\u7684\u62e6\u622a\u6548\u679c<\/p>\n<\/li>\n<h5>\u521b\u5efa\u62e6\u622a\u5668\u7c7b\u5b9e\u73b0HandlerInterceptor\u63a5\u53e3<\/h5>\n<p>public class MyInterceptor1 implements HandlerInterceptor {<br \/>\n    \/\/\u5728\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u4e4b\u524d\u6267\u884c<br \/>\n    &#064;Override<br \/>\n    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {<br \/>\n        System.out.println(&#034;preHandle&#034;);<br \/>\n        \/\/\u8fd4\u56defalse\u4ee3\u8868\u4e0d\u653e\u884c(\u540e\u9762\u7684\u65b9\u6cd5\u90fd\u4e0d\u80fd\u6267\u884c) \u8fd4\u56detrue\u5219\u653e\u884c<br \/>\n        return true;<br \/>\n    }<\/p>\n<p>    \/\/\u5728\u76ee\u6807\u65b9\u6cd5\u6267\u884c\u4e4b\u540e\u89c6\u56fe\u8fd4\u56de\u4e4b\u524d\u6267\u884c<br \/>\n    \/\/modelandview\u53ef\u4ee5\u83b7\u53d6 \u8fdb\u884c\u4fee\u6539<br \/>\n    &#064;Override<br \/>\n    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {<br \/>\n        System.out.println(&#034;postHandle&#034;);<br \/>\n    }<\/p>\n<p>    \/\/\u5728\u6d41\u7a0b\u90fd\u6267\u884c\u5b8c\u6bd5\u540e \u6267\u884c<br \/>\n    &#064;Override<br \/>\n    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {<br \/>\n        System.out.println(&#034;afterCompletion&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h5>\u914d\u7f6e\u62e6\u622a\u5668<\/h5>\n<p>&lt;!&#8211;    \u914d\u7f6e\u62e6\u622a\u5668&#8211;&gt;<br \/>\n    &lt;mvc:interceptors&gt;<br \/>\n        &lt;mvc:interceptor&gt;<br \/>\n&lt;!&#8211;            \u5bf9\u54ea\u4e9b\u8d44\u6e90\u6267\u884c\u62e6\u622a\u64cd\u4f5c&#8211;&gt;<br \/>\n            &lt;mvc:mapping path&#061;&#034;\/**&#034;\/&gt;<br \/>\n            &lt;bean class&#061;&#034;com.itheima.interceptor.MyInterceptor1&#034;\/&gt;<br \/>\n        &lt;\/mvc:interceptor&gt;<br \/>\n                &lt;mvc:interceptor&gt;<br \/>\n&lt;!&#8211;            \u5f53\u8981\u52a0\u591a\u4e00\u4e2a\u62e6\u622a\u5668\u65f6&#8211;&gt;<br \/>\n            &lt;mvc:mapping path&#061;&#034;\/xxxx\/**&#034;\/&gt;xxxx\u4e0b\u7684\u5168\u90e8\u65b9\u6cd5<br \/>\n            &lt;bean class&#061;&#034;com.itheima.interceptor.MyInterceptor2&#034;\/&gt;<br \/>\n        &lt;\/mvc:interceptor&gt;<br \/>\n    &lt;\/mvc:interceptors&gt; <\/p>\n<h5>\u6d4b\u8bd5\u62e6\u622a\u5668\u7684\u62e6\u622a\u6548\u679c<\/h5>\n<p>preHandle running&#8230; postHandle afterCompletion<\/p>\n<h4>1.5 \u62e6\u622a\u5668\u65b9\u6cd5\u8bf4\u660e<\/h4>\n<table>\n<tr>\u65b9\u6cd5\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>preHandle()<\/td>\n<td>\u65b9\u6cd5\u5c06\u5728\u8bf7\u6c42\u5904\u7406\u4e4b\u524d\u8fdb\u884c\u8c03\u7528&#xff0c;\u8be5\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u662f\u5e03\u5c14\u503cBoolean\u7c7b\u578b\u7684&#xff0c;\u5f53\u5b83\u8fd4\u56defalse\u65f6&#xff0c;\u8868\u793a\u8bf7\u6c42\u7ed3\u675f&#xff0c;\u540e\u7eed\u7684Intercetor\u548cController\u90fd\u4e0d\u4f1a\u518d\u6267\u884c&#xff1b;\u5f53\u8fd4\u56de\u503ctrue\u65f6\u5c31\u4f1a\u7ee7\u7eed\u8c03\u7528\u4e0b\u4e00\u4e2aInterceptor\u7684preHandle\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>postHandle()<\/td>\n<td>\u8be5\u65b9\u6cd5\u662f\u5f53\u524d\u8bf7\u6c42\u8fdb\u884c\u5904\u7406\u4e4b\u540e\u88ab\u8c03\u7528&#xff0c;\u524d\u63d0\u662fpreHandle\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e3atrue\u65f6\u624d\u80fd\u88ab\u8c03\u7528&#xff0c;\u4e14\u5b83\u4f1a\u5728DispatcherServlet\u8fdb\u884c\u89c6\u56fe\u8fd4\u56de\u6e32\u67d3\u4e4b\u524d\u88ab\u8c03\u7528&#xff0c;\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u5bf9Controller\u5904\u7406\u4e4b\u540e\u7684ModelAndView\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c<\/td>\n<\/tr>\n<tr>\n<td>afterCompletion()<\/td>\n<td>\u8be5\u65b9\u6cd5\u5c06\u5728\u6574\u4e2a\u8bf7\u6c42\u7ed3\u675f\u4e4b\u540e&#xff0c;\u4e5f\u5c31\u662f\u5728DispatcherServlet\u6e32\u67d3\u4e86\u5bf9\u5e94\u7684\u89c6\u56fe\u4e4b\u540e\u6267\u884c&#xff0c;\u524d\u63d0\u662fpreHandle\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e3atrue\u65f6\u624d\u80fd\u88ab\u8c03\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.6 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<p>\u81ea\u5b9a\u4e49\u62e6\u622a\u5668\u6b65\u9aa4<\/p>\n<li>\n<p>\u521b\u5efa\u62e6\u622a\u5668\u7c7b\u5b9e\u73b0HandlerInterceptor\u63a5\u53e3<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u62e6\u622a\u5668<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u62e6\u622a\u5668\u7684\u62e6\u622a\u6548\u679c<\/p>\n<\/li>\n<h4>1.7 \u6848\u4f8b-\u7528\u6237\u767b\u5f55\u6743\u9650\u63a7\u5236<\/h4>\n<p>\u9700\u6c42&#xff1a;\u7528\u6237\u6ca1\u6709\u767b\u5f55\u7684\u60c5\u51b5\u4e0b&#xff0c;\u4e0d\u80fd\u5bf9\u540e\u53f0\u83dc\u5355\u8fdb\u884c\u8bbf\u95ee\u64cd\u4f5c&#xff0c;\u70b9\u51fb\u83dc\u5355\u8df3\u8f6c\u5230\u767b\u5f55\u9875\u9762&#xff0c;\u53ea\u6709\u7528\u6237\u767b\u5f55\u6210\u529f\u540e\u624d\u80fd\u8fdb\u884c\u540e\u53f0\u529f\u80fd\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<h2>08-\u5f02\u5e38\u5904\u7406\u673a\u5236<\/h2>\n<h3>1. SpringMVC\u5f02\u5e38\u5904\u7406<\/h3>\n<h4>1.1 \u5f02\u5e38\u5904\u7406\u7684\u601d\u8def<\/h4>\n<p>\u7cfb\u7edf\u4e2d\u5f02\u5e38\u5305\u62ec\u4e24\u7c7b&#xff1a;\u9884\u671f\u5f02\u5e38\u548c\u8fd0\u884c\u65f6\u5f02\u5e38RuntimeException&#xff0c;\u524d\u8005\u901a\u8fc7\u6355\u83b7\u5f02\u5e38\u4ece\u800c\u83b7\u53d6\u5f02\u5e38\u4fe1\u606f&#xff0c;\u540e\u8005\u4e3b\u8981\u901a\u8fc7\u89c4\u8303\u4ee3\u7801\u5f00\u53d1\u3001\u6d4b\u8bd5\u7b49\u624b\u6bb5\u51cf\u5c11\u8fd0\u884c\u65f6\u5f02\u5e38\u7684\u53d1\u751f\u3002<\/p>\n<p>\u7cfb\u7edf\u7684Dao\u3001Service\u3001Controller\u51fa\u73b0\u90fd\u901a\u8fc7throws Exception\u5411\u4e0a\u629b\u51fa&#xff0c;\u6700\u540e\u7531SpringMVC\u524d\u7aef\u63a7\u5236\u5668\u4ea4\u7531\u5f02\u5e38\u5904\u7406\u5668\u8fdb\u884c\u5f02\u5e38\u5904\u7406&#xff0c;\u5982\u4e0b\u56fe&#xff1a;<\/p>\n<\/p>\n<h4>1.2 \u5f02\u5e38\u5904\u7406\u4e24\u79cd\u65b9\u5f0f<\/h4>\n<li>\n<p>\u4f7f\u7528SpringMVC\u63d0\u4f9b\u7684\u7b80\u5355\u5f02\u5e38\u5904\u7406\u5668SimpleMappingExceptionResover<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0Spring\u7684\u5f02\u5e38\u5904\u7406\u63a5\u53e3HandlerExceptionResover\u81ea\u5b9a\u4e49\u81ea\u5df1\u7684\u5f02\u5e38\u5904\u7406\u5668<\/p>\n<\/li>\n<h4>1.3 \u7b80\u5355\u5f02\u5e38\u5904\u7406\u5668SimpleMappingExceptionResover<\/h4>\n<\/p>\n<li>\n<p>\u505a\u597d\u524d\u671f\u5de5\u4f5c&#xff0c;\u5efa\u7acb\u9879\u76ee\u6dfb\u52a0web&#xff0c;\u5efa\u597d\u4e09\u5c42\u5efa\u6784&#xff0c;\u914d\u7f6epom\u5e76\u6253\u5305\u65b9\u5f0f\u4e3awar<\/p>\n<\/li>\n<li>\n<p>applicationContext.xml<\/p>\n<p> &lt;context:component-scan base-package&#061;&#034;com.itheima&#034;\/&gt; <\/li>\n<li>\n<p>spring-mvc.xml<\/p>\n<p> &lt;!&#8211;    \u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.itheima.controller&#034;\/&gt;<br \/>\n&lt;!&#8211;mvc\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;mvc:annotation-driven\/&gt;<br \/>\n&lt;!&#8211;    \u914d\u7f6e\u89c6\u56fe\u89e3\u6790\u5668&#8211;&gt;<br \/>\n    &lt;bean class&#061;&#034;org.springframework.web.servlet.view.InternalResourceViewResolver&#034;&gt;<br \/>\n        &lt;property name&#061;&#034;prefix&#034; value&#061;&#034;\/&#034;\/&gt;<br \/>\n        &lt;property name&#061;&#034;suffix&#034; value&#061;&#034;.jsp&#034;\/&gt;<br \/>\n    &lt;\/bean&gt;<br \/>\n&lt;!&#8211;    \u9759\u6001\u8d44\u6e90\u6743\u9650\u5f00\u653e&#8211;&gt;<br \/>\n    &lt;mvc:default-servlet-handler\/&gt;<br \/>\n&lt;!&#8211;    \u914d\u7f6e\u5f02\u5e38\u5904\u7406\u5668&#8211;&gt;<br \/>\n    &lt;bean class&#061;&#034;org.springframework.web.servlet.handler.SimpleMappingExceptionResolver&#034;&gt;<br \/>\n&lt;!&#8211;        &lt;property name&#061;&#034;defaultErrorView&#034; value&#061;&#034;error&#034;\/&gt;  \u62a5\u9519\u8df3\u5230\u9ed8\u8ba4\u9519\u8bef\u9875\u9762&#8211;&gt;<br \/>\n        &lt;property name&#061;&#034;exceptionMappings&#034;&gt;<br \/>\n            &lt;map&gt;<br \/>\n                &lt;entry key&#061;&#034;java.lang.ClassCastException&#034; value&#061;&#034;error1&#034;\/&gt;<br \/>\n                &lt;entry key&#061;&#034;com.itheima.exception.MyException&#034; value&#061;&#034;error5&#034;\/&gt;<br \/>\n            &lt;\/map&gt;<br \/>\n        &lt;\/property&gt;<br \/>\n    &lt;\/bean&gt; <\/li>\n<li>\n<p>web.xml<\/p>\n<p> &lt;listener&gt;<br \/>\n        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;\/listener-class&gt;<br \/>\n    &lt;\/listener&gt;<br \/>\n    &lt;context-param&gt;<br \/>\n        &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n        &lt;param-value&gt;classpath:applicationContext.xml&lt;\/param-value&gt;<br \/>\n    &lt;\/context-param&gt;<br \/>\n&lt;!&#8211;    \u524d\u7aef\u63a7\u5236\u5668&#8211;&gt;<br \/>\n    &lt;servlet&gt;<br \/>\n        &lt;servlet-name&gt;DispatcherServlet&lt;\/servlet-name&gt;<br \/>\n        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;classpath:spring-mvc.xml&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n        &lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;<br \/>\n    &lt;\/servlet&gt;<br \/>\n    &lt;servlet-mapping&gt;<br \/>\n        &lt;servlet-name&gt;DispatcherServlet&lt;\/servlet-name&gt;<br \/>\n        &lt;url-pattern&gt;\/&lt;\/url-pattern&gt;<br \/>\n    &lt;\/servlet-mapping&gt;<\/p>\n<p>    &lt;!&#8211;    \u914d\u7f6e\u5168\u5c40\u8fc7\u6ee4\u7684filter&#8211;&gt;<br \/>\n    &lt;filter&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;\/filter-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;encoding&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;UTF-8&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n    &lt;\/filter&gt;<br \/>\n    &lt;filter-mapping&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<br \/>\n    &lt;\/filter-mapping&gt; <\/li>\n<li> &#064;Service<br \/>\npublic class DemoServiceImpl implements DemoService{<br \/>\n    &#064;Override<br \/>\n    public void show1() {<br \/>\n        System.out.println(&#034;\u629b\u51fa\u7c7b\u578b\u8f6c\u6362\u5f02\u5e38&#8230;&#034;);<br \/>\n        Object str&#061;&#034;shanghai&#034;;<br \/>\n        Integer num&#061;(Integer)str;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void show2() {<br \/>\n        System.out.println(&#034;\u629b\u51fa\u96f6\u5f02\u5e38&#8230;&#034;);<br \/>\n        int i&#061;1\/0;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void show3() throws FileNotFoundException {<br \/>\n        System.out.println(&#034;\u6587\u4ef6\u627e\u4e0d\u5230\u5f02\u5e38&#8230;&#034;);<br \/>\n        InputStream in&#061;new FileInputStream(&#034;C:\/xxx\/xxx&#034;);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void show4() {<br \/>\n        System.out.println(&#034;\u7a7a\u6307\u9488\u5f02\u5e38&#8230;&#034;);<br \/>\n        String str&#061;null;<br \/>\n        str.length();<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void show5() throws MyException {<br \/>\n        System.out.println(&#034;\u81ea\u5b9a\u4e49\u5f02\u5e38&#8230;&#034;);<br \/>\n        throw new MyException();<br \/>\n    }<br \/>\n} public class MyException extends Exception{<br \/>\n} &#064;Controller<br \/>\npublic class DemoController {<br \/>\n    &#064;Autowired<br \/>\n    private DemoService demoService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/show&#034;)<br \/>\n    public String show() throws MyException {<br \/>\n        System.out.println(&#034;show running&#8230;&#034;);<br \/>\n        demoService.show5();<br \/>\n        return &#034;index&#034;;<br \/>\n    }<br \/>\n} <\/li>\n<h4>1.4 \u5f02\u5e38\u5904\u7406\u6b65\u9aa4<\/h4>\n<li>\n<p>\u521b\u5efa\u5f02\u5e38\u5904\u7406\u5668\u7c7b\u5b9e\u73b0HandlerExceptionResolver<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u5f02\u5e38\u5904\u7406\u5668<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u5f02\u5e38\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u5f02\u5e38\u8df3\u8f6c<\/p>\n<\/li>\n<ul>\n<li>\n<h5>\u521b\u5efa\u5f02\u5e38\u5904\u7406\u5668\u7c7b\u5b9e\u73b0HandlerExceptionResolver<\/h5>\n<p> public class MyExceptionResolver implements HandlerExceptionResolver {<br \/>\n \u00a0 \u00a0&#064;Override<br \/>\n \u00a0 \u00a0\/*<br \/>\n \u00a0 \u00a0* \u53c2\u6570Exception:\u5f02\u5e38\u5bf9\u8c61<br \/>\n \u00a0 \u00a0* \u8fd4\u56de\u503cModelandView&#xff1a;\u8df3\u8f6c\u5230\u9519\u8bef\u89c6\u56fe\u4fe1\u606f<br \/>\n \u00a0 \u00a0*<br \/>\n \u00a0 \u00a0* *\/<br \/>\n \u00a0 \u00a0public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0ModelAndView modelAndView&#061;new ModelAndView();<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0if(e instanceof MyException){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0modelAndView.addObject(&#034;info&#034;,&#034;\u81ea\u5b9a\u4e49\u5f02\u5e38&#034;);<br \/>\n \u00a0 \u00a0 \u00a0  }else if(e instanceof ClassCastException){<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0modelAndView.addObject(&#034;info&#034;,&#034;\u7c7b\u578b\u8f6c\u6362\u5f02\u5e38&#034;);<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n\u200b<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0modelAndView.setViewName(&#034;error&#034;);<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return modelAndView;<br \/>\n \u00a0  }<br \/>\n} <\/li>\n<li>\n<h5>\u914d\u7f6e\u5f02\u5e38\u5904\u7406\u5668<\/h5>\n<p> &lt;!&#8211; \u00a0  \u81ea\u5b9a\u4e49\u5f02\u5e38\u5904\u7406\u5668&#8211;&gt;<br \/>\n&lt;bean class&#061;&#034;com.itheima.resolver.MyExceptionResolver&#034;\/&gt; <\/li>\n<li>\n<h5>\u7f16\u5199\u5f02\u5e38\u9875\u9762<\/h5>\n<p> &lt;h1&gt;<br \/>\n    ${info}<br \/>\n&lt;\/h1&gt; <\/li>\n<li>\n<h5>\u6d4b\u8bd5\u5f02\u5e38\u8df3\u8f6c<\/h5>\n<p> &#064;Controller<br \/>\npublic class DemoController {<br \/>\n    &#064;Autowired<br \/>\n    private DemoService demoService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/show&#034;)<br \/>\n    public String show() throws MyException {<br \/>\n        System.out.println(&#034;show running&#8230;&#034;);<br \/>\n        demoService.show5();<br \/>\n        return &#034;index&#034;;<br \/>\n    }<br \/>\n} <\/li>\n<\/ul>\n<h4>1.4 \u77e5\u8bc6\u8981\u70b9<\/h4>\n<h5>\u5f02\u5e38\u5904\u7406\u65b9\u5f0f<\/h5>\n<li>\n<p>\u914d\u7f6e\u7b80\u5355\u5f02\u5e38\u5904\u7406\u5668SimpleMappingExceptionResovler<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u5f02\u5e38\u5904\u7406\u5668<\/p>\n<\/li>\n<h5>\u5f02\u5e38\u5904\u7406\u6b65\u9aa4<\/h5>\n<li>\n<p>\u521b\u5efa\u5f02\u5e38\u5904\u7406\u7c7b\u5b9e\u73b0HandlerExceptionResolver<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u5f02\u5e38\u5904\u7406\u5668<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u5f02\u5e38\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u5f02\u5e38\u8df3\u8f6c<\/p>\n<\/li>\n<h2>3-3 Spring&#043;SpringMVC\u7efc\u5408\u7ec3\u4e60<\/h2>\n<h2>Spring\u7ec3\u4e60<\/h2>\n<h3>1. Spring\u7ec3\u4e60\u73af\u5883\u642d\u5efa<\/h3>\n<h4>1.1 Spring\u73af\u5883\u642d\u5efa\u6b65\u9aa4<\/h4>\n<li>\n<p>\u521b\u5efa\u5de5\u7a0b(Project&amp;Module)<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u9759\u6001\u9875\u9762(\u89c1\u8d44\u6599jsp\u9875\u9762)<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u9700\u8981\u5750\u6807(\u89c1\u8d44\u6599\u4e2d\u7684pomxml)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u5305\u7ed3\u6784(controller\u3001service\u3001dao\u3001domain\u3001utils)<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u6570\u636e\u5e93\u811a\u672c(\u89c1\u8d44\u6599test.sql)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaPOJO\u7c7b(\u89c1\u8d44\u6599User.java\u548cRole.java)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6(applicationContext.xml\u3001spring-mvc.xml\u3001jbdc.properties\u3001log4j.properties)<\/p>\n<p>applicationContext\u52a0\u8f7djbdc.properties\u3001\u4e66\u5199\u6570\u636e\u6e90\u3001\u6570\u636e\u5e93\u6a21\u677f\u5bf9\u8c61<\/p>\n<p>spring-mvc\u6ce8\u89e3\u9a71\u52a8\u3001\u9759\u6001\u8d44\u6e90\u6743\u9650\u5f00\u653e\u3001\u89c6\u56fe\u89e3\u6790\u5668<\/p>\n<p>web.xml\u4e5f\u8981\u914d\u7f6e\u524d\u7aef\u63a7\u5236\u5668\u548cspring\u7684\u76d1\u542c\u5668ContextLoaderListener<\/p>\n<\/li>\n<h4>1.2 \u7528\u6237\u548c\u89d2\u8272\u7684\u5173\u7cfb<\/h4>\n<\/p>\n<p>\u4e00\u4e2a\u7528\u6237\u53ef\u4ee5\u62e5\u6709\u591a\u4e2a\u89d2\u8272&#xff0c;\u4e00\u4e2a\u89d2\u8272\u53ef\u4ee5\u6709\u591a\u4e2a\u7528\u6237&#xff0c;\u662f\u591a\u5bf9\u591a\u7684\u5173\u7cfb<\/p>\n<h4>2.1 \u89d2\u8272\u5217\u8868\u7684\u5c55\u793a\u6548\u679c<\/h4>\n<\/p>\n<h4>2.2 \u89d2\u8272\u5217\u8868\u7684\u5c55\u793a\u6b65\u9aa4\u5206\u6790<\/h4>\n<li>\n<p>\u70b9\u51fb\u89d2\u8272\u7ba1\u7406\u83dc\u5355\u53d1\u9001\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u7aef(\u4fee\u6539\u89d2\u8272\u7ba1\u7406\u83dc\u5355\u7684url\u5730\u5740)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleController\u548cshowList()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleService\u548cshowList()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleDao\u65b9\u6cd5\u548cfindAll()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u5c06\u67e5\u8be2\u6570\u636e\u5b58\u50a8\u5230Model\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u8f6c\u53d1\u5230role-list.jsp\u9875\u9762\u8fdb\u884c\u5c55\u793a<\/p>\n<\/li>\n<h4>2.3 \u89d2\u8272\u6dfb\u52a0\u7684\u6548\u679c<\/h4>\n<\/p>\n<h4>2.4 \u89d2\u8272\u6dfb\u52a0\u7684\u6b65\u9aa4\u5206\u6790<\/h4>\n<li>\n<p>\u70b9\u51fb\u5217\u8868\u9875\u9762\u65b0\u5efa\u6309\u94ae\u8df3\u8f6c\u5230\u89d2\u8272\u6dfb\u52a0\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>\u8f93\u5165\u89d2\u8272\u4fe1\u606f&#xff0c;\u70b9\u51fb\u4fdd\u5b58\u6309\u94ae&#xff0c;\u8868\u5355\u6570\u636e\u63d0\u4ea4\u670d\u52a1\u5668<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199RoleController\u7684save()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Roleservice\u7684save()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199RoleDao\u7684save()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528jdbcTemplate\u4fdd\u5b58Role\u6570\u636e\u5230sys_role<\/p>\n<\/li>\n<li>\n<p>\u8df3\u8f6c\u56de\u89d2\u8272\u5217\u8868\u9875\u9762<\/p>\n<\/li>\n<p>&#064;Override<br \/>\npublic Long save(User user) {<br \/>\n    \/\/jdbcTemplate.update(&#034;insert into sys_user values (?,?,?,?,?)&#034;,null,user.getUsername(),user.getEmail(),user.getPassword(),user.getPhoneNum());<\/p>\n<p>    \/\/\u521b\u5efaPreparedStatementCreator<br \/>\n    PreparedStatementCreator creator&#061;new PreparedStatementCreator() {<br \/>\n        &#064;Override<br \/>\n        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {<br \/>\n            \/\/\u4f7f\u7528\u539f\u59cbjdbc\u5b8c\u6210\u6709\u4e2aPreparedStatement\u7684\u7ec4\u5efa<br \/>\n            PreparedStatement preparedStatement &#061; connection.prepareStatement(&#034;insert into sys_user values (?,?,?,?,?)&#034;, PreparedStatement.RETURN_GENERATED_KEYS);<br \/>\n            preparedStatement.setObject(1,null);<br \/>\n            preparedStatement.setString(2,user.getUsername());<br \/>\n            preparedStatement.setString(3,user.getEmail());<br \/>\n            preparedStatement.setString(4,user.getPassword());<br \/>\n            preparedStatement.setString(5,user.getPhoneNum());<br \/>\n            return preparedStatement;<br \/>\n        }<br \/>\n    };<\/p>\n<p>    \/\/\u521b\u5efakeyHolder<br \/>\n    GeneratedKeyHolder keyHolder&#061;new GeneratedKeyHolder();<br \/>\n    jdbcTemplate.update(creator,keyHolder);<br \/>\n    long userId &#061; keyHolder.getKey().longValue();<\/p>\n<p>    return userId;\/\/\u8fd4\u56de\u5f53\u524d\u4fdd\u5b58\u7528\u6237\u7684id \u8be5id\u662f\u6570\u636e\u5e93\u81ea\u52a8\u751f\u6210\u7684<br \/>\n} <\/p>\n<h4>3.1 \u7528\u6237\u5217\u8868\u7684\u5c55\u793a\u6548\u679c<\/h4>\n<\/p>\n<h4>3.2 \u7528\u6237\u5217\u8868\u7684\u5c55\u793a\u6b65\u9aa4\u5206\u6790<\/h4>\n<li>\n<p>\u70b9\u51fb\u7528\u6237\u7ba1\u7406\u83dc\u5355\u53d1\u9001\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u7aef(\u4fee\u6539\u7528\u6237\u7ba1\u7406\u83dc\u5355\u7684url\u5730\u5740)<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleController\u548cshowList()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleService\u548cshowList()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaRoleDao\u548cfindAll()\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528JdbcTemplate\u5b8c\u6210\u67e5\u8be2\u64cd\u4f5c<\/p>\n<\/li>\n<li>\n<p>\u5c06\u67e5\u8be2\u6570\u636e\u5b58\u50a8\u5230Model\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u8f6c\u53d1\u5230user-list.jsp\u9875\u9762\u8fdb\u884c\u5c55\u793a<\/p>\n<\/li>\n<h4>3.3 \u7528\u6237\u6dfb\u52a0\u7684\u6548\u679c<\/h4>\n<\/p>\n<h4>3.4 \u7528\u6237\u6dfb\u52a0\u7684\u6b65\u9aa4\u5206\u6790<\/h4>\n<p>\u2460\u70b9\u51fb\u5217\u8868\u9875\u9762\u65b0\u5efa\u6309\u94ae\u8df3\u8f6c\u5230\u89d2\u8272\u6dfb\u52a0\u9875\u9762<\/p>\n<p>\u2461\u8f93\u5165\u89d2\u8272\u4fe1\u606f&#xff0c;\u70b9\u51fb\u4fdd\u5b58\u6309\u94ae&#xff0c;\u8868\u5355\u6570\u636e\u63d0\u4ea4\u670d\u52a1\u5668<\/p>\n<p>\u2462\u7f16\u5199RoleController\u7684save()\u65b9\u6cd5<\/p>\n<p>\u2463\u7f16\u5199RoleService\u7684save()\u65b9\u6cd5<\/p>\n<p>\u2464\u7f16\u5199RoleDao\u7684save()\u65b9\u6cd5<\/p>\n<p>\u2465\u4f7f\u7528JdbcTemplate\u4fdd\u5b58Role\u6570\u636e\u5230sys_role<\/p>\n<p>\u2466\u8df3\u8f6c\u56de\u89d2\u8272\u5217\u8868\u9875\u9762<\/p>\n<h4>4.1 \u5220\u9664\u7528\u6237\u7684\u6548\u679c<\/h4>\n<\/p>\n<p>&lt;script&gt;<br \/>\n   function delUser(userId) {<br \/>\n      if (confirm(&#034;\u60a8\u786e\u8ba4\u8981\u5220\u9664\u5417&#034;)){<br \/>\n         location.href&#061;&#034;${pageContext.request.contextPath}\/user\/del\/&#034;&#043;userId;<br \/>\n      }<br \/>\n   }<br \/>\n&lt;\/script&gt; <\/p>\n<p>onclick<\/p>\n<p>&lt;td class&#061;&#034;text-center&#034;&gt;<br \/>\n   &lt;a href&#061;&#034;javascript:void(0);&#034; onclick&#061;&#034;delUser(&#039;${user.id}&#039;)&#034; class&#061;&#034;btn bg-olive btn-xs&#034;&gt;\u5220\u9664&lt;\/a&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&#064;RequestMapping(&#034;\/del\/{userId}&#034;)<br \/>\npublic String del(&#064;PathVariable(&#034;userId&#034;) Long userId){<br \/>\n    userService.del(userId);<br \/>\n    return &#034;redirect:\/user\/list&#034;;<br \/>\n} <\/p>\n<h2>3-4 MyBatis<\/h2>\n<h2>01-Mybatis\u5feb\u901f\u5165\u95e8<\/h2>\n<h3>1. Mybatis\u7b80\u4ecb<\/h3>\n<h4>1.1\u539f\u59cbjdbc\u64cd\u4f5c(\u67e5\u8be2\u6570\u636e)<\/h4>\n<p>\/\/\u6ce8\u518c\u9a71\u52a8<br \/>\nClass.forName(&#034;com.mysql.jdbc.Driver&#034;);<br \/>\n\/\/\u83b7\u5f97\u8fde\u63a5<br \/>\nConnection connection&#061;DriverManager.getConnection(url,user,password);<br \/>\n\/\/\u83b7\u5f97satement<br \/>\nPreparedStatement statement&#061;connection.prepareStatement(sql);<br \/>\n\/\/\u6267\u884c\u67e5\u8be2<br \/>\nResultSet resultSet&#061;statement.executeQuery();<br \/>\n\/\/\u904d\u5386\u7ed3\u679c\u96c6<br \/>\nwhile(resultSet.next()){<br \/>\n    \/\/\u5c01\u88c5\u5b9e\u4f53<br \/>\n    User user&#061;new User();<br \/>\n    user.setId(resultSet.getInt(&#034;id&#034;));<br \/>\n    user.setUserName(resultSet.getString(&#034;userName&#034;));<br \/>\n    user.setPassword(resultSet.getString(&#034;password&#034;));<br \/>\n    \/\/user\u5b9e\u4f53\u5c01\u88c5\u5b8c\u6bd5<br \/>\n    sout(user);<br \/>\n}<br \/>\nresultSet.close();<br \/>\nstatement.close();<br \/>\nconnection.close(); <\/p>\n<h4>1.1 \u539f\u59cbjdbc\u64cd\u4f5c(\u63d2\u5165\u6570\u636e)<\/h4>\n<p>\/\/\u6a21\u62df\u5b9e\u4f53\u5bf9\u8c61<br \/>\nUser user&#061;new User();<br \/>\nuser.setId(2);<br \/>\nuser.setUserName(&#034;tom&#034;);<br \/>\nuser.setPassword(&#034;lucy&#034;);<\/p>\n<p>\/\/\u6ce8\u518c\u9a71\u52a8<br \/>\nClass.forName(&#034;com.mysql.jdbc.Driver&#034;);<br \/>\n\/\/\u83b7\u5f97\u8fde\u63a5<br \/>\nConnection connection&#061;DriverManager.getConnection(url,user,password);<br \/>\n\/\/\u83b7\u5f97statement<br \/>\nPreparedStatement statement&#061;connection.preparedStatement(sql(?,?&#8230;));<br \/>\n\/\/\u8bbe\u7f6e\u5360\u4f4d\u7b26\u53c2\u6570(?)<br \/>\nstatement.setInt(1,user.getId());<br \/>\nstatement.setString(2,user.getUserName());<br \/>\nstatement.setString(3,user.getPassword());<br \/>\n\/\/\u6267\u884c\u66f4\u65b0\u64cd\u4f5c<br \/>\nstatement.executeUpdate();<br \/>\n\/\/\u91ca\u653e\u8d44\u6e90<br \/>\nstatement.close();<br \/>\nconnection.close(); <\/p>\n<h4>1.2 \u539f\u59cbjdbc\u64cd\u4f5c\u7684\u5206\u6790<\/h4>\n<p>\u539f\u59cbjdbc\u5f00\u53d1\u5b58\u5728\u7684\u95ee\u9898\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u6570\u636e\u5e93\u8fde\u63a5\u521b\u5efa\u3001\u91ca\u653e\u9891\u7e41\u9020\u6210\u7cfb\u7edf\u8d44\u6e90\u6d6a\u8d39\u4ece\u800c\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd<\/p>\n<\/li>\n<li>\n<p>sql\u8bed\u53e5\u5728\u4ee3\u7801\u4e2d\u786c\u4ee3\u7801&#xff0c;\u9020\u6210\u4ee3\u7801\u4e0d\u6613\u7ef4\u62a4&#xff0c;\u5b9e\u9645\u5e94\u7528sql\u53d8\u5316\u53ef\u80fd\u8f83\u5927&#xff0c;sql\u53d8\u52a8\u9700\u8981\u6539\u53d8Java\u4ee3\u7801(java\u8026\u5408\u8fc7\u5ea6 \u4ee3\u7801\u91cd\u590d\u591a \u4e0d\u591f\u7075\u6d3b)<\/p>\n<\/li>\n<li>\n<p>\u67e5\u8be2\u64cd\u4f5c&#xff0c;\u9700\u8981\u624b\u52a8\u5c06\u7ed3\u679c\u96c6\u4e2d\u7684\u6570\u636e\u624b\u52a8\u5c01\u88c5\u5230\u5b9e\u4f53\u4e2d&#xff0c;\u63d2\u5165\u64cd\u4f5c\u65f6&#xff0c;\u9700\u8981\u624b\u52a8\u5c06\u5b9e\u4f53\u7684\u6570\u636e\u8bbe\u7f6e\u5230sql\u8bed\u53e5\u7684\u5360\u4f4d\u7b26\u4f4d\u7f6e<\/p>\n<\/li>\n<p>\u5e94\u5bf9\u4e0a\u8ff0\u95ee\u9898\u7ed9\u51fa\u7684\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\n<p>\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u521d\u59cb\u5316\u8fde\u63a5\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>\u5c06sql\u8bed\u53e5\u62bd\u53d6\u5230xml\u914d\u7f6e\u6587\u4ef6\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u53cd\u5c04\u3001\u5185\u7701\u7b49\u5e95\u5c42\u6280\u672f&#xff0c;\u81ea\u52a8\u5c06\u5b9e\u4f53\u4e0e\u8868\u8fdb\u884c\u5c5e\u6027\u4e0e\u5b57\u6bb5\u7684\u81ea\u52a8\u6620\u5c04<\/p>\n<\/li>\n<h4>1.3 \u4ec0\u4e48\u662fMybatis<\/h4>\n<li>\n<p>mybatis\u662f\u4e00\u4e2a\u4f18\u79c0\u7684\u57fa\u4e8ejava\u7684\u6301\u4e45\u5c42\u6846\u67b6&#xff0c;\u5b83\u5185\u90e8\u5c01\u88c5\u4e86jdbc&#xff0c;\u4f7f\u5f00\u53d1\u8005\u53ea\u9700\u8981\u5173\u6ce8sql\u8bed\u53e5\u672c\u8eab&#xff0c;\u800c\u4e0d\u9700\u8981\u82b1\u8d39\u7cbe\u529b\u53bb\u5904\u7406\u52a0\u8f7d\u9a71\u52a8\u3001\u521b\u5efa\u8fde\u63a5\u3001\u521b\u5efastatement\u7b49\u7e41\u6742\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>mybatis\u901a\u8fc7xml\u6216\u6ce8\u89e3\u7684\u65b9\u5f0f\u5c06\u8981\u6267\u884c\u7684\u5404\u79cdstatement\u914d\u7f6e\u8d77\u6765&#xff0c;\u5e76\u901a\u8fc7java\u5bf9\u8c61\u548cstatement\u4e2dsql\u7684\u52a8\u6001\u53c2\u6570\u8fdb\u884c\u6620\u5c04\u751f\u6210\u6700\u7ec8\u6267\u884c\u7684sql<\/p>\n<\/li>\n<li>\n<p>\u6700\u540emybatis\u6846\u67b6\u6267\u884csql\u5e76\u5c06\u7ed3\u679c\u6620\u5c04\u4e3aJava\u5bf9\u8c61\u5e76\u8fd4\u56de\u3002\u91c7\u7528ORM\u601d\u60f3\u89e3\u51b3\u4e86\u5b9e\u4f53\u548c\u6570\u636e\u5e93\u6620\u5c04\u7684\u95ee\u9898&#xff0c;\u5bf9jdbc\u8fdb\u884c\u4e86\u5c01\u88c5&#xff0c;\u5c4f\u853d\u4e86jdbc api\u5e95\u5c42\u8bbf\u95ee\u7ec6\u8282&#xff0c;\u4f7f\u6211\u4eec\u4e0d\u7528\u4e0ejdbc api\u6253\u4ea4\u9053&#xff0c;\u5c31\u53ef\u4ee5\u5b8c\u6210\u5bf9\u6570\u636e\u5e93\u7684\u6301\u4e45\u5316\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<h5>\u91cd\u70b9&#xff1a;<\/h5>\n<li>\n<p>mybatis\u662f\u4e00\u4e2a\u4f18\u79c0\u7684\u57fa\u4e8ejava\u7684\u6301\u4e45\u5c42\u6846\u67b6<\/p>\n<\/li>\n<li>\n<p>mybatis\u53ef\u4ee5\u9690\u85cf\u7e41\u6742\u7684api<\/p>\n<\/li>\n<li>\n<p>\u6211\u4eec\u53ea\u9700\u8981\u5173\u6ce8\u6211\u4eec\u7684sql\u8bed\u53e5&#xff0c;\u4e0d\u9700\u8981\u5173\u6ce8\u52a0\u8f7d\u9a71\u52a8\u3001\u521b\u5efa\u8fde\u63a5\u3001\u521b\u5efastatement\u7b49\u7e41\u6742\u7684\u8fc7\u7a0b<\/p>\n<\/li>\n<li>\n<p>mybatais\u53ef\u4ee5\u5b8c\u6210\u5b9e\u4f53\u5bf9\u8c61\u4e0e\u6570\u636e\u5e93\u6620\u5c04\u5173\u7cfb<\/p>\n<\/li>\n<h3>2. Mybatis\u7684\u5feb\u901f\u5165\u95e8<\/h3>\n<h4>2.1 Mybatis\u5f00\u53d1\u6b65\u9aa4<\/h4>\n<p>Mybatis\u5b98\u7f51\u5730\u5740&#xff1a;MyBatis 3 | Introduction \u2013 mybatis<\/p>\n<\/p>\n<p>Mybatis\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u6dfb\u52a0Mybatis\u7684\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efauser\u6570\u636e\u8868<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199User\u5b9e\u4f53\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6620\u5c04\u6587\u4ef6UserMapper.xml<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6838\u5fc3\u6587\u4ef6SqlMapConfig.xml<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6d4b\u8bd5\u7c7b<\/p>\n<\/li>\n<h4>2.2 \u73af\u5883\u642d\u5efa<\/h4>\n<li>\n<p>\u5bfc\u5165Mybatis\u7684\u5750\u6807\u548c\u5176\u4ed6\u76f8\u5173\u5750\u6807<\/p>\n<p> &lt;dependencies&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;mysql&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;8.0.22&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.mybatis&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;mybatis&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;3.5.6&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;junit&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;4.13.1&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;log4j&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;log4j&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.2.17&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n    &lt;\/dependencies&gt;<br \/>\n    &lt;properties&gt;<br \/>\n        &lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;<br \/>\n    &lt;\/properties&gt; <\/li>\n<li>\n<p>\u521b\u5efauser\u6570\u636e\u8868\u548c\u7f16\u5199User\u5b9e\u4f53<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199UserMapper\u6620\u5c04\u6587\u4ef6&#xff08;\u5728resources.com.itheima.mapper\u76ee\u5f55\u4e0b&#xff09;<\/p>\n<p> &lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034; ?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034; &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt;<br \/>\n&lt;!&#8211;namespace\u662f\u4e3a\u4e86\u5206\u8fa8\u51fa\u54ea\u4e9b\u529f\u80fd\u53d6\u540d resultType \u8fd4\u56de\u7684\u7ed3\u679c\u662f\u4ec0\u4e48\u7c7b\u578b\u8fdb\u884c\u58f0\u660e&#8211;&gt;<br \/>\n&lt;mapper  namespace&#061;&#034;userMapper&#034;&gt;<br \/>\n    &lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n        select * from user;<br \/>\n    &lt;\/select&gt;<br \/>\n&lt;\/mapper&gt; <\/li>\n<li>\n<p>\u7f16\u5199sqlMapConfig.xml(\u5728resource\u76ee\u5f55\u4e0b)<\/p>\n<p> &lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034; ?&gt;<br \/>\n&lt;!DOCTYPE configuration PUBLIC &#034;-\/\/mybatis.org\/\/DTD Config 3.0\/\/EN&#034; &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-config.dtd&#034;&gt;<br \/>\n&lt;configuration&gt;<br \/>\n&lt;!&#8211;    \u6570\u636e\u6e90\u73af\u5883&#8211;&gt;<br \/>\n    &lt;environments default&#061;&#034;development&#034;&gt;<br \/>\n        &lt;environment id&#061;&#034;development&#034;&gt;<br \/>\n            &lt;transactionManager type&#061;&#034;JDBC&#034;&gt;&lt;\/transactionManager&gt;<br \/>\n            &lt;dataSource type&#061;&#034;POOLED&#034;&gt;<br \/>\n                &lt;property name&#061;&#034;driver&#034; value&#061;&#034;com.mysql.cj.jdbc.Driver&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;url&#034; value&#061;&#034;jdbc:mysql:\/\/localhost:3306\/test?useUnicode&#061;true&amp;amp;characterEncoding&#061;utf-8&amp;amp;serverTimezone&#061;UTC&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;username&#034; value&#061;&#034;root&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;password&#034; value&#061;&#034;admin&#034;\/&gt;<br \/>\n            &lt;\/dataSource&gt;<br \/>\n        &lt;\/environment&gt;<br \/>\n    &lt;\/environments&gt;<br \/>\n&lt;!&#8211;    \u52a0\u8f7d\u6620\u5c04\u6587\u4ef6&#8211;&gt;<br \/>\n    &lt;mappers&gt;<br \/>\n        &lt;mapper resource&#061;&#034;com\/itheima\/mapper\/UserMapper.xml&#034;&gt;&lt;\/mapper&gt;<br \/>\n    &lt;\/mappers&gt;<br \/>\n&lt;\/configuration&gt; <\/li>\n<li>\n<p>\u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801<\/p>\n<p> public class MybatisTest {<br \/>\n    &#064;Test<br \/>\n    public void test01() throws IOException {<br \/>\n        \/\/\u83b7\u5f97\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6<br \/>\n        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        \/\/\u83b7\u5f97session\u5de5\u7a0b\u5bf9\u8c61<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        \/\/\u83b7\u5f97session\u4f1a\u8bdd\u5bf9\u8c61<br \/>\n        SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n        \/\/\u6267\u884c\u64cd\u4f5c \u53c2\u6570&#xff1a;namespace&#043;id<br \/>\n        List&lt;User&gt; users &#061; sqlSession.selectList(&#034;userMapper.findAll&#034;);<br \/>\n        System.out.println(users);<br \/>\n        sqlSession.close();<br \/>\n    }<br \/>\n} <\/li>\n<h4>2.4 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<p>Mybatis\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u6dfb\u52a0Mybatis\u7684\u5750\u6807&#xff08;\u81f3\u5c11\u8981\u6709mybatis\u548cmysql-connector&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efauser\u6570\u636e\u8868<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199User\u5b9e\u4f53\u7c7b<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6620\u5c04\u6587\u4ef6UserMapper.xml<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6838\u5fc3\u6587\u4ef6SqlMapConfig.xml<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199\u6d4b\u8bd5\u7c7b<\/p>\n<\/li>\n<h3>3. Mybatis\u7684\u6620\u5c04\u6587\u4ef6\u6982\u8ff0<\/h3>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034; ?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034; &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt; <\/p>\n<ul>\n<li>\n<p>\u8fd9\u4e2a\u662f\u6620\u5c04\u6587\u4ef6DTD\u7ea6\u675f\u5934&#xff0c;\u5177\u6709\u7ea6\u675f\u548c\u63d0\u793a\u4f5c\u7528<\/p>\n<\/li>\n<\/ul>\n<p>&lt;mapper namespace&#061;&#034;userMapper&#034;&gt;<\/p>\n<ul>\n<li>\n<p>mapper\u662f\u6839\u6807\u7b7e&#xff0c;userMapper\u662f\u547d\u540d\u7a7a\u95f4&#xff0c;\u4e0e\u4e0b\u9762\u8bed\u53e5\u7684id\u4e00\u8d77\u7ec4\u6210\u67e5\u8be2\u7684\u6807\u8bc6<\/p>\n<\/li>\n<\/ul>\n<p>&lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.itheima.domain.User&#034;&gt;<\/p>\n<ul>\n<li>\n<p>select \u67e5\u8be2\u64cd\u4f5c \u53ef\u9009\u7684\u8fd8\u6709insert\u3001update\u3001delete<\/p>\n<\/li>\n<li>\n<p>resultType \u67e5\u8be2\u7ed3\u679c\u5bf9\u5e94\u7684\u5b9e\u4f53\u7c7b\u578b<\/p>\n<\/li>\n<\/ul>\n<p>&lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n    select * from user;<br \/>\n&lt;\/select&gt; <\/p>\n<ul>\n<li>\n<p>\u8981\u6267\u884csql\u8bed\u53e5<\/p>\n<\/li>\n<\/ul>\n<h3>4. Mybatis\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c<\/h3>\n<h4>4.1 Mybatis\u7684\u63d2\u5165\u6570\u636e\u64cd\u4f5c<\/h4>\n<h5>1. \u7f16\u5199UserMapper\u6620\u5c04\u6587\u4ef6<\/h5>\n<p>&lt;!&#8211;    \u63d2\u5165\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;insert id&#061;&#034;save&#034; parameterType&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n        insert into user values(#{id},#{userName},#{password})<br \/>\n    &lt;\/insert&gt; <\/p>\n<h5>2. \u7f16\u5199\u63d2\u5165\u5b9e\u4f53User\u7684\u4ee3\u7801<\/h5>\n<p>&#064;Test<br \/>\npublic void test02() throws IOException {<br \/>\n    \/\/\u6a21\u62dfuser\u5bf9\u8c61<br \/>\n    User user&#061;new User();<br \/>\n    user.setUserName(&#034;zhanananaaaa&#034;);<br \/>\n    user.setPassword(&#034;aaaaaaaa&#034;);<\/p>\n<p>    InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n    SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n    SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n    int row &#061; sqlSession.insert(&#034;userMapper.save&#034;,user);<br \/>\n    System.out.println(row);<br \/>\n    \/\/mybatis\u6267\u884c\u66f4\u65b0\u64cd\u4f5c \u63d0\u4ea4\u4e8b\u52a1<br \/>\n    sqlSession.commit();<br \/>\n    sqlSession.close();<br \/>\n} <\/p>\n<h5>3. \u63d2\u5165\u64cd\u4f5c\u6ce8\u610f\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u63d2\u5165\u8bed\u53e5\u4f7f\u7528insert\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>\u5728\u6620\u5c04\u6587\u4ef6\u4e2d\u4f7f\u7528parameterType\u5c5e\u6027\u503c<\/p>\n<\/li>\n<li>\n<p>Sql\u8bed\u53e5\u4e2d\u4f7f\u7528#{\u5b9e\u4f53\u5c5e\u6027\u540d}\u65b9\u5f0f\u5f15\u7528\u5b9e\u4f53\u7684\u5c5e\u6027\u503c<\/p>\n<\/li>\n<li>\n<p>\u63d2\u5165\u64cd\u4f5c\u4f7f\u7528\u7684API\u662fsqlSession.insert(&#034;\u547d\u540d\u7a7a\u95f4id&#xff0c;\u5b9e\u4f53\u5bf9\u8c61&#034;)<\/p>\n<\/li>\n<li>\n<p>\u63d2\u5165\u64cd\u4f5c\u6d89\u53ca\u6570\u636e\u5e93\u6570\u636e\u53d8\u5316&#xff0c;\u6240\u4ee5\u8981\u4f7f\u7528sqlSession\u5bf9\u8c61\u663e\u793a\u7684\u63d0\u4ea4\u4e8b\u52a1&#xff0c;\u5373sqlSession.commit()<\/p>\n<\/li>\n<\/ul>\n<h4>4.2 Mybatis\u7684\u4fee\u6539\u6570\u636e\u64cd\u4f5c<\/h4>\n<h5>1. \u7f16\u5199UserMapper\u6620\u5c04\u6587\u4ef6<\/h5>\n<p>&lt;!&#8211;    \u4fee\u6539\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;update id&#061;&#034;update&#034; parameterType&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n        update user set userName&#061;#{userName},password&#061;#{password} where id&#061;#{id}<br \/>\n    &lt;\/update&gt; <\/p>\n<h5>2. \u7f16\u5199\u4fee\u6539\u5b9e\u4f53User\u7684\u4ee3\u7801<\/h5>\n<p>&#064;Test<br \/>\n    public void test03() throws IOException {<br \/>\n        \/\/\u6a21\u62dfuser\u5bf9\u8c61<br \/>\n        User user&#061;new User();<br \/>\n        user.setId(11);<br \/>\n        user.setUserName(&#034;vv&#034;);<br \/>\n        user.setPassword(&#034;abc&#034;);<\/p>\n<p>        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n        int row &#061; sqlSession.update(&#034;userMapper.update&#034;,user);<br \/>\n        System.out.println(row);<br \/>\n        \/\/mybatis\u6267\u884c\u66f4\u65b0\u64cd\u4f5c \u63d0\u4ea4\u4e8b\u52a1<br \/>\n        sqlSession.commit();<br \/>\n        sqlSession.close();<br \/>\n    } <\/p>\n<h5>3. \u4fee\u6539\u64cd\u4f5c\u6ce8\u610f\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u4fee\u6539\u8bed\u53e5\u4f7f\u7528update\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539\u64cd\u4f5c\u4f7f\u7528\u7684API\u662fsqlSession.update(&#034;\u547d\u540d\u7a7a\u95f4.id&#034;,\u5b9e\u4f53\u5bf9\u8c61)&#xff1b;<\/p>\n<\/li>\n<\/ul>\n<h4>4.3 Mybatis\u7684\u5220\u9664\u6570\u636e\u64cd\u4f5c<\/h4>\n<h5>1. \u7f16\u5199UserMapper\u6620\u5c04\u6587\u4ef6<\/h5>\n<p>&lt;!&#8211;    \u5220\u9664\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;delete id&#061;&#034;delete&#034; parameterType&#061;&#034;java.lang.Integer&#034;&gt;<br \/>\n        delete from user id&#061;#{id}<br \/>\n    &lt;\/delete&gt; <\/p>\n<h5>2. \u6d4b\u8bd5\u4ee3\u7801<\/h5>\n<p>&#064;Test<br \/>\n    public void test04() throws IOException {<br \/>\n        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n        int row &#061; sqlSession.delete(&#034;userMapper.delete&#034;,1);<br \/>\n        System.out.println(row);<br \/>\n        \/\/mybatis\u6267\u884c\u66f4\u65b0\u64cd\u4f5c \u63d0\u4ea4\u4e8b\u52a1<br \/>\n        sqlSession.commit();<br \/>\n        sqlSession.close();<br \/>\n    } <\/p>\n<h5>3. \u5220\u9664\u64cd\u4f5c\u6ce8\u610f\u95ee\u9898<\/h5>\n<ul>\n<li>\n<p>\u5220\u9664\u8bed\u53e5\u4f7f\u7528delete\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>sql\u8bed\u53e5\u4e2d\u4f7f\u7528#{\u4efb\u610f\u5b57\u7b26\u4e32}\u65b9\u5f0f\u5f15\u7528\u4f20\u9012\u7684\u5355\u4e2a\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u5220\u9664\u64cd\u4f5c\u4f7f\u7528\u7684API\u662fsqlSession.delete(&#034;\u547d\u540d\u7a7a\u95f4.id&#034;&#xff0c;Object)&#xff1b;<\/p>\n<\/li>\n<\/ul>\n<h4>4.4 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<p>\u589e\u5220\u67e5\u6539\u6807\u7b7e&#xff1a;select\u3001insert\u3001update\u3001delete<\/p>\n<p>resultType\u662f\u8fd4\u56de\u7ed3\u679c\u96c6 parameterType\u662f\u5360\u4f4d\u7b26\u5bf9\u8c61(\u5b9e\u4f53\u7c7b\u548c\u666e\u901a\u7c7b\u578b\u7c7b)<\/p>\n<p>\u4f8b\u5b50&#xff1a;<\/p>\n<p>\u67e5\u8be2\u6570\u636e&#xff1a; List&lt;User&gt; userList &#061; sqlSession.selectList(&#034;userMapper.findAll&#034;);<br \/>\n    &lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.itheima.domain.User&#034;&gt;<br \/>\n        select * from User<br \/>\n    &lt;\/select&gt; <\/p>\n<h3>5. Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u6982\u8ff0<\/h3>\n<h4>5.1 Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u5c42\u7ea7\u5173\u7cfb<\/h4>\n<ul>\n<li>\n<p>configuration\u914d\u7f6e<\/p>\n<ul>\n<li>\n<p>properties\u5c5e\u6027<\/p>\n<\/li>\n<li>\n<p>settings\u8bbe\u7f6e<\/p>\n<\/li>\n<li>\n<p>typeAllassess\u7c7b\u578b\u522b\u540d<\/p>\n<\/li>\n<li>\n<p>type Handlers\u7c7b\u578b\u5904\u7406\u5668<\/p>\n<\/li>\n<li>\n<p>objectFactory\u5bf9\u8c61\u5de5\u5382<\/p>\n<\/li>\n<li>\n<p>plugins\u63d2\u4ef6<\/p>\n<\/li>\n<li>\n<p>environments\u73af\u5883<\/p>\n<ul>\n<li>\n<p>environment\u73af\u5883\u53d8\u91cf<\/p>\n<ul>\n<li>\n<p>transactionManager\u4e8b\u52a1\u7ba1\u7406\u5668<\/p>\n<\/li>\n<li>\n<p>dataSource\u6570\u636e\u6e90<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>databaseIdProvider\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6<\/p>\n<\/li>\n<li>\n<p>mappers\u6620\u5c04\u5668<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>5.2 Mybatis\u5e38\u7528\u914d\u7f6e\u89e3\u6790<\/h4>\n<h5>1. environment\u6807\u7b7e<\/h5>\n<p>\u6570\u636e\u5e93\u73af\u5883\u7684\u914d\u7f6e&#xff0c;\u652f\u6301\u591a\u73af\u5883\u914d\u7f6e<\/p>\n<p>sqlMapConfig.xml<\/p>\n<p>&lt;!&#8211; \u00a0  \u6570\u636e\u6e90\u73af\u5883&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;environments default&#061;&#034;development&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;environment id&#061;&#034;development&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;transactionManager type&#061;&#034;JDBC&#034;&gt;&lt;\/transactionManager&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;dataSource type&#061;&#034;POOLED&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;driver&#034; value&#061;&#034;com.mysql.cj.jdbc.Driver&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;url&#034; value&#061;&#034;jdbc:mysql:\/\/localhost:3306\/test?useUnicode&#061;true&amp;amp;characterEncoding&#061;utf-8&amp;amp;serverTimezone&#061;UTC&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;username&#034; value&#061;&#034;root&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;property name&#061;&#034;password&#034; value&#061;&#034;admin&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dataSource&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/environment&gt;<br \/>\n \u00a0 \u00a0&lt;\/environments&gt; <\/p>\n<table>\n<tr>\u89e3\u6790<\/tr>\n<tbody>\n<tr>\n<td>default<\/td>\n<td>\u5728environments\u91cc\u9762&#xff0c;\u4ee3\u8868\u6307\u5b9a\u9ed8\u8ba4\u7684\u73af\u5883\u540d\u79f0<\/td>\n<\/tr>\n<tr>\n<td>id<\/td>\n<td>\u6307\u5b9a\u5f53\u524d\u73af\u5883\u7684\u540d\u79f0<\/td>\n<\/tr>\n<tr>\n<td>type&#061;&#034;JDBC&#034;<\/td>\n<td>\u6307\u5b9a\u4e8b\u52a1\u7ba1\u7406\u7c7b\u578b\u662fJDBC<\/td>\n<\/tr>\n<tr>\n<td>type&#061;&#034;POOLED&#034;<\/td>\n<td>\u6307\u5b9a\u5f53\u524d\u6570\u636e\u6e90\u7c7b\u578b\u662f\u8fde\u63a5\u6c60<\/td>\n<\/tr>\n<tr>\n<td>&lt;property name&#061;&#034;driver&#034; value&#061;&#034;${jdbc.Driver}&#034;\/&gt; &lt;property name&#061;&#034;url&#034; value&#061;&#034;${jdbc.url}&#034;\/&gt; &lt;property name&#061;&#034;username&#034; value&#061;&#034;root&#034;\/&gt; &lt;property name&#061;&#034;password&#034; value&#061;&#034;admin&#034;\/&gt;<\/td>\n<td>\u6570\u636e\u6e90\u914d\u7f6e\u7684\u57fa\u672c\u53c2\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4e2d&#xff0c;\u4e8b\u52a1\u7ba1\u7406\u5668(transactionManager)\u7c7b\u578b\u6709\u4e24\u79cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>JDBC&#xff1a;\u8fd9\u4e2a\u914d\u7f6e\u5c31\u662f\u76f4\u63a5\u4f7f\u7528\u4e86JDBC\u7684\u63d0\u4ea4\u548c\u56de\u6eda\u8bbe\u7f6e&#xff0c;\u5b83\u4f9d\u8d56\u4e8e\u6570\u636e\u6e90\u5f97\u5230\u7684\u8fde\u63a5\u6765\u7ba1\u7406\u4e8b\u52a1\u4f5c\u7528\u57df(\u5e38\u7528)<\/p>\n<\/li>\n<li>\n<p>MANAGED&#xff1a;\u8fd9\u4e2a\u914d\u7f6e\u51e0\u4e4e\u6ca1\u505a\u4ec0\u4e48\u3002\u5b83\u4ece\u6765\u4e0d\u63d0\u4ea4\u6216\u56de\u6eda\u4e00\u4e2a\u8fde\u63a5&#xff0c;\u800c\u662f\u8ba9\u5bb9\u5668\u6765\u7ba1\u7406\u4e8b\u52a1\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f(\u6bd4\u5982JEE\u5e94\u7528\u670d\u52a1\u5668\u7684\u4e0a\u4e0b\u6587)\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5b83\u56de\u5173\u95ed\u8fde\u63a5&#xff0c;\u7136\u800c\u4e00\u4e9b\u5bb9\u5668\u5e76\u4e0d\u5e0c\u671b\u8fd9\u6837&#xff0c;\u56e0\u6b64\u9700\u8981\u5c06closeConnection\u5c5e\u6027\u8bbe\u7f6e\u4e3afalse\u6765\u963b\u6b62\u5b83\u9ed8\u8ba4\u7684\u5173\u95ed\u884c\u4e3a\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5176\u4e2d&#xff0c;\u6570\u636e\u6e90(dataSource)\u7c7b\u578b\u6709\u4e09\u79cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>UNPOOLED&#xff1a;\u8fd9\u4e2a\u6570\u636e\u6e90\u7684\u5b9e\u73b0\u53ea\u662f\u6bcf\u6b21\u88ab\u8bf7\u6c42\u65f6\u6253\u5f00\u548c\u5173\u95ed\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>POOLED&#xff1a;\u8fd9\u79cd\u6570\u636e\u6e90\u7684\u5b9e\u73b0\u5229\u7528&#034;\u6c60&#034;\u7684\u6982\u5ff5\u5c06JDBC\u8fde\u63a5\u5bf9\u8c61\u7ec4\u7ec7\u8d77\u6765<\/p>\n<\/li>\n<li>\n<p>JNDI&#xff1a;\u8fd9\u4e2a\u6570\u636e\u6e90\u7684\u5b9e\u73b0\u662f\u4e3a\u4e86\u80fd\u5728\u5982EJB\u6216\u5e94\u7528\u670d\u52a1\u5668\u8fd9\u7c7b\u5bb9\u5668\u4e2d\u4f7f\u7528&#xff0c;\u5bb9\u5668\u53ef\u4ee5\u96c6\u4e2d\u6216\u5728\u5916\u90e8\u914d\u7f6e\u6570\u636e\u6e90&#xff0c;\u7136\u540e\u653e\u7f6e\u4e00\u4e2aJNDI\u4e0a\u4e0b\u6587\u7684\u5f15\u7528\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2. mapper\u6807\u7b7e<\/h5>\n<p>\u8be5\u6807\u7b7e\u7684\u4f5c\u7528\u662f\u52a0\u8f7d\u6620\u5c04\u7684&#xff0c;\u52a0\u8f7d\u65b9\u5f0f\u6709\u5982\u4e0b\u51e0\u79cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u76f8\u5bf9\u4e8e\u7c7b\u8def\u5f84\u7684\u8d44\u6e90\u5f15\u7528&#xff08;\u5e38\u7528&#xff09;&#xff0c;\u4f8b\u5982&#xff1a;&lt; mapper resource&#061;&#034;com\/itheima\/mapper\/UserMapper.xml&#034;&gt;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5b8c\u5168\u9650\u5b9a\u8d44\u6e90\u5b9a\u4f4d\u7b26(URL)&#xff0c;\u4f8b\u5982&#xff1a;&lt; mapper url&#061;&#034;file:\/\/\/var\/mappers\/AuthorMapper.xml&#034;\/&gt;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6620\u5c04\u5668\u63a5\u53e3\u5b9e\u73b0\u7c7b\u7684\u5b8c\u5168\u9650\u5b9a\u7c7b\u540d&#xff0c;\u4f8b\u5982&#xff1a;&lt; mapper class&#061;&#034;com\/itheima\/mapper\/UserMapper&#034;&gt;<\/p>\n<\/li>\n<li>\n<p>\u5c06\u5305\u5185\u6620\u5c04\u5668\u63a5\u53e3\u5b9e\u73b0\u5168\u90e8\u6ce8\u518c\u4e3a\u6620\u5c04\u5668&#xff0c;\u4f8b\u5982&lt; mapper name&#061;&#034;com\/itheima\/mapper&#034;&gt;<\/p>\n<\/li>\n<\/ul>\n<h5>3. Properties\u6807\u7b7e<\/h5>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u4e60\u60ef\u6570\u636e\u6e90\u7684\u914d\u7f6e\u4fe1\u606f\u5355\u72ec\u62bd\u53d6\u6210\u4e00\u4e2aproperties\u6587\u4ef6&#xff0c;\u8be5\u6807\u7b7e\u53ef\u4ee5\u52a0\u8f7d\u989d\u5916\u914d\u7f6e\u7684properties\u6587\u4ef6<\/p>\n<\/p>\n<h5>4. typeAliases\u6807\u7b7e<\/h5>\n<p>\u7c7b\u578b\u522b\u540d\u662f\u4e3ajava\u7c7b\u578b\u8bbe\u7f6e\u4e00\u4e2a\u77ed\u7684\u540d\u5b57\u3002\u539f\u6765\u7684\u7c7b\u578b\u540d\u79f0\u914d\u7f6e\u5982\u4e0b<\/p>\n<p>&lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;com.itheima.domain.User&#034;&gt;(\u5168\u9650\u5b9a\u540d\u79f0)<br \/>\n    select *from User<br \/>\n&lt;\/select&gt; <\/p>\n<p>\u914d\u7f6etypeAliases&#xff0c;\u4e3acom.itheima.domain.User\u5b9a\u4e49\u522b\u540d\u4e3auser(\u6709\u987a\u5e8f&#xff01;&#xff01;&#xff01;)<\/p>\n<p>&lt;typeAliases&gt;<br \/>\n    &lt;typeAlias type&#061;&#034;com.itheima.domain.User&#034; alias&#061;&#034;user&#034;&gt;&lt;\/typeAlias&gt;<br \/>\n&lt;\/typeAliases&gt;<br \/>\n&lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;user&#034;&gt;(user\u4e3a\u522b\u540d)<br \/>\n    select *from User<br \/>\n&lt;\/select&gt; <\/p>\n<p>\u4e0a\u9762\u6211\u4eec\u662f\u81ea\u5b9a\u4e49\u7684\u522b\u540d&#xff0c;mybatis\u6846\u67b6\u5df2\u7ecf\u4e3a\u6211\u4eec\u8bbe\u7f6e\u597d\u7684\u4e00\u4e9b\u5e38\u7528\u7684\u7c7b\u578b\u7684\u522b\u540d<\/p>\n<table>\n<tr>\u522b\u540d\u6570\u636e\u7c7b\u578b<\/tr>\n<tbody>\n<tr>\n<td>string<\/td>\n<td>String<\/td>\n<\/tr>\n<tr>\n<td>long<\/td>\n<td>Long<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>Integer<\/td>\n<\/tr>\n<tr>\n<td>double<\/td>\n<td>Double<\/td>\n<\/tr>\n<tr>\n<td>boolean<\/td>\n<td>Boolean<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.3 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<li>\n<p>properties\u6807\u7b7e&#xff1a;\u8be5\u6807\u7b7e\u53ef\u4ee5\u52a0\u8f7d\u5916\u90e8\u7684properties\u6587\u4ef6<\/p>\n<p>&lt; properties resource&#061;&#034;jdbc.properties&#034;\/&gt;<\/p>\n<\/li>\n<li>\n<p>typeAliases\u6807\u7b7e&#xff1a;\u8bbe\u7f6e\u7c7b\u578b\u522b\u540d<\/p>\n<p>&lt; typeAlias type&#061;&#034;com.itheima.domain.User&#034; alias&#061;&#034;user&#034;\/&gt;<\/p>\n<\/li>\n<li>\n<p>mappers\u6807\u7b7e&#xff1a;\u52a0\u8f7d\u6620\u5c04\u914d\u7f6e<\/p>\n<p>&lt; mapper resource&#061;&#034;com\/itheima\/mapper\/UserMapper.xml&#034;\/&gt;<\/p>\n<\/li>\n<li>\n<p>environments\u6807\u7b7e&#xff1a;\u6570\u636e\u6e90\u73af\u5883\u914d\u7f6e\u6807\u7b7e(\u591a\u73af\u5883)<\/p>\n<p>&lt; environment&gt; &lt; transactionManager&gt; &lt; dataSource&gt;<\/p>\n<\/li>\n<h3>6. Mybatis\u76f8\u5e94API<\/h3>\n<h4>6.1 SqlSession\u5de5\u5382\u6784\u5efa\u5668SqlSessionFactoryBuilder<\/h4>\n<p>\u5e38\u7528API&#xff1a;SqlSessionFactory build(InputStream inputStream)<\/p>\n<p>\u901a\u8fc7\u52a0\u8f7dmybatis\u7684\u6838\u5fc3\u6587\u4ef6\u7684\u8f93\u5165\u6d41\u7684\u5f62\u5f0f\u6784\u5efa\u4e00\u4e2aSqlSessionFactory\u5bf9\u8c61<\/p>\n<p>String resource&#061;&#034;sqlMapConfig.xml&#034;;<br \/>\nInputStream inputStream&#061;Resources.getResourceAsStream(resource);<br \/>\nSqlSessionFactoryBuilder builder&#061;new SqlSessionFactoryBuilder();<br \/>\nsqlSessionFactory factory&#061;builder.build(inputStream); <\/p>\n<p>\u5176\u4e2d&#xff0c;Resource\u5de5\u5177\u7c7b&#xff0c;\u8fd9\u4e2a\u7c7b\u5728org.apache.ibatis.io\u5305\u4e2d\u3002Resources\u7c7b\u5e2e\u52a9\u4f60\u4ece\u7c7b\u8def\u5f84\u4e0b\u3001\u6587\u4ef6\u7cfb\u7edf\u6216\u4e00\u4e2aweb URL\u4e2d\u52a0\u8f7d\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p>SqlSessionFactory\u6709\u591a\u4e2a\u65b9\u6cd5\u521b\u5efaSqlSession\u5b9e\u4f8b\u3002\u5e38\u7528\u7684\u6709\u5982\u4e0b\u4e24\u4e2a&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\u89e3\u91ca<\/tr>\n<tbody>\n<tr>\n<td>openSession()<\/td>\n<td>\u4f1a\u9ed8\u8ba4\u5f00\u542f\u4e00\u4e2a\u4e8b\u52a1&#xff0c;\u4f46\u4e8b\u52a1\u4e0d\u4f1a\u81ea\u52a8\u63d0\u4ea4&#xff0c;\u4e5f\u5c31\u4ee5\u4e3a\u7740\u9700\u8981\u624b\u52a8\u63d0\u4ea4\u8be5\u4e8b\u52a1&#xff0c;\u66f4\u65b0\u64cd\u4f5c\u6570\u636e\u624d\u4f1a\u6301\u4e45\u5316\u5230\u6570\u636e\u5e93\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>openSession(boolean autoCommit)<\/td>\n<td>\u53c2\u6570\u662f\u5426\u81ea\u52a8\u63d0\u4ea4&#xff0c;\u5982\u679c\u8bbe\u7f6e\u4e3atrue&#xff0c;\u90a3\u4e48\u4e0d\u9700\u8981\u624b\u52a8\u63d0\u4ea4\u4e8b\u52a1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>6.3 SqlSession\u4f1a\u8bdd\u5bf9\u8c61<\/h4>\n<p>SqlSession\u5b9e\u4f8b\u5728Mybatis\u4e2d\u662f\u975e\u5e38\u5f3a\u5927\u7684\u4e00\u4e2a\u7c7b\u3002\u5728\u8fd9\u91cc\u4f60\u4f1a\u770b\u5230\u6240\u6709\u6267\u884c\u8bed\u53e5\u3001\u63d0\u4ea4\u6216\u56de\u6eda\u4e8b\u52a1\u548c\u83b7\u53d6\u6620\u5c04\u5668\u5b9e\u4f8b\u7684\u65b9\u6cd5\u3002\u6267\u884c\u8bed\u53e5\u7684\u65b9\u6cd5\u4e3b\u8981\u6709&#xff1a;<\/p>\n<p>&lt;T&gt; T selectOne(String statement, Object parameter)<br \/>\n&lt;E&gt; List&lt;E&gt; selectList(String statement, Object parameter)<br \/>\nint insert(String statement, Object parameter)<br \/>\nint update(String statement, Object parameter)<br \/>\nint delete(String statement, Object parameter) <\/p>\n<p>\u64cd\u4f5c\u4e8b\u52a1\u7684\u65b9\u6cd5\u4e3b\u8981\u6709&#xff1a;<\/p>\n<p>void commit()<br \/>\nvoid rollback()  <\/p>\n<h2>02-Mybatis\u7684dao\u5c42\u5b9e\u73b0\u539f\u7406<\/h2>\n<h4>1. Mybatis\u7684Dao\u5c42\u5b9e\u73b0<\/h4>\n<h5>1. \u7f16\u5199UserDao\u63a5\u53e3<\/h5>\n<p>public interface UserDao{<br \/>\n    List&lt;User&gt; findAll() throws IOException;<br \/>\n} <\/p>\n<h5>2. \u7f16\u5199UserDaoImpl\u5b9e\u73b0<\/h5>\n<p>public class UserMapperImpl implements UserMapper {<\/p>\n<p>    &#064;Override<br \/>\n    public List&lt;User&gt; findAll() throws IOException {<br \/>\n        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n        List&lt;User&gt; userList &#061; sqlSession.selectList(&#034;userMapper.findAll&#034;);<br \/>\n        sqlSession.close();<br \/>\n        return userList;<br \/>\n    }<br \/>\n} <\/p>\n<h5>3. \u6d4b\u8bd5\u4f20\u7edf\u65b9\u5f0f<\/h5>\n<p>public class ServiceDemo {<\/p>\n<p>    public static void main(String[] args) throws IOException {<br \/>\n        \/\/\u521b\u5efadao\u5c42\u5bf9\u8c61<br \/>\n        UserMapper userMapper&#061;new UserMapperImpl();<br \/>\n        List&lt;User&gt; all &#061; userMapper.findAll();<br \/>\n        System.out.println(all);<br \/>\n    }<br \/>\n} <\/p>\n<h4>1.2 \u4ee3\u7406\u5f00\u53d1\u65b9\u5f0f<\/h4>\n<h5>1. \u4ee3\u7406\u5f00\u53d1\u65b9\u5f0f\u4ecb\u7ecd<\/h5>\n<p>\u91c7\u7528Mybatis\u7684\u4ee3\u7406\u5f00\u53d1\u65b9\u5f0f\u5b9e\u73b0DAO\u5c42\u7684\u5f00\u53d1&#xff0c;\u8fd9\u79cd\u65b9\u5f0f\u662f\u6211\u4eec\u540e\u9762\u8fdb\u5165\u4f01\u4e1a\u7684\u4e3b\u6d41\u3002<\/p>\n<p>Mapper\u63a5\u53e3\u5f00\u53d1\u65b9\u6cd5\u53ea\u9700\u8981\u7a0b\u5e8f\u5458\u7f16\u5199Mapper\u63a5\u53e3(\u76f8\u5f53\u4e8eDao\u63a5\u53e3)&#xff0c;\u7531Mybatis\u6846\u67b6\u63a5\u53e3\u5b9a\u4e49\u521b\u5efa\u63a5\u53e3\u7684\u52a8\u6001\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u7684\u65b9\u6cd5\u4f53\u540c\u4e0a\u8fb9Dao\u63a5\u53e3\u5b9e\u73b0\u7c7b\u65b9\u6cd5\u3002<\/p>\n<p>Mapper\u63a5\u53e3\u5f00\u53d1\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u89c4\u8303&#xff1a;<\/p>\n<li>\n<p>Mapper.xml\u6587\u4ef6\u4e2d\u7684namespace\u4e0emapper\u63a5\u53e3\u7684\u5168\u9650\u5b9a\u540d\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>Mapper\u63a5\u53e3\u65b9\u6cd5\u540d\u548cMapper.xml\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2astatement\u7684id\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>Mapper\u63a5\u53e3\u65b9\u6cd5\u7684\u8f93\u5165\u53c2\u6570\u7c7b\u578b\u548cmapper.xml\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2asql\u7684parameterType\u7684\u7c7b\u578b\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>Mapper\u63a5\u53e3\u65b9\u6cd5\u7684\u8f93\u51fa\u53c2\u6570\u7c7b\u578b\u548cmapper.xml\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2asql\u7684resultType\u7684\u7c7b\u578b\u76f8\u540c<\/p>\n<\/li>\n<h5>2. \u7f16\u5199UserMapper\u63a5\u53e3<\/h5>\n<\/p>\n<h5>3. \u6d4b\u8bd5\u4ee3\u7406\u65b9\u5f0f<\/h5>\n<p>public class ServiceDemo {<\/p>\n<p>    public static void main(String[] args) throws IOException {<br \/>\n        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n        UserMapper userMapper &#061; sqlSession.getMapper(UserMapper.class);<br \/>\n        List&lt;User&gt; all &#061; userMapper.findAll();<br \/>\n        System.out.println(all);<br \/>\n        sqlSession.close();<br \/>\n    }<br \/>\n} <\/p>\n<h4>1.3 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<p>MyBatis\u7684Dao\u5c42\u5b9e\u73b0\u7684\u4e24\u79cd\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u624b\u52a8\u5bf9Dao\u8fdb\u884c\u5b9e\u73b0&#xff1a;\u4f20\u7edf\u5f00\u53d1\u65b9\u5f0f<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7406\u65b9\u5f0f\u5bf9Dao\u8fdb\u884c\u5b9e\u73b0<\/p>\n<p>UserMapper userMapper&#061;sqlSession.getMapper(UserMapper.class)<\/p>\n<\/li>\n<\/ul>\n<h2>03_Mybatis\u6620\u5c04\u6587\u4ef6\u6df1\u5165(\u52a8\u6001SQL)<\/h2>\n<h3>1. Mybatis\u6620\u5c04\u6587\u4ef6\u6df1\u5165<\/h3>\n<h4>1.1 \u52a8\u6001sql\u8bed\u53e5<\/h4>\n<h5>1. \u52a8\u6001sql\u8bed\u53e5\u6982\u8ff0<\/h5>\n<p>mybatis\u7684\u6620\u5c04\u6587\u4ef6\u4e2d&#xff0c;\u524d\u9762\u6211\u4eec\u7684SQL\u90fd\u662f\u6bd4\u8f83\u7b80\u5355\u7684&#xff0c;\u6709\u4e9b\u65f6\u5019\u4e1a\u52a1\u903b\u8f91\u590d\u6742\u65f6&#xff0c;\u6211\u4eec\u7684SQL\u662f\u52a8\u6001\u53d8\u5316\u7684&#xff0c;\u6b64\u65f6\u5728\u524d\u9762\u7684\u5b66\u4e60\u4e2d\u6211\u4eec\u7684SQL\u5c31\u4e0d\u80fd\u6ee1\u8db3\u8981\u6c42\u4e86\u3002<\/p>\n<\/p>\n<h5>2. \u52a8\u6001SQL\u4e4b&lt; if&gt;<\/h5>\n<p>\u6211\u4eec\u6839\u636e\u5b9e\u4f53\u7c7b\u7684\u4e0d\u592a\u53d6\u503c&#xff0c;\u4f7f\u7528\u4e0d\u540c\u7684SQL\u8bed\u53e5\u6765\u8fdb\u884c\u67e5\u8be2\u3002\u6bd4\u5982\u5728id\u5982\u679c\u4e0d\u4e3a\u7a7a\u65f6\u53ef\u4ee5\u6839\u636eid\u67e5\u8be2&#xff0c;\u5982\u679cusername\u4e0d\u540c\u7a7a\u65f6\u8fd8\u8981\u52a0\u5165\u7528\u6237\u540d\u4f5c\u4e3a\u6761\u4ef6\u3002\u8fd9\u79cd\u60c5\u51b5\u5728\u6211\u4eec\u591a\u6761\u4ef6\u7ec4\u5408\u67e5\u8be2\u4e2d\u7ecf\u5e38\u4f1a\u78b0\u5230\u3002<\/p>\n<p>&lt;select id&#061;&#034;findByCondition&#034; parameterType&#061;&#034;user&#034; resultType&#061;&#034;user&#034;&gt;<br \/>\nselect * from User<br \/>\n&lt;where&gt;<br \/>\n&lt;if test&#061;&#034;id!&#061;0&#034;&gt;<br \/>\nand id&#061;#{id}<br \/>\n&lt;\/if&gt;<br \/>\n&lt;if test&#061;&#034;username!&#061;null&#034;&gt;<br \/>\nand username&#061;#{username}<br \/>\n&lt;\/if&gt;<br \/>\n&lt;\/where&gt;<br \/>\n&lt;\/select&gt; <\/p>\n<\/p>\n<h5>3. \u52a8\u6001SQL\u4e4b&lt; foreach&gt;<\/h5>\n<p>\u5faa\u73af\u6267\u884csql\u7684\u62fc\u63a5\u64cd\u4f5c&#xff0c;\u4f8b\u5982&#xff1a;select * from user where id in(1,2,5)<\/p>\n<p>public List&lt;User&gt; findByIds(List&lt;Integer&gt; ids);<br \/>\n&lt;select id&#061;&#034;findByIds&#034; parameterType&#061;&#034;list&#034; resultType&#061;&#034;user&#034;&gt;<br \/>\n    select * from user<br \/>\n    &lt;where&gt;<br \/>\n        &lt;foreach collection&#061;&#034;list&#034; open&#061;&#034;id&#034; close&#061;&#034;)&#034; item&#061;&#034;id&#034; separator&#061;&#034;,&#034;&gt;<br \/>\n            #{id}<br \/>\n        &lt;\/foreach&gt;<br \/>\n    &lt;\/where&gt;<br \/>\n&lt;\/select&gt; <\/p>\n<p>foreach\u6807\u7b7e\u7684\u5c5e\u6027\u542b\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>&lt; foreach&gt;\u6807\u7b7e\u7528\u4e8e\u904d\u5386\u96c6\u5408&#xff0c;\u5b83\u7684\u5c5e\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>collection&#xff1a;\u4ee3\u8868\u8981\u904d\u5386\u7684\u96c6\u5408\u5143\u7d20&#xff0c;\u6ce8\u610f\u7f16\u5199\u65f6\u4e0d\u7528\u5199#{} \u6570\u7ec4\u5219\u4e3aarray \u96c6\u5408\u6839\u636e\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>open&#xff1a;\u4ee3\u8868\u8bed\u53e5\u7684\u5f00\u59cb\u90e8\u5206<\/p>\n<\/li>\n<li>\n<p>close&#xff1a;\u4ee3\u8868\u7ed3\u675f\u90e8\u5206<\/p>\n<\/li>\n<li>\n<p>item&#xff1a;\u4ee3\u8868\u904d\u5386\u96c6\u5408\u7684\u6bcf\u4e2a\u5143\u7d20&#xff0c;\u751f\u6210\u7684\u53d8\u91cf\u540d<\/p>\n<\/li>\n<li>\n<p>sperator&#xff1a;\u4ee3\u8868\u5206\u9694\u7b26<\/p>\n<\/li>\n<\/ul>\n<h4>1.2 SQL\u7247\u6bb5\u62bd\u53d6<\/h4>\n<p>Sql\u4e2d\u53ef\u5c06\u91cd\u590d\u7684sql\u63d0\u53d6\u51fa\u6765&#xff0c;\u4f7f\u7528\u65f6\u7528include\u5f15\u7528\u5373\u53ef&#xff0c;\u6700\u7ec8\u8fbe\u5230sql\u91cd\u7528\u7684\u76ee\u7684<\/p>\n<p>&lt;!&#8211;    sql\u8bed\u53e5\u62bd\u53d6&#8211;&gt;<br \/>\n    &lt;sql id&#061;&#034;selectUser&#034;&gt;select * from user&lt;\/sql&gt;<br \/>\n    &lt;select id&#061;&#034;findByCondition&#034; parameterType&#061;&#034;user&#034; resultType&#061;&#034;user&#034;&gt;<br \/>\n        &lt;include refid&#061;&#034;selectUser&#034;&gt;&lt;\/include&gt;<br \/>\n        &lt;where&gt;<br \/>\n            &lt;if test&#061;&#034;id&#xff01;&#061;0&#034;&gt;<br \/>\n                #{id}<br \/>\n            &lt;\/if&gt;<br \/>\n            &lt;if test&#061;&#034;userName!&#061;null&#034;&gt;<br \/>\n                #{userName}<br \/>\n            &lt;\/if&gt;<br \/>\n            &lt;if test&#061;&#034;password!&#061;null&#034;&gt;<br \/>\n                #{password}<br \/>\n            &lt;\/if&gt;<br \/>\n        &lt;\/where&gt;<br \/>\n    &lt;\/select&gt; <\/p>\n<h4>1.3 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<h5>Mybatis\u6620\u5c04\u6587\u4ef6\u914d\u7f6e&#xff1a;<\/h5>\n<p>&lt; select&gt;:\u67e5\u8be2<\/p>\n<p>&lt; insert&gt;:\u63d2\u5165<\/p>\n<p>&lt; update&gt;:\u4fee\u6539<\/p>\n<p>&lt; delete&gt;:\u5220\u9664<\/p>\n<p>&lt; where&gt;:where\u6761\u4ef6<\/p>\n<p>&lt; if&gt;:if\u5224\u65ad<\/p>\n<p>&lt; foreach&gt;:\u5faa\u73af<\/p>\n<p>&lt; sql&gt;&#xff1a;sql\u7247\u6bb5\u62bd\u53d6<\/p>\n<h2>04_Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u6df1\u5165<\/h2>\n<h3>1.Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u6df1\u5165<\/h3>\n<h4>1.1typeHandler\u6807\u7b7e<\/h4>\n<p>\u65e0\u8bba\u662fMybatis\u5728\u9884\u5904\u7406\u8bed\u53e5(PreparedStatement)\u4e2d\u8bbe\u7f6e\u4e00\u4e2a\u53c2\u6570\u65f6&#xff0c;\u8fd8\u662f\u4ece\u7ed3\u679c\u96c6\u4e2d\u53d6\u51fa\u4e00\u4e2a\u503c\u65f6&#xff0c;\u90fd\u4f1a\u7528\u7c7b\u578b\u5904\u7406\u5668\u5c06\u83b7\u53d6\u7684\u503c\u4ee5\u5408\u9002\u7684\u65b9\u5f0f\u8f6c\u6362\u6210java\u7c7b\u578b\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u7684\u7c7b\u578b\u5904\u7406\u5668(\u622a\u53d6\u90e8\u5206)\u3002<\/p>\n<\/p>\n<p>\u4f60\u53ef\u4ee5\u91cd\u5199\u7c7b\u578b\u5904\u7406\u5668\u6216\u521b\u5efa\u4f60\u81ea\u5df1\u7684\u7c7b\u578b\u5904\u7406\u5668\u6765\u5904\u7406\u4e0d\u652f\u6301\u7684\u6216\u975e\u6807\u51c6\u7684\u7c7b\u578b\u3002\u5177\u4f53\u505a\u6cd5\u4e3a&#xff1a;\u5b9e\u73b0org.apache.ibatis.type.TypeHandler\u63a5\u53e3&#xff0c;\u6216\u7ee7\u627f\u4e00\u4e2a\u5f88\u4fbf\u5229\u7684\u7c7borg.apache.ibatis.type.BaseTypeHandler&#xff0c;\u7136\u540e\u53ef\u4ee5\u9009\u62e9\u6027\u5730\u5c06\u5b83\u6620\u5c04\u5230\u4e00\u4e2aJDBC\u7c7b\u578b\u3002\u4f8b\u5982\u9700\u6c42&#xff1a;\u4e00\u4e2ajava\u4e2d\u7684Date\u6570\u636e\u7c7b\u578b&#xff0c;\u6211\u60f3\u5c06\u4e4b\u5b58\u5230\u6570\u636e\u5e93\u7684\u65f6\u5019\u5b58\u6210\u4e00\u4e2a1970\u5e74\u81f3\u4eca\u7684\u6beb\u79d2\u6570&#xff0c;\u53d6\u51fa\u6765\u65f6\u8f6c\u6362\u6210java\u7684Date&#xff0c;\u5373java\u7684Date\u4e0e\u6570\u636e\u5e93\u7684varchar\u6beb\u79d2\u503c\u4e4b\u95f4\u8f6c\u6362\u3002<\/p>\n<p>\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u5b9a\u4e49\u8f6c\u6362\u7ee7\u627f\u7c7bBaseTypeHandler&lt;T&gt;<\/p>\n<\/li>\n<li>\n<p>\u8986\u76d64\u4e2a\u672a\u5b9e\u73b0\u7684\u65b9\u6cd5&#xff0c;\u5176\u4e2dsetNonNullParameter\u4e3ajava\u7a0b\u5e8f\u8bbe\u7f6e\u6570\u636e\u5230\u6570\u636e\u5e93\u7684\u56de\u8c03\u65b9\u6cd5&#xff0c;getNullableResult\u4e3a\u67e5\u8be2\u65f6mysql\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u8f6c\u6362\u6210java\u7684type\u7c7b\u578b\u7684\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u5728Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u6ce8\u518c<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u8f6c\u6362\u662f\u5426\u6b63\u786e<\/p>\n<\/li>\n<p>public class DateTypeHandler extends BaseTypeHandler&lt;Date&gt; {<br \/>\n    \/\/\u5c06java\u7684Date\u7c7b\u578b \u8f6c\u6362\u6210\u6570\u636e\u5e93\u9700\u8981\u7684\u7c7b\u578b(int)<br \/>\n    &#064;Override<br \/>\n    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Date date, JdbcType jdbcType) throws SQLException {<br \/>\n        long time &#061; date.getTime();<br \/>\n        preparedStatement.setLong(i,time);<br \/>\n    }<\/p>\n<p>    \/\/\u5c06\u6570\u636e\u5e93\u4e2d\u7c7b\u578b \u8f6c\u6362\u6210java\u7c7b\u578b<br \/>\n    \/\/string\u53c2\u6570 \u8981\u8f6c\u6362\u7684\u5b57\u6bb5\u540d\u79f0<br \/>\n    \/\/Resultset \u67e5\u8be2\u51fa\u7684\u7ed3\u679c<br \/>\n    &#064;Override<br \/>\n    public Date getNullableResult(ResultSet resultSet, String s) throws SQLException {<br \/>\n        \/\/\u83b7\u5f97\u7ed3\u679c\u96c6\u4e2d\u9700\u8981\u7684\u6570\u636e(long)\u8f6c\u6362\u6210Date\u7c7b\u578b \u8fd4\u56de<br \/>\n        long aLong &#061; resultSet.getLong(s);<br \/>\n        Date date &#061; new Date(aLong);<br \/>\n        return date;<br \/>\n    }<\/p>\n<p>    \/\/\u5c06\u6570\u636e\u5e93\u4e2d\u7c7b\u578b \u8f6c\u6362\u6210java\u7c7b\u578b<br \/>\n    &#064;Override<br \/>\n    public Date getNullableResult(ResultSet resultSet, int i) throws SQLException {<br \/>\n        \/\/\u83b7\u5f97\u7ed3\u679c\u96c6\u4e2d\u9700\u8981\u7684\u6570\u636e(long)\u8f6c\u6362\u6210Date\u7c7b\u578b \u8fd4\u56de<br \/>\n        long aLong &#061; resultSet.getLong(i);<br \/>\n        Date date &#061; new Date(aLong);<br \/>\n        return date;<br \/>\n    }<\/p>\n<p>    \/\/\u5c06\u6570\u636e\u5e93\u4e2d\u7c7b\u578b \u8f6c\u6362\u6210java\u7c7b\u578b<br \/>\n    &#064;Override<br \/>\n    public Date getNullableResult(CallableStatement callableStatement, int i) throws SQLException {<br \/>\n        \/\/\u83b7\u5f97\u7ed3\u679c\u96c6\u4e2d\u9700\u8981\u7684\u6570\u636e(long)\u8f6c\u6362\u6210Date\u7c7b\u578b \u8fd4\u56de<br \/>\n        long aLong &#061; callableStatement.getLong(i);<br \/>\n        Date date &#061; new Date(aLong);<br \/>\n        return date;<br \/>\n    }<br \/>\n}<br \/>\n&lt;!&#8211;    \u81ea\u5b9a\u4e49\u6ce8\u518c\u7c7b\u578b\u5904\u7406&#8211;&gt;<br \/>\n    &lt;typeHandlers&gt;<br \/>\n        &lt;typeHandler handler&#061;&#034;com.itheima.handler.DateTypeHandler&#034;\/&gt;<br \/>\n    &lt;\/typeHandlers&gt; <\/p>\n<h4>1.2 plugins\u6807\u7b7e<\/h4>\n<p>Mybatis\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u7684\u63d2\u4ef6\u6765\u5bf9\u529f\u80fd\u8fdb\u884c\u6269\u5c55&#xff0c;\u5206\u9875\u52a9\u624bPageHelper\u662f\u5c06\u5206\u9875\u7684\u590d\u6742\u64cd\u4f5c\u8fdb\u884c\u5c01\u88c5&#xff0c;\u4f7f\u7528\u7b80\u5355\u7684\u65b9\u5f0f\u5373\u53ef\u83b7\u5f97\u5206\u9875\u7684\u76f8\u5173\u6570\u636e<\/p>\n<p>\u5f00\u53d1\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u5bfc\u5165\u901a\u7528PageHelper\u7684\u5750\u6807<\/p>\n<\/li>\n<li>\n<p>\u5728mybatis\u6838\u5fc3\u4f4d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6ePageHelper\u63d2\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u5206\u9875\u6570\u636e\u83b7\u53d6<\/p>\n<\/li>\n<h5>1.\u5bfc\u5165\u901a\u7528PageHelper\u7684\u5750\u6807<\/h5>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;com.github.pagehelper&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;pagehelper&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;3.7.5&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt;<br \/>\n&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;com.github.jsqlparser&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;jsqlparser&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;0.9.1&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<h5>2. plugins\u6807\u7b7e<\/h5>\n<p>\u5728mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6ePageHelper\u63d2\u4ef6<\/p>\n<p>&lt;!&#8211;    \u914d\u7f6e\u5206\u9875\u52a9\u624b\u63d2\u4ef6&#8211;&gt;<br \/>\n    &lt;plugins&gt;<br \/>\n        &lt;plugin interceptor&#061;&#034;com.github.pagehelper.PageHelper&#034;&gt;<br \/>\n            &lt;property name&#061;&#034;dialect&#034; value&#061;&#034;mysql&#034;\/&gt;<br \/>\n        &lt;\/plugin&gt;<br \/>\n    &lt;\/plugins&gt; <\/p>\n<h5>4. \u6d4b\u8bd5\u5206\u9875\u4ee3\u7801<\/h5>\n<\/p>\n<h5>5. plugins\u6807\u7b7e\u7684\u5176\u4ed6\u53c2\u6570<\/h5>\n<table>\n<tr>\u53c2\u6570(PageInfo&lt; User&gt; pageInfo &#061; new PageInfo&lt; User&gt;(userList);)<\/tr>\n<tbody>\n<tr>\n<td>pageInfo.getTotal()<\/td>\n<td>\u603b\u6761\u6570<\/td>\n<\/tr>\n<tr>\n<td>pageInfo.getPages()<\/td>\n<td>\u603b\u9875\u6570<\/td>\n<\/tr>\n<tr>\n<td>pageInfo.getPageNum()<\/td>\n<td>\u5f53\u524d\u9875<\/td>\n<\/tr>\n<tr>\n<td>pageInfo.getPageSize()<\/td>\n<td>\u6bcf\u9875\u663e\u793a\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>pageInfo.isFirstPage()<\/td>\n<td>\u662f\u5426\u7b2c\u4e00\u9875<\/td>\n<\/tr>\n<tr>\n<td>pageInfo.isLastPage()<\/td>\n<td>\u662f\u5426\u6700\u540e\u4e00\u9875<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.3 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<p>Mybatis\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u5e38\u7528\u6807\u7b7e&#xff1a;<\/p>\n<li>\n<p>properties\u6807\u7b7e&#xff1a;\u8be5\u6807\u7b7e\u53ef\u4ee5\u52a0\u8f7d\u5916\u90e8\u7684properties\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>typeAliases\u6807\u7b7e&#xff1a;\u8bbe\u7f6e\u7c7b\u578b\u522b\u540d<\/p>\n<\/li>\n<li>\n<p>environment\u6807\u7b7e&#xff1a;\u6570\u636e\u6e90\u73af\u5883\u914d\u7f6e\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>typeHandler\u6807\u7b7e&#xff1a;\u914d\u7f6e\u81ea\u5b9a\u4e49\u7c7b\u578b\u5904\u7406\u5668<\/p>\n<\/li>\n<li>\n<p>plugins\u6807\u7b7e&#xff1a;\u914d\u7f6eMybatis\u7684\u63d2\u4ef6<\/p>\n<\/li>\n<h3>05_Mybatis\u7684\u591a\u8868\u64cd\u4f5c<\/h3>\n<h4>1. Mybatis\u591a\u8868\u67e5\u8be2<\/h4>\n<h5>1. \u4e00\u5bf9\u4e00\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u548c\u8ba2\u5355\u8868\u7684\u5173\u7cfb\u4e3a&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u8ba2\u5355&#xff0c;\u4e00\u4e2a\u8ba2\u5355\u53ea\u4ece\u5c5e\u4e00\u4e2a\u7528\u6237<\/p>\n<p>\u4e00\u5bf9\u4e00\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u4e00\u4e2a\u8ba2\u5355&#xff0c;\u4e0e\u6b64\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u8ba2\u5355\u6240\u5c5e\u7684\u7528\u6237<\/p>\n<\/p>\n<h5>2. \u4e00\u5bf9\u4e00\u67e5\u8be2\u7684\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5&#xff1a;select * from orders o,user u where o.uid&#061;u.id;<\/p>\n<p>\u67e5\u8be2\u7684\u7ed3\u679c\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<h5>3.\u521b\u5efaOrder\u548cUser\u5b9e\u4f53<\/h5>\n<\/p>\n<h5>4.\u521b\u5efaOrderMapper\u63a5\u53e3<\/h5>\n<p>public interface OrderMapper {<br \/>\n    public List&lt;Order&gt; findAll();<br \/>\n} <\/p>\n<h5>5. \u914d\u7f6eOrderMapper.xml<\/h5>\n<p>&lt;mapper namespace&#061;&#034;com.itheima.mapper.OrderMapper&#034;&gt;<br \/>\n    &lt;resultMap id&#061;&#034;orderMap&#034; type&#061;&#034;order&#034;&gt;<br \/>\n&lt;!&#8211;        \u624b\u52a8\u6307\u5b9a\u5b57\u6bb5\u4e0e\u5b9e\u4f53\u5c5e\u6027\u7684\u6620\u5c04\u5173\u7cfb<br \/>\ncolumn:\u6570\u636e\u8868\u7684\u5b57\u6bb5\u540d\u79f0<br \/>\nproperties:\u5b9e\u4f53\u7684\u5c5e\u6027\u540d\u79f0<br \/>\n&#8211;&gt;<br \/>\n        &lt;id column&#061;&#034;oid&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;ordertime&#034; property&#061;&#034;ordertime&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;total&#034; property&#061;&#034;total&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;uid&#034; property&#061;&#034;user.id&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;userName&#034; property&#061;&#034;user.userName&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;password&#034; property&#061;&#034;user.password&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;Birthday&#034; property&#061;&#034;user.Birthday&#034;\/&gt;<br \/>\n        or<br \/>\n        &lt;!&#8211;property\u5f53\u524d\u5b9e\u4f53(order)\u4e2d\u7684\u5c5e\u6027\u540d\u79f0 private User user<br \/>\n            javaType:\u5f53\u524d\u5b9e\u4f53(order)\u4e2d\u7684\u5c5e\u6027\u7684\u7c7b\u578b(User)&#8211;&gt;<br \/>\n        &lt;association property&#061;&#034;user&#034; javaType&#061;&#034;user&#034;&gt;<br \/>\n            &lt;id column&#061;&#034;uid&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n            &lt;result column&#061;&#034;userName&#034; property&#061;&#034;user.userName&#034;\/&gt;<br \/>\n            &lt;result column&#061;&#034;password&#034; property&#061;&#034;user.password&#034;\/&gt;<br \/>\n            &lt;result column&#061;&#034;Birthday&#034; property&#061;&#034;user.Birthday&#034;\/&gt;<br \/>\n        &lt;\/association&gt;<br \/>\n    &lt;\/resultMap&gt;<br \/>\n    &lt;select id&#061;&#034;findAll&#034; resultMap&#061;&#034;orderMap&#034;&gt;<br \/>\n        select *,o.id oid from orders o,user u where o.uid&#061;u.id<br \/>\n    &lt;\/select&gt;<br \/>\n&lt;\/mapper&gt; <\/p>\n<h4>1.2 \u4e00\u5bf9\u591a\u67e5\u8be2<\/h4>\n<h5>1. \u4e00\u5bf9\u591a\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u8868\u548c\u8ba2\u5355\u8868\u7684\u5173\u7cfb\u4e3a&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u8ba2\u5355&#xff0c;\u4e00\u4e2a\u8ba2\u5355\u53ea\u4ece\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237<\/p>\n<p>\u4e00\u5bf9\u591a\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u4e00\u4e2a\u7528\u6237&#xff0c;\u4e0e\u6b64\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u7528\u6237\u5177\u6709\u7684\u8ba2\u5355<\/p>\n<\/p>\n<h5>2. \u4e00\u5bf9\u591a\u67e5\u8be2\u7684\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5&#xff1a;select *,o.id oid from user u ,orders o where u.id&#061;o.uid<\/p>\n<p>\u67e5\u8be2\u7684\u7ed3\u679c\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<h5>3. \u4fee\u6539User\u5b9e\u4f53<\/h5>\n<\/p>\n<h5>4.\u521b\u5efaUserMapper\u63a5\u53e3<\/h5>\n<\/p>\n<h5>5.\u914d\u7f6eUserMapper.xml<\/h5>\n<p>&lt;resultMap id&#061;&#034;userMap&#034; type&#061;&#034;user&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;id column&#061;&#034;uid&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;result column&#061;&#034;userName&#034; property&#061;&#034;userName&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;result column&#061;&#034;password&#034; property&#061;&#034;password&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;result column&#061;&#034;Birthday&#034; property&#061;&#034;Birthday&#034;\/&gt;<br \/>\n&lt;!&#8211; \u00a0 \u00a0 \u00a0  \u914d\u7f6e\u96c6\u5408\u4fe1\u606f&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;collection property&#061;&#034;orderList&#034; ofType&#061;&#034;order&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;id column&#061;&#034;oid&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;result column&#061;&#034;ordertime&#034; property&#061;&#034;ordertime&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;result column&#061;&#034;total&#034; property&#061;&#034;total&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/collection&gt;<br \/>\n \u00a0 \u00a0&lt;\/resultMap&gt;<br \/>\n \u00a0 \u00a0&lt;select id&#061;&#034;findAll&#034; resultMap&#061;&#034;userMap&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0  select *,o.id oid from user u ,orders o where u.id&#061;o.uid<br \/>\n \u00a0 \u00a0&lt;\/select&gt; <\/p>\n<h5>6.\u6d4b\u8bd5\u7ed3\u679c<\/h5>\n<\/p>\n<h4>1.3 \u591a\u5bf9\u591a\u67e5\u8be2<\/h4>\n<h5>1. \u591a\u5bf9\u591a\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u8868\u548c\u89d2\u8272\u8868\u7684\u5173\u7cfb\u4e3a&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u89d2\u8272&#xff0c;\u4e00\u4e2a\u89d2\u8272\u88ab\u591a\u4e2a\u7528\u6237\u4f7f\u7528<\/p>\n<p>\u591a\u5bf9\u591a\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u7528\u6237\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u7528\u6237\u7684\u6240\u6709\u89d2\u8272<\/p>\n<\/p>\n<h5>2. \u591a\u5bf9\u591a\u67e5\u8be2\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5\u548c\u7ed3\u679c&#xff1a;<\/p>\n<\/p>\n<h5>3. \u521b\u5efaRole\u5b9e\u4f53&#xff0c;\u4fee\u6539User\u5b9e\u4f53<\/h5>\n<\/p>\n<h5>4.\u6dfb\u52a0UserMapper\u63a5\u53e3\u65b9\u6cd5<\/h5>\n<\/p>\n<h5>5.\u914d\u7f6eUserMapper.xml<\/h5>\n<p>resultMap id&#061;&#034;userRoleMap&#034; type&#061;&#034;user&#034;&gt;<br \/>\n    &lt;id column&#061;&#034;id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;userName&#034; property&#061;&#034;userName&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;password&#034; property&#061;&#034;password&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;Birthday&#034; property&#061;&#034;Birthday&#034;\/&gt;<br \/>\n    &lt;collection property&#061;&#034;roleList&#034; ofType&#061;&#034;com.itheima.domain.Role&#034;&gt;<br \/>\n        &lt;id column&#061;&#034;roleId&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;roleName&#034; property&#061;&#034;roleName&#034;\/&gt;<br \/>\n        &lt;result column&#061;&#034;roleDesc&#034; property&#061;&#034;roleDesc&#034;\/&gt;<br \/>\n    &lt;\/collection&gt;<br \/>\n&lt;\/resultMap&gt;<\/p>\n<p>&lt;select id&#061;&#034;findUserAndRoleAll&#034; resultMap&#061;&#034;userRoleMap&#034;&gt;<br \/>\n    select * from user u,sys_user_role ur,sys_role r where u.id&#061;ur.userId and ur.roleId&#061;r.id<br \/>\n&lt;\/select&gt; <\/p>\n<h4>1.4 \u77e5\u8bc6\u5c0f\u7ed3<\/h4>\n<p>Mybatis\u591a\u8868\u914d\u7f6e\u65b9\u5f0f&#xff1a;<\/p>\n<p>\u4e00\u5bf9\u4e00\u914d\u7f6e&#xff1a;\u4f7f\u7528&lt; resultMap&gt;\u505a\u914d\u7f6eor\u4f7f\u7528&lt; resultMap&gt;&#043;&lt; association&gt;\u505a\u914d\u7f6e<\/p>\n<p>\u4e00\u5bf9\u591a\u914d\u7f6e&#xff1a;\u4f7f\u7528&lt; resultMap&gt;&#043;&lt; collection&gt;\u505a\u914d\u7f6e<\/p>\n<p>\u591a\u5bf9\u591a\u914d\u7f6e&#xff1a;\u4f7f\u7528&lt; resultMap&gt;&#043;&lt; collection&gt;\u505a\u914d\u7f6e<\/p>\n<h2>06_Mybatis\u6ce8\u89e3\u5f00\u53d1<\/h2>\n<h3>1.Mybatis\u7684\u6ce8\u89e3\u5f00\u53d1<\/h3>\n<h4>1.1Mybatis\u7684\u5e38\u7528\u6ce8\u89e3<\/h4>\n<p>\u8fd9\u51e0\u5e74\u6765\u6ce8\u89e3\u5f00\u53d1\u8d8a\u6765\u8d8a\u6d41\u884c&#xff0c;Mybatis\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6ce8\u89e3\u5f00\u53d1\u65b9\u5f0f&#xff0c;\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u51cf\u5c11\u7f16\u5199Mapper\u6620\u5c04\u6587\u4ef6\u4e86\u3002\u6211\u4eec\u5148\u56f4\u7ed5\u4e00\u4e9b\u57fa\u672c\u7684CRUD\u6765\u5b66\u4e60&#xff0c;\u518d\u5b66\u4e60\u590d\u6742\u6620\u5c04\u591a\u8868\u64cd\u4f5c\u3002<\/p>\n<p>&#064;Insert&#xff1a;\u5b9e\u73b0\u65b0\u589e<\/p>\n<p>&#064;Update&#xff1a;\u5b9e\u73b0\u66f4\u65b0<\/p>\n<p>&#064;Delete&#xff1a;\u5b9e\u73b0\u5220\u9664<\/p>\n<p>&#064;Select&#xff1a;\u5b9e\u73b0\u67e5\u8be2<\/p>\n<p>&#064;Result&#xff1a;\u5b9e\u73b0\u7ed3\u679c\u96c6\u5c01\u88c5<\/p>\n<p>&#064;Results&#xff1a;\u53ef\u4ee5\u4e0e&#064;Result\u4e00\u8d77\u4f7f\u7528&#xff0c;\u5c01\u88c5\u591a\u4e2a\u7ed3\u679c\u96c6<\/p>\n<p>&#064;One&#xff1a;\u5b9e\u73b0\u4e00\u5bf9\u4e00\u7ed3\u679c\u96c6\u5c01\u88c5<\/p>\n<p>&#064;Many&#xff1a;\u5b9e\u73b0\u4e00\u5bf9\u591a\u7ed3\u679c\u96c6\u5c01\u88c5<\/p>\n<h4>1.2 Mybatis\u7684\u589e\u5220\u6539\u67e5<\/h4>\n<p>\u6211\u4eec\u5148\u7528xml\u914d\u7f6e\u65b9\u5f0f\u5b8c\u6210\u7b80\u5355\u7684user\u8868\u7684\u589e\u5220\u6539\u67e5<\/p>\n<p>UserMapper.xml<\/p>\n<p>&lt;!&#8211;    \u67e5\u8be2\u5355\u4e2a&#8211;&gt;<br \/>\n    &lt;select id&#061;&#034;findById&#034; parameterType&#061;&#034;int&#034; resultType&#061;&#034;user&#034;&gt;<br \/>\n    select * from user where id&#061;#{id}<br \/>\n    &lt;\/select&gt;<br \/>\n&lt;!&#8211;    \u67e5\u8be2\u5168\u90e8&#8211;&gt;<br \/>\n    &lt;select id&#061;&#034;findAll&#034; resultType&#061;&#034;user&#034;&gt;<br \/>\n        select * from user<br \/>\n    &lt;\/select&gt;<br \/>\n&lt;!&#8211;    \u63d2\u5165\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;insert id&#061;&#034;save&#034; parameterType&#061;&#034;user&#034;&gt;<br \/>\n        insert into user values (#{id},#{userName},#{password},#{Birthday});<br \/>\n    &lt;\/insert&gt;<br \/>\n&lt;!&#8211;    \u4fee\u6539\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;update id&#061;&#034;update&#034; parameterType&#061;&#034;user&#034;&gt;<br \/>\n        update user set userName&#061;#{userName},password&#061;#{password} where id&#061;#{id}<br \/>\n    &lt;\/update&gt;<br \/>\n&lt;!&#8211;    \u5220\u9664\u64cd\u4f5c&#8211;&gt;<br \/>\n    &lt;delete id&#061;&#034;delete&#034; parameterType&#061;&#034;int&#034;&gt;<br \/>\n        delete from user where id&#061;#{id}<br \/>\n    &lt;\/delete&gt;<br \/>\npublic interface UserMapper {<\/p>\n<p>    public User findById(int id);<\/p>\n<p>    public List&lt;User&gt; findAll();<\/p>\n<p>    public void save(User user);<\/p>\n<p>    public void update(User user);<\/p>\n<p>    public void delete(int id);<br \/>\n}<br \/>\npublic class MybatisTest {<br \/>\n    private UserMapper mapper;<\/p>\n<p>    &#064;Before<br \/>\n    public void before() throws IOException {<br \/>\n        InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n        SqlSessionFactory build &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n        SqlSession sqlSession &#061; build.openSession(true);<br \/>\n        mapper &#061; sqlSession.getMapper(UserMapper.class);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testSave(){<br \/>\n        User user&#061;new User();<br \/>\n        user.setUserName(&#034;lisa&#034;);<br \/>\n        user.setPassword(&#034;123&#034;);<br \/>\n        mapper.save(user);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testUpdate(){<br \/>\n        User user&#061;new User();<br \/>\n        user.setId(17);<br \/>\n        user.setUserName(&#034;wisi&#034;);<br \/>\n        user.setPassword(&#034;123&#034;);<br \/>\n        mapper.update(user);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testDelete(){<br \/>\n        mapper.delete(5);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testFindById(){<br \/>\n        User user &#061; mapper.findById(17);<br \/>\n        System.out.println(user);<br \/>\n    }<\/p>\n<p>    &#064;Test<br \/>\n    public void testFindFindAll(){<br \/>\n        List&lt;User&gt; userList &#061; mapper.findAll();<br \/>\n        System.out.println(userList);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u4fee\u6539Mybatis\u7684\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6&#xff0c;\u6211\u4eec\u4f7f\u7528\u4e86\u6ce8\u89e3\u66ff\u4ee3\u7684\u6620\u5c04\u6587\u4ef6&#xff0c;\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u52a0\u8f7d\u4f7f\u7528\u4e86\u6ce8\u89e3\u7684Mapper\u63a5\u53e3\u6216\u8005\u6307\u5b9a\u626b\u63cf\u5305\u542b\u6620\u5c04\u5173\u7cfb\u7684\u63a5\u53e3\u5305<\/p>\n<p>&lt;!&#8211;    \u52a0\u8f7d\u6620\u5c04\u5173\u7cfb&#8211;&gt;<br \/>\n    &lt;mappers&gt;<br \/>\n&lt;!&#8211;        \u6307\u5b9a\u63a5\u53e3\u6240\u5728\u7684\u5305&#8211;&gt;<br \/>\n        &lt;package name&#061;&#034;com.itheima.mapper&#034;\/&gt;<br \/>\n    &lt;\/mappers&gt;<br \/>\npublic interface UserMapper {<br \/>\n    &#064;Select(&#034;select * from user where id&#061;#{id}&#034;)<br \/>\n    public User findById(int id);<br \/>\n    &#064;Select(&#034;select * from user&#034;)<br \/>\n    public List&lt;User&gt; findAll();<br \/>\n    &#064;Insert(&#034;insert into user values (#{id},#{userName},#{password},#{Birthday});&#034;)<br \/>\n    public void save(User user);<br \/>\n    &#064;Update(&#034;update user set userName&#061;#{userName},password&#061;#{password} where id&#061;#{id}&#034;)<br \/>\n    public void update(User user);<br \/>\n    &#064;Delete(&#034;delete from user where id&#061;#{id}&#034;)<br \/>\n    public void delete(int id);<br \/>\n} <\/p>\n<h4>1.3 Mybatis\u7684\u6ce8\u89e3\u5b9e\u73b0\u590d\u6742\u6620\u5c04\u5f00\u53d1<\/h4>\n<p>\u5b9e\u73b0\u590d\u6742\u5173\u7cfb\u6620\u5c04\u4e4b\u524d\u6211\u4eec\u53ef\u4ee5\u5728\u6620\u5c04\u6587\u4ef6\u4e2d\u901a\u8fc7\u914d\u7f6e&lt; resultMap&gt;\u6765\u5b9e\u73b0&#xff0c;\u4f7f\u7528\u6ce8\u89e3\u5f00\u53d1\u540e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528&#064;Results\u6ce8\u89e3&#xff0c;&#064;Result\u6ce8\u89e3&#xff0c;&#064;One\u6ce8\u89e3&#xff0c;&#064;Many\u6ce8\u89e3\u7ec4\u5408\u5b8c\u6210\u590d\u6742\u5173\u7cfb\u7684\u914d\u7f6e<\/p>\n<table>\n<tr>\u6ce8\u89e3\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>&#064;Results<\/td>\n<td>\u4ee3\u66ff\u7684\u662f\u6807\u7b7e&lt; resultMap&gt;\u8be5\u6ce8\u89e3\u4e2d\u53ef\u4ee5\u4f7f\u7528\u5355\u4e2a&#064;Result\u6ce8\u89e3&#xff0c;\u4e5f\u53ef\u4ee5\u4f7f\u7528&#064;Result\u96c6\u5408\u3002 \u4f7f\u7528\u683c\u5f0f&#xff1a;&#064;Results({&#064;Result()&#xff0c;&#064;Result()})\u6216&#064;Results(&#064;Result())<\/td>\n<\/tr>\n<tr>\n<td>&#064;Result<\/td>\n<td>\u4ee3\u66ff&lt; id&gt;\u6807\u7b7e\u548c&lt; Result&gt;\u6807\u7b7e &#064; Result\u4e2d\u5c5e\u6027\u4ecb\u7ecd&#xff1a; column&#xff1a;\u6570\u636e\u5e93\u7684\u5217\u540d property&#xff1a;\u9700\u8981\u88c5\u914d\u7684\u5c5e\u6027\u540d one&#xff1a;\u9700\u8981\u4f7f\u7528\u7684&#064;One\u6ce8\u89e3(&#064;Result(one&#061;&#064;One( ))) many&#xff1a;\u9700\u8981\u4f7f\u7528\u7684&#064;Many\u6ce8\u89e3(&#064;Result(many&#061;&#064;many( )))<\/td>\n<\/tr>\n<tr>\n<td>&#064;One(\u4e00\u5bf9\u4e00)<\/td>\n<td>\u4ee3\u66ff\u4e86&lt; assocation&gt;\u6807\u7b7e&#xff0c;\u662f\u591a\u8868\u67e5\u8be2\u7684\u5173\u952e&#xff0c;\u5728\u6ce8\u89e3\u4e2d\u7528\u6765\u6307\u5b9a\u5b50\u67e5\u8be2\u8fd4\u56de\u5355\u4e00\u5bf9\u8c61\u3002 &#064;One\u6ce8\u89e3\u5c5e\u6027\u4ecb\u7ecd&#xff1a; select&#xff1a;\u6307\u5b9a\u7528\u6765\u591a\u8868\u67e5\u8be2\u7684sqlmapper \u4f7f\u7528\u683c\u5f0f&#xff1a;&#064;Result(column&#061;&#034;&#034;,property&#061;&#034;&#034;,one&#061;&#064;One(select&#061;&#034;&#034;))<\/td>\n<\/tr>\n<tr>\n<td>&#064;Many(\u591a\u5bf9\u4e00)<\/td>\n<td>\u4ee3\u66ff\u4e86&lt; collection&gt;\u6807\u7b7e&#xff0c;\u662f\u591a\u8868\u67e5\u8be2\u7684\u5173\u952e&#xff0c;\u5728\u6ce8\u89e3\u4e2d\u7528\u6765\u6307\u5b9a\u5b50\u67e5\u8be2\u8fd4\u56de\u5bf9\u8c61\u96c6\u5408\u3002 \u4f7f\u7528\u683c\u5f0f&#xff1a;&#064;Result(property&#061;&#034;&#034;,column&#061;&#034;&#034;,many&#061;&#064;Many(select&#061;&#034;&#034;))<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.4 \u4e00\u5bf9\u4e00\u67e5\u8be2<\/h4>\n<h5>1. \u4e00\u5bf9\u4e00\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u8868\u548c\u8ba2\u5355\u8868\u7684\u5173\u7cfbwei&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u8ba2\u5355&#xff0c;\u4e00\u4e2a\u8ba2\u5355\u53ea\u4ece\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237<\/p>\n<p>\u4e00\u5bf9\u4e00\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u4e00\u4e2a\u8ba2\u5355&#xff0c;\u4e8e\u6b64\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u8ba2\u5355\u6240\u5c5e\u7684yonghu<\/p>\n<\/p>\n<h5>2. \u4e00\u5bf9\u4e00\u67e5\u8be2\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5&#xff1a;select *,o.id oid from orders o,user u where o.uid&#061;u.id<\/p>\n<p>\u67e5\u8be2\u7684\u7ed3\u679c\u5982\u4e0b&#xff1a;<\/p>\n<\/p>\n<h5>3.\u521b\u5efaOrder\u548cUser\u7684\u5b9e\u4f53&#xff08;\u5982\u4e0a\u7684\u7b14\u8bb0\u53ef\u77e5&#xff09;<\/h5>\n<h5>4.\u521b\u5efaOrderMapper\u63a5\u53e3\u548c\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e<\/h5>\n<p>public interface OrderMapper {<br \/>\n    &#064;Select(&#034;select *,o.id oid from orders o,user u where o.uid&#061;u.id&#034;)<br \/>\n    &#064;Results({<br \/>\n            &#064;Result(column &#061; &#034;oid&#034;, property &#061; &#034;id&#034;),<br \/>\n            &#064;Result(column &#061; &#034;ordertime&#034;, property &#061; &#034;ordertime&#034;),<br \/>\n            &#064;Result(column &#061; &#034;total&#034;, property &#061; &#034;total&#034;),<br \/>\n            &#064;Result(column &#061; &#034;uid&#034;, property &#061; &#034;user.id&#034;),<br \/>\n            &#064;Result(column &#061; &#034;userName&#034;, property &#061; &#034;user.userName&#034;),<br \/>\n            &#064;Result(column &#061; &#034;password&#034;, property &#061; &#034;user.password&#034;),<br \/>\n            &#064;Result(column &#061; &#034;Birthday&#034;, property &#061; &#034;user.Birthday&#034;),<br \/>\n    })<br \/>\n    public List&lt;Order&gt; findAll();<br \/>\n}<br \/>\npublic interface OrderMapper {<br \/>\n    &#064;Select(&#034;select * from orders&#034;)<br \/>\n    &#064;Results({<br \/>\n            &#064;Result(column &#061; &#034;id&#034;, property &#061; &#034;id&#034;),<br \/>\n            &#064;Result(column &#061; &#034;ordertime&#034;, property &#061; &#034;ordertime&#034;),<br \/>\n            &#064;Result(column &#061; &#034;total&#034;, property &#061; &#034;total&#034;),<br \/>\n            &#064;Result(<br \/>\n                    property &#061; &#034;user&#034;,\/\/\u8981\u5c01\u88c5\u7684\u5c5e\u6027\u540d\u79f0<br \/>\n                    column &#061; &#034;uid&#034;,\/\/\u6839\u636e\u90a3\u4e2a\u5b57\u6bb5\u53bb\u67e5\u8be2user\u8868\u7684\u6570\u636e<br \/>\n                    javaType &#061; User.class, \/\/\u8981\u5c01\u88c5\u7684\u5b9e\u4f53\u7c7b\u578b<br \/>\n                    \/\/select\u5c5e\u6027 \u4ee3\u8868\u67e5\u8be2\u90a3\u4e2a\u63a5\u53e3\u7684\u65b9\u6cd5\u83b7\u5f97\u6570\u636e<br \/>\n                    one &#061; &#064;One(select &#061; &#034;com.itheima.mapper.UserMapper.findById&#034;)<br \/>\n            )<br \/>\n    })<br \/>\n    public List&lt;Order&gt; findAll();<br \/>\n} <\/p>\n<h5>5.\u6d4b\u8bd5\u7ed3\u679c<\/h5>\n<\/p>\n<h4>1.5 \u4e00\u5bf9\u591a\u67e5\u8be2<\/h4>\n<h5>1.\u4e00\u5bf9\u591a\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u8868\u548c\u8ba2\u5355\u8868\u7684\u5173\u7cfb\u4e3a&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u8ba2\u5355&#xff0c;\u4e00\u4e2a\u8ba2\u5355\u53ea\u4ece\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237<\/p>\n<p>\u4e00\u5bf9\u591a\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u4e00\u4e2a\u7528\u6237&#xff0c;\u4e0e\u6b64\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u7528\u6237\u5177\u6709\u7684\u8ba2\u5355<\/p>\n<\/p>\n<h5>2.\u4e00\u5bf9\u591a\u7684\u67e5\u8be2\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5&#xff1a;<\/p>\n<p>select*from user&#xff1b;<\/p>\n<p>select * from orders where uid&#061;\u67e5\u8be2\u51fa\u7528\u6237\u7684id;<\/p>\n<h5>3.\u4fee\u6539\u5b9e\u4f53&#xff08;\u7531\u4e0a\u7b14\u8bb0\u53ef\u77e5&#xff09;<\/h5>\n<h5>4.\u521b\u5efaUserMapper\u63a5\u53e3\u548c\u4f7f\u7528\u6ce8\u89e3<\/h5>\n<p>usermapper.java<\/p>\n<p>&#064;Select(&#034;select * from orders where uid&#061;#{id}&#034;)<br \/>\npublic List&lt;Order&gt; findByUid(int uid);<br \/>\n&#064;Select(&#034;select * from user&#034;)<br \/>\n&#064;Results({<br \/>\n        &#064;Result(column &#061; &#034;id&#034;,property &#061; &#034;id&#034;),<br \/>\n        &#064;Result(column &#061; &#034;userName&#034;,property &#061; &#034;userName&#034;),<br \/>\n        &#064;Result(column &#061; &#034;password&#034;,property &#061; &#034;password&#034;),<br \/>\n        &#064;Result(column &#061; &#034;Birthday&#034;,property &#061; &#034;Birthday&#034;),<br \/>\n        &#064;Result(<br \/>\n                property &#061; &#034;orderList&#034;,<br \/>\n                column &#061; &#034;id&#034;,<br \/>\n                javaType &#061; List.class,<br \/>\n                many &#061; &#064;Many(select &#061; &#034;com.itheima.mapper.UserMapper.findByUid&#034;)<br \/>\n        )<br \/>\n})<br \/>\npublic List&lt;User&gt; findUserAndOrderAll(); <\/p>\n<h5>6.\u6d4b\u8bd5\u7ed3\u679c<\/h5>\n<\/p>\n<h4>1.6\u591a\u5bf9\u591a\u67e5\u8be2<\/h4>\n<h5>1.\u591a\u5bf9\u591a\u67e5\u8be2\u7684\u6a21\u578b<\/h5>\n<p>\u7528\u6237\u548c\u89d2\u8272\u8868\u7684\u5173\u7cfb\u4e3a&#xff0c;\u4e00\u4e2a\u7528\u6237\u6709\u591a\u4e2a\u89d2\u8272&#xff0c;\u4e00\u4e2a\u89d2\u8272\u88ab\u591a\u4e2a\u7528\u6237\u4f7f\u7528<\/p>\n<p>\u591a\u5bf9\u591a\u67e5\u8be2\u7684\u9700\u6c42&#xff1a;\u67e5\u8be2\u7528\u6237\u540c\u65f6\u67e5\u8be2\u51fa\u8be5\u7528\u6237\u7684\u6240\u6709\u89d2\u8272<\/p>\n<p>\u4e0e\u4e00\u5bf9\u591a\u5dee\u4e0d\u591a&#xff0c;\u533a\u522b\u5c31\u662f\u8981\u4f7f\u7528\u4e00\u4e2a\u4e2d\u95f4\u8868<\/p>\n<\/p>\n<h5>2.\u591a\u5bf9\u591a\u67e5\u8be2\u8bed\u53e5<\/h5>\n<p>\u5bf9\u5e94\u7684sql\u8bed\u53e5&#xff1a;<\/p>\n<p>select * from user;<\/p>\n<p>select * from role r,user_role ur where r.id&#061;ur.role_id and ur.user_id&#061;\u7528\u6237\u7684id<\/p>\n<h5>3.\u521b\u5efaRole\u5b9e\u4f53&#xff0c;\u4fee\u6539User\u5b9e\u4f53(\u7531\u4e0a\u9762\u7b14\u8bb0\u53ef\u77e5)<\/h5>\n<h5>4.\u6dfb\u52a0UserMapper\u548cRoleMapper\u7684\u63a5\u53e3\u65b9\u6cd5\u5e76\u6ce8\u89e3<\/h5>\n<p>public interface RoleMapper {<br \/>\n    &#064;Select(&#034;select * from sys_user_role ur,sys_role r where ur.roleId&#061;r.id and ur.userId&#061;#{uid}&#034;)<br \/>\n    public List&lt;Role&gt; findByUid(int uid);<br \/>\n}<br \/>\n&#064;Select(&#034;select * from user&#034;)<br \/>\n&#064;Results({<br \/>\n        &#064;Result(id &#061; true,column &#061; &#034;id&#034;,property &#061; &#034;id&#034;),<br \/>\n        &#064;Result(column &#061; &#034;userName&#034;,property &#061; &#034;userName&#034;),<br \/>\n        &#064;Result(column &#061; &#034;password&#034;,property &#061; &#034;password&#034;),<br \/>\n        &#064;Result(column &#061; &#034;Birthday&#034;,property &#061; &#034;Birthday&#034;),<br \/>\n        &#064;Result(<br \/>\n                property &#061; &#034;roleList&#034;,<br \/>\n                javaType &#061; List.class,<br \/>\n                column &#061; &#034;id&#034;,<br \/>\n                many &#061;&#064;Many(select &#061; &#034;com.itheima.mapper.RoleMapper.findByUid&#034;)<\/p>\n<p>        )<br \/>\n})<br \/>\npublic List&lt;User&gt; findUserAndRoleAll(); <\/p>\n<h5>5.\u6d4b\u8bd5\u7ed3\u679c<\/h5>\n<\/p>\n<h2>SSM\u6574\u5408<\/h2>\n<h4>1.1\u51c6\u5907\u5de5\u4f5c<\/h4>\n<h5>1.\u539f\u59cb\u65b9\u5f0f\u6574\u5408<\/h5>\n<\/p>\n<h5>2.\u521b\u5efaMaven\u5de5\u7a0b<\/h5>\n<\/p>\n<h5>3.\u5bfc\u5165Maven\u7684\u5750\u6807<\/h5>\n<p> \u00a0 &lt;dependencies&gt;<br \/>\n&lt;!&#8211; \u00a0 \u00a0 \u00a0  spring\u76f8\u5173&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-web&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-tx&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.3.3&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-test&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.3.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.aspectj&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;aspectjweaver&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;1.8.13&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.springframework&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;5.0.5.RELEASE&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n&lt;!&#8211; \u00a0 \u00a0 \u00a0  \u6570\u636e\u5e93\u548cmybatis&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;mysql&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;8.0.22&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.mybatis&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;mybatis&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;3.5.6&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;org.mybatis&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;mybatis-spring&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;2.0.6&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;!&#8211; \u00a0 \u00a0 \u00a0  \u6d4b\u8bd5&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;junit&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;junit&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;4.13.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;scope&gt;test&lt;\/scope&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;log4j&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;log4j&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;1.2.17&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n&lt;!&#8211; \u00a0 \u00a0 \u00a0  servlet\u548cjsp&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;javax.servlet&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;javax.servlet-api&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;4.0.0&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;javax.servlet.jsp&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;jsp-api&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;2.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n&lt;!&#8211; \u00a0 \u00a0 \u00a0  \u6570\u636e\u6e90\u548c\u6807\u7b7e\u5e93&#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;com.mchange&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;c3p0&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;0.9.5.5&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;javax.servlet.jsp.jstl&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;jstl&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;1.2&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;dependency&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;groupId&gt;com.alibaba&lt;\/groupId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;druid&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;1.2.4&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/dependency&gt;<br \/>\n \u00a0 \u00a0&lt;\/dependencies&gt;<br \/>\n\u200b<br \/>\n \u00a0 \u00a0&lt;build&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;finalName&gt;itheima_ssm&lt;\/finalName&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;pluginManagement&gt;&lt;!&#8211; lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) &#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugins&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-clean-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;3.0.0&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;!&#8211; see http:\/\/maven.apache.org\/ref\/current\/maven-core\/default-bindings.html#Plugin_bindings_for_war_packaging &#8211;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-resources-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;3.0.2&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;3.7.0&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-surefire-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;2.20.1&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-war-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;3.2.0&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-install-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;2.5.2&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;artifactId&gt;maven-deploy-plugin&lt;\/artifactId&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;version&gt;2.8.2&lt;\/version&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugin&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;\/plugins&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/pluginManagement&gt;<br \/>\n \u00a0 \u00a0&lt;\/build&gt; <\/p>\n<h5>4.\u7f16\u5199\u5b9e\u4f53\u7c7b<\/h5>\n<\/p>\n<h5>5.\u7f16\u5199Mapper\u63a5\u53e3<\/h5>\n<p>public interface AccountMapper {<br \/>\n    &#064;Insert(&#034;insert into account values(#{id},#{name},#{money})&#034;)<br \/>\n    public void save(Account account);<\/p>\n<p>    &#064;Select(&#034;select * from account&#034;)<br \/>\n    public List&lt;Account&gt; findAll();<br \/>\n} <\/p>\n<h5>6.\u7f16\u5199Service\u63a5\u53e3 \u7f16\u5199Service\u63a5\u53e3\u5b9e\u73b0<\/h5>\n<p>public interface AccountService {<br \/>\n    public void save(Account account);<\/p>\n<p>    public List&lt;Account&gt; findAll();<br \/>\n}<br \/>\n&#064;Service(&#034;accountService&#034;)<br \/>\npublic class AccountServiceImpl implements AccountService {<\/p>\n<p>    &#064;Override<br \/>\n    public void save(Account account) {<br \/>\n        try {<br \/>\n            InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n            SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n            SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n            AccountMapper accountMapper&#061;sqlSession.getMapper(AccountMapper.class);<br \/>\n            accountMapper.save(account);<br \/>\n            sqlSession.commit();<br \/>\n            sqlSession.close();<br \/>\n        } catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public List&lt;Account&gt; findAll() {<br \/>\n        List&lt;Account&gt; accountList&#061;new ArrayList&lt;Account&gt;();<br \/>\n        try {<br \/>\n            InputStream resourceAsStream &#061; Resources.getResourceAsStream(&#034;sqlMapConfig.xml&#034;);<br \/>\n            SqlSessionFactory sqlSessionFactory &#061; new SqlSessionFactoryBuilder().build(resourceAsStream);<br \/>\n            SqlSession sqlSession &#061; sqlSessionFactory.openSession();<br \/>\n            AccountMapper accountMapper&#061;sqlSession.getMapper(AccountMapper.class);<br \/>\n            accountList &#061; accountMapper.findAll();<br \/>\n            sqlSession.commit();<br \/>\n            sqlSession.close();<br \/>\n        } catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        return accountList;<br \/>\n    }<br \/>\n} <\/p>\n<h5>7.\u7f16\u5199Controller<\/h5>\n<p>&#064;Controller<br \/>\n&#064;RequestMapping(&#034;\/account&#034;)<br \/>\npublic class AccountController {<br \/>\n    &#064;Autowired<br \/>\n    private AccountService accountService;<br \/>\n    \/\/\u4fdd\u5b58<br \/>\n    &#064;RequestMapping(value &#061; &#034;\/save&#034;,produces &#061; &#034;text\/html;charset&#061;UTF-8&#034;)<br \/>\n    &#064;ResponseBody<br \/>\n    public String save(Account account){<br \/>\n        accountService.save(account);<br \/>\n        return &#034;\u4fdd\u5b58\u6210\u529f&#034;;<br \/>\n    }<\/p>\n<p>    \/\/\u67e5\u8be2<br \/>\n    &#064;RequestMapping(&#034;findAll&#034;)<br \/>\n    public ModelAndView findAll(){<br \/>\n        ModelAndView modelAndView&#061;new ModelAndView();<br \/>\n        List&lt;Account&gt; accountList &#061; accountService.findAll();<br \/>\n        modelAndView.addObject(accountList);<br \/>\n        modelAndView.setViewName(&#034;AccountList&#034;);<br \/>\n        return modelAndView;<br \/>\n    }<br \/>\n} <\/p>\n<h5>8.\u7f16\u5199\u6dfb\u52a0\u9875\u9762<\/h5>\n<p>&lt;body&gt;<br \/>\n    &lt;h1&gt;\u6dfb\u52a0\u8d26\u6237\u4fe1\u606f\u8868\u5355&lt;\/h1&gt;<br \/>\n    &lt;form name&#061;&#034;accountForm&#034; action&#061;&#034;${pageContext.request.contextPath}\/account\/save&#034; method&#061;&#034;post&#034;&gt;<br \/>\n        \u8d26\u6237\u540d\u79f0:&lt;input type&#061;&#034;text&#034; name&#061;&#034;name&#034;&gt;&lt;br&gt;<br \/>\n        \u8d26\u6237\u91d1\u989d:&lt;input type&#061;&#034;text&#034; name&#061;&#034;money&#034;&gt;&lt;br&gt;<br \/>\n        &lt;input type&#061;&#034;submit&#034; value&#061;&#034;\u4fdd\u5b58&#034;&gt;&lt;br&gt;<br \/>\n    &lt;\/form&gt;<br \/>\n&lt;\/body&gt; <\/p>\n<h5>9.\u7f16\u5199\u5217\u8868\u9875\u9762<\/h5>\n<p>&lt;body&gt;<br \/>\n&lt;h1&gt;\u5c55\u793a\u8d26\u6237\u6570\u636e\u5217\u8868&lt;\/h1&gt;<br \/>\n&lt;table border&#061;&#034;1&#034;&gt;<br \/>\n    &lt;tr&gt;<br \/>\n        &lt;th&gt;\u8d26\u6237id&lt;\/th&gt;<br \/>\n        &lt;th&gt;\u8d26\u6237\u540d\u79f0&lt;\/th&gt;<br \/>\n        &lt;th&gt;\u8d26\u6237\u91d1\u989d&lt;\/th&gt;<br \/>\n    &lt;\/tr&gt;<\/p>\n<p>    &lt;c:forEach items&#061;&#034;${accountList}&#034; var&#061;&#034;account&#034;&gt;<br \/>\n    &lt;tr&gt;<br \/>\n        &lt;td&gt;${account.id}&lt;\/td&gt;<br \/>\n        &lt;td&gt;${account.name}&lt;\/td&gt;<br \/>\n        &lt;td&gt;${account.money}&lt;\/td&gt;<br \/>\n    &lt;\/tr&gt;<br \/>\n    &lt;\/c:forEach&gt;<br \/>\n&lt;\/table&gt;<br \/>\n&lt;\/body&gt; <\/p>\n<h5>10.\u7f16\u5199\u76f8\u5e94\u914d\u7f6e\u6587\u4ef6<\/h5>\n<ul>\n<li>\n<p>Spring\u914d\u7f6e\u6587\u4ef6&#xff1a;applicationContext.xml<\/p>\n<p> &lt;!&#8211;\u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n    &lt;context:component-scan base-package&#061;&#034;com.itheima&#034;&gt;<br \/>\n&lt;!&#8211;        \u6392\u9664controller\u626b\u63cf&#8211;&gt;<br \/>\n        &lt;context:exclude-filter type&#061;&#034;annotation&#034; expression&#061;&#034;org.springframework.stereotype.Controller&#034;\/&gt;<br \/>\n    &lt;\/context:component-scan&gt; <\/li>\n<li>\n<p>SpringMVC\u914d\u7f6e\u6587\u4ef6&#xff1a;spring-mvc.xml<\/p>\n<p> &lt;!&#8211;    mvc\u7ec4\u4ef6\u626b\u63cf&#8211;&gt;<br \/>\n&lt;context:component-scan base-package&#061;&#034;com.itheima.controller&#034;\/&gt;<br \/>\n&lt;!&#8211;    \u914d\u7f6emvc\u6ce8\u89e3\u9a71\u52a8&#8211;&gt;<br \/>\n    &lt;mvc:annotation-driven\/&gt;<br \/>\n&lt;!&#8211;    \u5185\u90e8\u8d44\u6e90\u89c6\u56fe\u89e3\u6790\u5668&#8211;&gt;<br \/>\n    &lt;bean id&#061;&#034;InternalResourceViewResolver&#034; class&#061;&#034;org.springframework.web.servlet.view.InternalResourceViewResolver&#034;<br \/>\n          p:prefix&#061;&#034;\/WEB-INF\/pages\/&#034; p:suffix&#061;&#034;.jsp&#034; \/&gt;<br \/>\n&lt;!&#8211;    \u5f00\u53d1\u9759\u6001\u8d44\u6e90\u8bbf\u95ee\u6743\u9650&#8211;&gt;<br \/>\n    &lt;mvc:default-servlet-handler\/&gt; <\/li>\n<li>\n<p>Mybatis\u6838\u5fc3\u6587\u4ef6&#xff1a;sqlMapConfig.xml<\/p>\n<p> &lt;configuration&gt;<br \/>\n    &lt;properties resource&#061;&#034;jdbc.properties&#034;\/&gt;<br \/>\n    &lt;environments default&#061;&#034;development&#034;&gt;<br \/>\n        &lt;environment id&#061;&#034;development&#034;&gt;<br \/>\n            &lt;transactionManager type&#061;&#034;JDBC&#034;&gt;&lt;\/transactionManager&gt;<br \/>\n            &lt;dataSource type&#061;&#034;POOLED&#034;&gt;<br \/>\n                &lt;property name&#061;&#034;driver&#034; value&#061;&#034;${jdbc.driver}&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;url&#034; value&#061;&#034;${jdbc.url}&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;username&#034; value&#061;&#034;${jdbc.username}&#034;\/&gt;<br \/>\n                &lt;property name&#061;&#034;password&#034; value&#061;&#034;${jdbc.password}&#034;\/&gt;<br \/>\n            &lt;\/dataSource&gt;<br \/>\n        &lt;\/environment&gt;<br \/>\n    &lt;\/environments&gt;<br \/>\n    &lt;mappers&gt;<br \/>\n        &lt;package name&#061;&#034;com.itheima.mapper&#034;\/&gt;<br \/>\n    &lt;\/mappers&gt;<br \/>\n&lt;\/configuration&gt; <\/li>\n<li>\n<p>\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u6587\u4ef6&#xff1a;jdbc.properties<\/p>\n<\/li>\n<li>\n<p>web.xml\u6587\u4ef6<\/p>\n<p> &lt;!&#8211;    spring\u7684\u76d1\u542c\u5668&#8211;&gt;<br \/>\n    &lt;context-param&gt;<br \/>\n        &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n        &lt;param-value&gt;classpath:applicationContext.xml&lt;\/param-value&gt;<br \/>\n    &lt;\/context-param&gt;<br \/>\n&lt;listener&gt;<br \/>\n    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<br \/>\n&lt;!&#8211;    springmvc\u524d\u7aef\u63a7\u5236\u5668&#8211;&gt;<br \/>\n    &lt;servlet&gt;<br \/>\n        &lt;servlet-name&gt;DispatcherServlet&lt;\/servlet-name&gt;<br \/>\n        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;classpath:spring-mvc.xml&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n        &lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;<br \/>\n    &lt;\/servlet&gt;<br \/>\n    &lt;servlet-mapping&gt;<br \/>\n        &lt;servlet-name&gt;DispatcherServlet&lt;\/servlet-name&gt;<br \/>\n        &lt;url-pattern&gt;\/&lt;\/url-pattern&gt;<br \/>\n    &lt;\/servlet-mapping&gt;<br \/>\n&lt;!&#8211;    utf-8\u7684\u4e71\u7801\u8fc7\u6ee4\u5668&#8211;&gt;<br \/>\n    &lt;filter&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;\/filter-class&gt;<br \/>\n        &lt;init-param&gt;<br \/>\n            &lt;param-name&gt;encoding&lt;\/param-name&gt;<br \/>\n            &lt;param-value&gt;UTF-8&lt;\/param-value&gt;<br \/>\n        &lt;\/init-param&gt;<br \/>\n    &lt;\/filter&gt;<br \/>\n    &lt;filter-mapping&gt;<br \/>\n        &lt;filter-name&gt;CharacterEncodingFilter&lt;\/filter-name&gt;<br \/>\n        &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<br \/>\n    &lt;\/filter-mapping&gt;<br \/>\n    &lt;jsp-config&gt;<br \/>\n        &lt;taglib&gt;<br \/>\n            &lt;taglib-uri&gt;http:\/\/java.sun.com\/jsp\/jstl\/core&lt;\/taglib-uri&gt;<br \/>\n            &lt;taglib-location&gt;\/WEB-INF\/lib\/c.tld&lt;\/taglib-location&gt;<br \/>\n        &lt;\/taglib&gt;<br \/>\n    &lt;\/jsp-config&gt; <\/li>\n<li>\n<p>\u65e5\u5fd7\u6587\u4ef6&#xff1a;log4j.xml<\/p>\n<\/li>\n<\/ul>\n<h4>1.2 Spring\u6574\u5408Mybatis<\/h4>\n<h5>1.\u6574\u5408\u601d\u8def<\/h5>\n<\/p>\n<h5>2.\u5c06SqlSessionFactory\u914d\u7f6e\u5230Spring\u5bb9\u5668\u4e2d&#xff0c;\u4e14\u628a\u6570\u636e\u6e90\u548cjdbc\u6587\u4ef6\u58f0\u660e\u653e\u5728\u5bb9\u5668\u4e2d<\/h5>\n<p>applicationContext.xml<\/p>\n<p> \u00a0 \u00a0&lt;!&#8211; \u00a0  \u52a0\u8f7dproperties\u6587\u4ef6&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;context:property-placeholder location&#061;&#034;classpath:jdbc.properties&#034;\/&gt;<br \/>\n&lt;!&#8211; \u00a0  \u914d\u7f6e\u6570\u636e\u6e90&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;dataSource&#034; class&#061;&#034;com.mchange.v2.c3p0.ComboPooledDataSource&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0p:driverClass&#061;&#034;${jdbc.driver}&#034; p:jdbcUrl&#061;&#034;${jdbc.url}&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0p:user&#061;&#034;${jdbc.username}&#034; p:password&#061;&#034;${jdbc.password}&#034;<br \/>\n \u00a0 \u00a0\/&gt;<br \/>\n&lt;!&#8211; \u00a0  \u914d\u7f6esessionFactory&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;!&#8211; \u00a0 \u00a0 \u00a0  \u52a0\u8f7dmybatis\u6838\u5fc3\u6587\u4ef6&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;SqlSessionFactory&#034; class&#061;&#034;org.mybatis.spring.SqlSessionFactoryBean&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0p:dataSource-ref&#061;&#034;dataSource&#034; p:configLocation&#061;&#034;classpath:sqlMapConfig-spring.xml&#034;&gt;<br \/>\n \u00a0 \u00a0&lt;\/bean&gt; <\/p>\n<h5>3.\u626b\u63cfMapper&#xff0c;\u8ba9Spring\u5bb9\u5668\u4ea7\u751fMapper\u5b9e\u73b0\u7c7b<\/h5>\n<p>applicationContext.xml<\/p>\n<p>&lt;!&#8211; \u00a0  \u52a0\u8f7d\u626b\u63cfmapper\u6240\u5728\u7684\u5305 \u4e3amapper\u521b\u5efa\u5b9e\u73b0\u7c7b&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;bean class&#061;&#034;org.mybatis.spring.mapper.MapperScannerConfigurer&#034; p:basePackage&#061;&#034;com.itheima.mapper&#034;\/&gt; <\/p>\n<h5>4.Service\u4ee3\u7801\u4fee\u6539<\/h5>\n<p>&#064;Service(&#034;accountService&#034;)<br \/>\npublic class AccountServiceImpl implements AccountService {<br \/>\n \u00a0 \u00a0&#064;Autowired<br \/>\n \u00a0 \u00a0private AccountMapper accountMapper;<br \/>\n\u200b<br \/>\n \u00a0 \u00a0&#064;Override<br \/>\n \u00a0 \u00a0public void save(Account account) {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0accountMapper.save(account);<br \/>\n \u00a0  }<br \/>\n\u200b<br \/>\n \u00a0 \u00a0&#064;Override<br \/>\n \u00a0 \u00a0public List&lt;Account&gt; findAll() {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0List&lt;Account&gt; accountList &#061; accountMapper.findAll();<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0return accountList;<br \/>\n \u00a0  }<br \/>\n} <\/p>\n<h5>5.\u914d\u7f6e\u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236<\/h5>\n<p>\u4ee3\u8868SqlSession\u7684commit\u548cclose<\/p>\n<p>&lt;!&#8211; \u00a0  \u58f0\u660e\u5f0f\u4e8b\u52a1\u63a7\u5236&#8211;&gt;<br \/>\n&lt;!&#8211; \u00a0  \u5e73\u53f0\u4e8b\u52a1\u7ba1\u7406\u5668&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;bean id&#061;&#034;transactionManager&#034; class&#061;&#034;org.springframework.jdbc.datasource.DataSourceTransactionManager&#034;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0p:dataSource-ref&#061;&#034;dataSource&#034;<br \/>\n \u00a0 \u00a0\/&gt;<br \/>\n \u00a0 \u00a0<br \/>\n&lt;!&#8211; \u00a0  \u914d\u7f6e\u4e8b\u52a1\u589e\u5f3a&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;tx:advice id&#061;&#034;txAdvice&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;tx:attributes&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;tx:method name&#061;&#034;*&#034;\/&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/tx:attributes&gt;<br \/>\n \u00a0 \u00a0&lt;\/tx:advice&gt;<br \/>\n \u00a0 \u00a0<br \/>\n&lt;!&#8211; \u00a0  \u4e8b\u52a1\u7684AOP\u7ec7\u5165&#8211;&gt;<br \/>\n \u00a0 \u00a0&lt;aop:config&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;aop:advisor advice-ref&#061;&#034;txAdvice&#034; pointcut&#061;&#034;execution(* com.itheima.service.impl.*.*(..))&#034;\/&gt;<br \/>\n \u00a0 \u00a0&lt;\/aop:config&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>01_SpringloC&amp;DI<br \/>\n1.Spring\u6982\u8ff0<br \/>\n1.1Spring\u662f\u4ec0\u4e48(\u7406\u89e3)<br \/>\nSpring\u662f\u5206\u5c42\u7684Java SE\/EE\u5e94\u7528 full-stack \u8f7b\u91cf\u7ea7\u5f00\u6e90\u6846\u67b6&#xff0c;\u4ee5 loC(Inverse Of Control:\u53cd\u8f6c\u63a7\u5236)\u548cAOP(Aspect Oriented Programming&#xff1a;\u9762\u5411\u5207\u9762\u7f16\u7a0b)\u4e3a\u5185\u6838\u3002<br \/>\n\u63d0\u4f9b\u4e86\u5c55\u73b0\u5c42SpringMVC\u548c\u6301\u4e45\u5c42Spring JDBCTemplate\u4ee5\u53ca\u4e1a\u52a1\u5c42\u4e8b\u52a1\u7ba1\u7406\u4f17\u591a\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u6280\u672f&amp;#xf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10187,99,3252],"topic":[],"class_list":["post-95543","post","type-post","status-publish","format-standard","hentry","category-server","tag-codingplan","tag-java","tag-ssm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/95543.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"01_SpringloC&amp;DI 1.Spring\u6982\u8ff0 1.1Spring\u662f\u4ec0\u4e48(\u7406\u89e3) Spring\u662f\u5206\u5c42\u7684Java SE\/EE\u5e94\u7528 full-stack \u8f7b\u91cf\u7ea7\u5f00\u6e90\u6846\u67b6&#xff0c;\u4ee5 loC(Inverse Of Control:\u53cd\u8f6c\u63a7\u5236)\u548cAOP(Aspect Oriented Programming&#xff1a;\u9762\u5411\u5207\u9762\u7f16\u7a0b)\u4e3a\u5185\u6838\u3002 \u63d0\u4f9b\u4e86\u5c55\u73b0\u5c42SpringMVC\u548c\u6301\u4e45\u5c42Spring JDBCTemplate\u4ee5\u53ca\u4e1a\u52a1\u5c42\u4e8b\u52a1\u7ba1\u7406\u4f17\u591a\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u6280\u672f&amp;#xf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/95543.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-26T06:24:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"72 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95543.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/95543.html\",\"name\":\"SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-26T06:24:42+00:00\",\"dateModified\":\"2026-08-26T06:24:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/95543.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/95543.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95543.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SSM\u6846\u67b6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/95543.html","og_locale":"zh_CN","og_type":"article","og_title":"SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"01_SpringloC&amp;DI 1.Spring\u6982\u8ff0 1.1Spring\u662f\u4ec0\u4e48(\u7406\u89e3) Spring\u662f\u5206\u5c42\u7684Java SE\/EE\u5e94\u7528 full-stack \u8f7b\u91cf\u7ea7\u5f00\u6e90\u6846\u67b6&#xff0c;\u4ee5 loC(Inverse Of Control:\u53cd\u8f6c\u63a7\u5236)\u548cAOP(Aspect Oriented Programming&#xff1a;\u9762\u5411\u5207\u9762\u7f16\u7a0b)\u4e3a\u5185\u6838\u3002 \u63d0\u4f9b\u4e86\u5c55\u73b0\u5c42SpringMVC\u548c\u6301\u4e45\u5c42Spring JDBCTemplate\u4ee5\u53ca\u4e1a\u52a1\u5c42\u4e8b\u52a1\u7ba1\u7406\u4f17\u591a\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u6280\u672f&amp;#xf","og_url":"https:\/\/www.wsisp.com\/helps\/95543.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-26T06:24:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"72 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/95543.html","url":"https:\/\/www.wsisp.com\/helps\/95543.html","name":"SSM\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-26T06:24:42+00:00","dateModified":"2026-08-26T06:24:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/95543.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/95543.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/95543.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"SSM\u6846\u67b6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=95543"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95543\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=95543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=95543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=95543"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=95543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}