{"id":58382,"date":"2025-08-16T09:04:41","date_gmt":"2025-08-16T01:04:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/58382.html"},"modified":"2025-08-16T09:04:41","modified_gmt":"2025-08-16T01:04:41","slug":"javaweb-30-%e5%a4%a9%e5%85%a5%e9%97%a8%ef%bc%9a%e7%ac%ac%e5%8d%81%e4%b8%80%e5%a4%a9-java-%e5%8f%8d%e5%b0%84%e6%9c%ba%e5%88%b6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/58382.html","title":{"rendered":"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3"},"content":{"rendered":"<h2><\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4eca\u5929\u6211\u4eec\u5c06\u6df1\u5165\u5b66\u4e60Java \u53cd\u5c04\u673a\u5236&#xff08;Reflection&#xff09;\u2014\u2014 \u8fd9\u662f Java \u8bed\u8a00\u7684\u52a8\u6001\u7279\u6027\u4e4b\u4e00&#xff0c;\u5141\u8bb8\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u83b7\u53d6\u7c7b\u7684\u4fe1\u606f\u5e76\u64cd\u4f5c\u7c7b\u7684\u6210\u5458&#xff08;\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u6784\u9020\u5668\u7b49&#xff09;\u3002\u5728 JavaWeb \u5f00\u53d1\u4e2d&#xff0c;\u53cd\u5c04\u662f\u6846\u67b6\u8bbe\u8ba1\u7684\u7075\u9b42&#xff08;\u5982 Spring \u7684 IOC \u5bb9\u5668\u3001MyBatis \u7684 ORM \u6620\u5c04&#xff09;&#xff0c;\u638c\u63e1\u53cd\u5c04\u673a\u5236\u80fd\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u6846\u67b6\u5e95\u5c42\u539f\u7406&#xff0c;\u7f16\u5199\u66f4\u7075\u6d3b\u7684\u4ee3\u7801\u3002<\/p>\n<h3>\u4ec0\u4e48\u662f\u53cd\u5c04\u673a\u5236&#xff1f;<\/h3>\n<p>\u53cd\u5c04\u673a\u5236\u662f\u6307\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u80fd\u591f\u83b7\u53d6\u81ea\u8eab\u7684\u4fe1\u606f&#xff1a;<\/p>\n<ul>\n<li>\u53ef\u4ee5\u77e5\u9053\u4e00\u4e2a\u7c7b\u7684\u6240\u6709\u5c5e\u6027\u548c\u65b9\u6cd5<\/li>\n<li>\u53ef\u4ee5\u8c03\u7528\u4e00\u4e2a\u5bf9\u8c61\u7684\u4efb\u610f\u65b9\u6cd5<\/li>\n<li>\u53ef\u4ee5\u4fee\u6539\u4e00\u4e2a\u5bf9\u8c61\u7684\u4efb\u610f\u5c5e\u6027<\/li>\n<li>\u53ef\u4ee5\u52a8\u6001\u521b\u5efa\u7c7b\u7684\u5b9e\u4f8b<\/li>\n<\/ul>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u53cd\u5c04\u8ba9 Java \u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u62e5\u6709\u4e86 \u201c\u81ea\u5ba1\u201d \u548c \u201c\u64cd\u4f5c\u81ea\u8eab\u201d \u7684\u80fd\u529b&#xff0c;\u7a81\u7834\u4e86\u7f16\u8bd1\u671f\u7684\u7c7b\u578b\u9650\u5236&#xff0c;\u5b9e\u73b0\u4e86\u52a8\u6001\u6027\u3002<\/p>\n<p>\u53cd\u5c04\u7684\u5e94\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u6846\u67b6\u5f00\u53d1&#xff1a;Spring\u3001MyBatis \u7b49\u6846\u67b6\u5927\u91cf\u4f7f\u7528\u53cd\u5c04\u5b9e\u73b0\u914d\u7f6e\u5316\u64cd\u4f5c<\/li>\n<li>\u52a8\u6001\u4ee3\u7406&#xff1a;AOP&#xff08;\u9762\u5411\u5207\u9762\u7f16\u7a0b&#xff09;\u7684\u5b9e\u73b0\u57fa\u7840<\/li>\n<li>\u6ce8\u89e3\u5904\u7406&#xff1a;\u89e3\u6790\u81ea\u5b9a\u4e49\u6ce8\u89e3\u5e76\u6267\u884c\u76f8\u5e94\u903b\u8f91<\/li>\n<li>\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316&#xff1a;\u5bf9\u8c61\u4e0e\u5b57\u8282\u6d41\u7684\u8f6c\u6362<\/li>\n<li>\u6570\u636e\u5e93 ORM \u6620\u5c04&#xff1a;\u5bf9\u8c61\u4e0e\u8868\u7ed3\u6784\u7684\u6620\u5c04<\/li>\n<\/ul>\n<h3>\u53cd\u5c04\u7684\u6838\u5fc3\u7c7b<\/h3>\n<p>Java \u53cd\u5c04\u673a\u5236\u4e3b\u8981\u901a\u8fc7java.lang.reflect\u5305\u4e2d\u7684\u7c7b\u5b9e\u73b0&#xff0c;\u6838\u5fc3\u7c7b\u5305\u62ec&#xff1a;<\/p>\n<table>\n<tr>\u7c7b\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>Class<\/td>\n<td>\u8868\u793a\u7c7b\u7684\u5b57\u8282\u7801\u5bf9\u8c61&#xff0c;\u662f\u53cd\u5c04\u7684\u5165\u53e3<\/td>\n<\/tr>\n<tr>\n<td>Constructor<\/td>\n<td>\u8868\u793a\u7c7b\u7684\u6784\u9020\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>Method<\/td>\n<td>\u8868\u793a\u7c7b\u7684\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>Field<\/td>\n<td>\u8868\u793a\u7c7b\u7684\u5c5e\u6027<\/td>\n<\/tr>\n<tr>\n<td>Modifier<\/td>\n<td>\u63d0\u4f9b\u65b9\u6cd5\u89e3\u6790\u7c7b\u548c\u6210\u5458\u7684\u4fee\u9970\u7b26&#xff08;\u5982 public\u3001private&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e9b\u7c7b\u5171\u540c\u534f\u4f5c&#xff0c;\u8ba9\u6211\u4eec\u80fd\u591f\u5728\u8fd0\u884c\u65f6\u64cd\u4f5c\u7c7b\u7684\u5404\u79cd\u6210\u5458\u3002<\/p>\n<h3>\u53cd\u5c04\u7684\u5165\u53e3&#xff1a;Class \u5bf9\u8c61<\/h3>\n<p>Class\u7c7b\u662f\u53cd\u5c04\u7684\u6838\u5fc3&#xff0c;\u6bcf\u4e2a\u7c7b\u5728 JVM \u4e2d\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684Class\u5bf9\u8c61&#xff0c;\u5b83\u5305\u542b\u4e86\u8be5\u7c7b\u7684\u6240\u6709\u4fe1\u606f\u3002\u83b7\u53d6Class\u5bf9\u8c61\u6709\u4e09\u79cd\u65b9\u5f0f&#xff1a;<\/p>\n<h4>\u65b9\u5f0f 1&#xff1a;\u901a\u8fc7Class.forName()\u65b9\u6cd5&#xff08;\u6700\u5e38\u7528&#xff09;<\/h4>\n<p>try {<br \/>\n    \/\/ \u53c2\u6570&#xff1a;\u7c7b\u7684\u5168\u9650\u5b9a\u540d&#xff08;\u5305\u540d&#043;\u7c7b\u540d&#xff09;<br \/>\n    Class&lt;?&gt; clazz &#061; Class.forName(&#034;com.example.User&#034;);<br \/>\n    System.out.println(&#034;\u83b7\u53d6\u5230\u7684Class\u5bf9\u8c61&#xff1a;&#034; &#043; clazz);<br \/>\n} catch (ClassNotFoundException e) {<br \/>\n    e.printStackTrace();<br \/>\n}<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u6700\u7075\u6d3b&#xff0c;\u4e0d\u9700\u8981\u5728\u7f16\u8bd1\u671f\u77e5\u9053\u5177\u4f53\u7c7b\u540d&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u52a8\u6001\u52a0\u8f7d\u7c7b&#xff08;\u5e38\u7528\u4e8e\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u7c7b\u540d&#xff09;\u3002<\/p>\n<h4>\u65b9\u5f0f 2&#xff1a;\u901a\u8fc7\u7c7b\u540d.class\u5c5e\u6027<\/h4>\n<p>\/\/ \u76f4\u63a5\u901a\u8fc7\u7c7b\u540d\u83b7\u53d6<br \/>\nClass&lt;User&gt; clazz &#061; User.class;<br \/>\nSystem.out.println(&#034;\u83b7\u53d6\u5230\u7684Class\u5bf9\u8c61&#xff1a;&#034; &#043; clazz);<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u5728\u7f16\u8bd1\u671f\u77e5\u9053\u5177\u4f53\u7c7b&#xff0c;\u7f16\u8bd1\u65f6\u4f1a\u68c0\u67e5\u7c7b\u662f\u5426\u5b58\u5728\u3002<\/p>\n<h4>\u65b9\u5f0f 3&#xff1a;\u901a\u8fc7\u5bf9\u8c61.getClass()\u65b9\u6cd5<\/h4>\n<\/p>\n<p>User user &#061; new User();<br \/>\n\/\/ \u901a\u8fc7\u5bf9\u8c61\u5b9e\u4f8b\u83b7\u53d6<br \/>\nClass&lt;? extends User&gt; clazz &#061; user.getClass();<br \/>\nSystem.out.println(&#034;\u83b7\u53d6\u5230\u7684Class\u5bf9\u8c61&#xff1a;&#034; &#043; clazz);<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u5148\u6709\u5bf9\u8c61\u5b9e\u4f8b&#xff0c;\u9002\u5408\u5df2\u6709\u5bf9\u8c61\u7684\u573a\u666f\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u4e00\u4e2a\u7c7b\u5728 JVM \u4e2d\u53ea\u6709\u4e00\u4e2aClass\u5bf9\u8c61&#xff0c;\u65e0\u8bba\u901a\u8fc7\u54ea\u79cd\u65b9\u5f0f\u83b7\u53d6&#xff0c;\u90fd\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61&#xff1a;<\/p>\n<p>Class&lt;?&gt; clazz1 &#061; Class.forName(&#034;com.example.User&#034;);<br \/>\nClass&lt;User&gt; clazz2 &#061; User.class;<br \/>\nUser user &#061; new User();<br \/>\nClass&lt;? extends User&gt; clazz3 &#061; user.getClass();<\/p>\n<p>System.out.println(clazz1 &#061;&#061; clazz2); \/\/ true<br \/>\nSystem.out.println(clazz1 &#061;&#061; clazz3); \/\/ true<\/p>\n<h3>\u901a\u8fc7\u53cd\u5c04\u64cd\u4f5c\u7c7b\u7684\u6784\u9020\u65b9\u6cd5<\/h3>\n<p>Constructor\u7c7b\u7528\u4e8e\u8868\u793a\u548c\u64cd\u4f5c\u7c7b\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u901a\u8fc7Class\u5bf9\u8c61\u53ef\u4ee5\u83b7\u53d6\u7c7b\u7684\u6240\u6709\u6784\u9020\u65b9\u6cd5&#xff0c;\u5e76\u521b\u5efa\u5bf9\u8c61\u5b9e\u4f8b\u3002<\/p>\n<h4>\u793a\u4f8b&#xff1a;User \u7c7b<\/h4>\n<p>\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u7528\u4e8e\u6d4b\u8bd5\u7684User\u7c7b&#xff1a;<\/p>\n<p>package com.example;<\/p>\n<p>public class User {<br \/>\n    private String username;<br \/>\n    private int age;<br \/>\n    private String email;<\/p>\n<p>    \/\/ \u65e0\u53c2\u6784\u9020<br \/>\n    public User() {<br \/>\n    }<\/p>\n<p>    \/\/ \u6709\u53c2\u6784\u90201<br \/>\n    public User(String username, int age) {<br \/>\n        this.username &#061; username;<br \/>\n        this.age &#061; age;<br \/>\n    }<\/p>\n<p>    \/\/ \u6709\u53c2\u6784\u90202&#xff08;\u79c1\u6709&#xff09;<br \/>\n    private User(String username, int age, String email) {<br \/>\n        this.username &#061; username;<br \/>\n        this.age &#061; age;<br \/>\n        this.email &#061; email;<br \/>\n    }<\/p>\n<p>    \/\/ getter\u548csetter\u65b9\u6cd5<br \/>\n    public String getUsername() {<br \/>\n        return username;<br \/>\n    }<\/p>\n<p>    public void setUsername(String username) {<br \/>\n        this.username &#061; username;<br \/>\n    }<\/p>\n<p>    public int getAge() {<br \/>\n        return age;<br \/>\n    }<\/p>\n<p>    public void setAge(int age) {<br \/>\n        this.age &#061; age;<br \/>\n    }<\/p>\n<p>    public String getEmail() {<br \/>\n        return email;<br \/>\n    }<\/p>\n<p>    public void setEmail(String email) {<br \/>\n        this.email &#061; email;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return &#034;User{&#034; &#043;<br \/>\n                &#034;username&#061;&#039;&#034; &#043; username &#043; &#039;\\\\&#039;&#039; &#043;<br \/>\n                &#034;, age&#061;&#034; &#043; age &#043;<br \/>\n                &#034;, email&#061;&#039;&#034; &#043; email &#043; &#039;\\\\&#039;&#039; &#043;<br \/>\n                &#039;}&#039;;<br \/>\n    }<br \/>\n}<\/p>\n<h4>\u83b7\u53d6\u6784\u9020\u65b9\u6cd5\u5e76\u521b\u5efa\u5bf9\u8c61<\/h4>\n<p>import java.lang.reflect.Constructor;<br \/>\nimport java.lang.reflect.InvocationTargetException;<\/p>\n<p>public class ConstructorReflectionDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            \/\/ \u83b7\u53d6User\u7c7b\u7684Class\u5bf9\u8c61<br \/>\n            Class&lt;?&gt; clazz &#061; Class.forName(&#034;com.example.User&#034;);<\/p>\n<p>            \/\/ 1. \u83b7\u53d6\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\u5e76\u521b\u5efa\u5bf9\u8c61<br \/>\n            Constructor&lt;?&gt; constructor1 &#061; clazz.getConstructor();<br \/>\n            User user1 &#061; (User) constructor1.newInstance(); \/\/ \u8c03\u7528\u65e0\u53c2\u6784\u9020<br \/>\n            user1.setUsername(&#034;\u5f20\u4e09&#034;);<br \/>\n            user1.setAge(20);<br \/>\n            System.out.println(&#034;\u65e0\u53c2\u6784\u9020\u521b\u5efa\u7684\u5bf9\u8c61&#xff1a;&#034; &#043; user1);<\/p>\n<p>            \/\/ 2. \u83b7\u53d6\u6709\u53c2\u6784\u9020\u65b9\u6cd5\u5e76\u521b\u5efa\u5bf9\u8c61<br \/>\n            \/\/ \u53c2\u6570&#xff1a;\u6784\u9020\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b.class<br \/>\n            Constructor&lt;?&gt; constructor2 &#061; clazz.getConstructor(String.class, int.class);<br \/>\n            User user2 &#061; (User) constructor2.newInstance(&#034;\u674e\u56db&#034;, 25); \/\/ \u4f20\u9012\u53c2\u6570<br \/>\n            System.out.println(&#034;\u6709\u53c2\u6784\u9020\u521b\u5efa\u7684\u5bf9\u8c61&#xff1a;&#034; &#043; user2);<\/p>\n<p>            \/\/ 3. \u83b7\u53d6\u79c1\u6709\u6784\u9020\u65b9\u6cd5\u5e76\u521b\u5efa\u5bf9\u8c61<br \/>\n            \/\/ getDeclaredConstructor()\u53ef\u4ee5\u83b7\u53d6\u79c1\u6709\u6784\u9020<br \/>\n            Constructor&lt;?&gt; constructor3 &#061; clazz.getDeclaredConstructor(String.class, int.class, String.class);<br \/>\n            constructor3.setAccessible(true); \/\/ \u66b4\u529b\u8bbf\u95ee&#xff08;\u5ffd\u7565\u8bbf\u95ee\u6743\u9650\u4fee\u9970\u7b26&#xff09;<br \/>\n            User user3 &#061; (User) constructor3.newInstance(&#034;\u738b\u4e94&#034;, 30, &#034;wangwu&#064;example.com&#034;);<br \/>\n            System.out.println(&#034;\u79c1\u6709\u6784\u9020\u521b\u5efa\u7684\u5bf9\u8c61&#xff1a;&#034; &#043; user3);<\/p>\n<p>        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |<br \/>\n                 IllegalAccessException | InvocationTargetException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5173\u952e\u65b9\u6cd5\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>getConstructor(Class&lt;?&gt;&#8230; parameterTypes)&#xff1a;\u83b7\u53d6 public \u4fee\u9970\u7684\u6784\u9020\u65b9\u6cd5<\/li>\n<li>getDeclaredConstructor(Class&lt;?&gt;&#8230; parameterTypes)&#xff1a;\u83b7\u53d6\u6240\u6709\u6784\u9020\u65b9\u6cd5&#xff08;\u5305\u62ec private&#xff09;<\/li>\n<li>newInstance(Object&#8230; initargs)&#xff1a;\u8c03\u7528\u6784\u9020\u65b9\u6cd5\u521b\u5efa\u5bf9\u8c61<\/li>\n<li>setAccessible(true)&#xff1a;\u5173\u95ed\u8bbf\u95ee\u6743\u9650\u68c0\u67e5&#xff0c;\u7528\u4e8e\u8bbf\u95ee\u79c1\u6709\u6210\u5458<\/li>\n<\/ul>\n<h3>\u901a\u8fc7\u53cd\u5c04\u64cd\u4f5c\u7c7b\u7684\u65b9\u6cd5<\/h3>\n<p>Method\u7c7b\u7528\u4e8e\u8868\u793a\u548c\u64cd\u4f5c\u7c7b\u7684\u65b9\u6cd5&#xff0c;\u901a\u8fc7\u53cd\u5c04\u53ef\u4ee5\u8c03\u7528\u7c7b\u7684\u4efb\u610f\u65b9\u6cd5&#xff08;\u5305\u62ec\u79c1\u6709\u65b9\u6cd5&#xff09;\u3002<\/p>\n<p>import java.lang.reflect.InvocationTargetException;<br \/>\nimport java.lang.reflect.Method;<\/p>\n<p>public class MethodReflectionDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            \/\/ \u83b7\u53d6Class\u5bf9\u8c61\u548c\u5b9e\u4f8b<br \/>\n            Class&lt;?&gt; clazz &#061; Class.forName(&#034;com.example.User&#034;);<br \/>\n            User user &#061; (User) clazz.getConstructor().newInstance();<\/p>\n<p>            \/\/ 1. \u83b7\u53d6\u5e76\u8c03\u7528public\u65b9\u6cd5&#xff08;setUsername&#xff09;<br \/>\n            \/\/ \u53c2\u6570&#xff1a;\u65b9\u6cd5\u540d&#xff0c;\u53c2\u6570\u7c7b\u578b.class<br \/>\n            Method setUsernameMethod &#061; clazz.getMethod(&#034;setUsername&#034;, String.class);<br \/>\n            \/\/ \u8c03\u7528\u65b9\u6cd5&#xff1a;invoke(\u5bf9\u8c61, \u53c2\u6570\u503c)<br \/>\n            setUsernameMethod.invoke(user, &#034;\u8d75\u516d&#034;);<\/p>\n<p>            \/\/ \u83b7\u53d6getUsername\u65b9\u6cd5\u5e76\u8c03\u7528<br \/>\n            Method getUsernameMethod &#061; clazz.getMethod(&#034;getUsername&#034;);<br \/>\n            String username &#061; (String) getUsernameMethod.invoke(user);<br \/>\n            System.out.println(&#034;\u7528\u6237\u540d&#xff1a;&#034; &#043; username);<\/p>\n<p>            \/\/ 2. \u8c03\u7528\u6709\u591a\u4e2a\u53c2\u6570\u7684\u65b9\u6cd5<br \/>\n            Method setAgeMethod &#061; clazz.getMethod(&#034;setAge&#034;, int.class);<br \/>\n            setAgeMethod.invoke(user, 28);<\/p>\n<p>            \/\/ 3. \u8c03\u7528\u79c1\u6709\u65b9\u6cd5&#xff08;\u5047\u8bbeUser\u7c7b\u6709\u4e00\u4e2a\u79c1\u6709\u65b9\u6cd5&#xff09;<br \/>\n            \/\/ \u5148\u5728User\u7c7b\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u79c1\u6709\u65b9\u6cd5&#xff1a;<br \/>\n            \/\/ private void showInfo() {<br \/>\n            \/\/     System.out.println(&#034;\u7528\u6237\u540d&#xff1a;&#034; &#043; username &#043; &#034;, \u5e74\u9f84&#xff1a;&#034; &#043; age);<br \/>\n            \/\/ }<\/p>\n<p>            Method showInfoMethod &#061; clazz.getDeclaredMethod(&#034;showInfo&#034;);<br \/>\n            showInfoMethod.setAccessible(true); \/\/ \u66b4\u529b\u8bbf\u95ee\u79c1\u6709\u65b9\u6cd5<br \/>\n            showInfoMethod.invoke(user); \/\/ \u8c03\u7528\u79c1\u6709\u65b9\u6cd5<\/p>\n<p>        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |<br \/>\n                 IllegalAccessException | InvocationTargetException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5173\u952e\u65b9\u6cd5\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>getMethod(String name, Class&lt;?&gt;&#8230; parameterTypes)&#xff1a;\u83b7\u53d6 public \u4fee\u9970\u7684\u65b9\u6cd5<\/li>\n<li>getDeclaredMethod(String name, Class&lt;?&gt;&#8230; parameterTypes)&#xff1a;\u83b7\u53d6\u6240\u6709\u65b9\u6cd5&#xff08;\u5305\u62ec private&#xff09;<\/li>\n<li>invoke(Object obj, Object&#8230; args)&#xff1a;\u8c03\u7528\u65b9\u6cd5&#xff0c;\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u5bf9\u8c61\u5b9e\u4f8b&#xff08;\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u4e3a null&#xff09;<\/li>\n<li>setAccessible(true)&#xff1a;\u540c\u6837\u9002\u7528\u4e8e\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u8bbf\u95ee\u79c1\u6709\u65b9\u6cd5<\/li>\n<\/ul>\n<h3>\u901a\u8fc7\u53cd\u5c04\u64cd\u4f5c\u7c7b\u7684\u5c5e\u6027<\/h3>\n<p>Field\u7c7b\u7528\u4e8e\u8868\u793a\u548c\u64cd\u4f5c\u7c7b\u7684\u5c5e\u6027&#xff0c;\u901a\u8fc7\u53cd\u5c04\u53ef\u4ee5\u83b7\u53d6\u548c\u4fee\u6539\u7c7b\u7684\u4efb\u610f\u5c5e\u6027&#xff08;\u5305\u62ec\u79c1\u6709\u5c5e\u6027&#xff09;\u3002<\/p>\n<p>import java.lang.reflect.Field;<\/p>\n<p>public class FieldReflectionDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            \/\/ \u521b\u5efaUser\u5bf9\u8c61<br \/>\n            User user &#061; new User(&#034;\u5b59\u4e03&#034;, 35);<br \/>\n            Class&lt;?&gt; clazz &#061; user.getClass();<\/p>\n<p>            \/\/ 1. \u83b7\u53d6\u5e76\u4fee\u6539public\u5c5e\u6027&#xff08;\u5982\u679c\u6709\u7684\u8bdd&#xff09;<br \/>\n            \/\/ \u5047\u8bbeUser\u6709public\u5c5e\u6027&#xff1a;public String address;<br \/>\n            \/\/ Field addressField &#061; clazz.getField(&#034;address&#034;);<br \/>\n            \/\/ addressField.set(user, &#034;\u5317\u4eac\u5e02&#034;); \/\/ \u8bbe\u7f6e\u5c5e\u6027\u503c<br \/>\n            \/\/ String address &#061; (String) addressField.get(user); \/\/ \u83b7\u53d6\u5c5e\u6027\u503c<\/p>\n<p>            \/\/ 2. \u83b7\u53d6\u5e76\u4fee\u6539private\u5c5e\u6027&#xff08;username&#xff09;<br \/>\n            Field usernameField &#061; clazz.getDeclaredField(&#034;username&#034;);<br \/>\n            usernameField.setAccessible(true); \/\/ \u66b4\u529b\u8bbf\u95ee\u79c1\u6709\u5c5e\u6027<\/p>\n<p>            \/\/ \u83b7\u53d6\u5c5e\u6027\u503c<br \/>\n            String username &#061; (String) usernameField.get(user);<br \/>\n            System.out.println(&#034;\u4fee\u6539\u524d\u7684\u7528\u6237\u540d&#xff1a;&#034; &#043; username);<\/p>\n<p>            \/\/ \u4fee\u6539\u5c5e\u6027\u503c<br \/>\n            usernameField.set(user, &#034;\u5b59\u4e03_\u4fee\u6539\u540e&#034;);<br \/>\n            System.out.println(&#034;\u4fee\u6539\u540e\u7684\u7528\u6237\u540d&#xff1a;&#034; &#043; user.getUsername());<\/p>\n<p>            \/\/ 3. \u83b7\u53d6\u5e76\u4fee\u6539private\u5c5e\u6027&#xff08;age&#xff09;<br \/>\n            Field ageField &#061; clazz.getDeclaredField(&#034;age&#034;);<br \/>\n            ageField.setAccessible(true);<br \/>\n            ageField.set(user, 36); \/\/ \u4fee\u6539\u5e74\u9f84<br \/>\n            System.out.println(&#034;\u4fee\u6539\u540e\u7684\u5e74\u9f84&#xff1a;&#034; &#043; user.getAge());<\/p>\n<p>            \/\/ 4. \u83b7\u53d6\u9759\u6001\u5c5e\u6027&#xff08;\u5982\u679c\u6709\u7684\u8bdd&#xff09;<br \/>\n            \/\/ \u5047\u8bbeUser\u6709\u9759\u6001\u5c5e\u6027&#xff1a;public static String version;<br \/>\n            \/\/ Field versionField &#061; clazz.getField(&#034;version&#034;);<br \/>\n            \/\/ versionField.set(null, &#034;1.0.0&#034;); \/\/ \u9759\u6001\u5c5e\u6027&#xff0c;\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3anull<br \/>\n            \/\/ String version &#061; (String) versionField.get(null);<\/p>\n<p>        } catch (NoSuchFieldException | IllegalAccessException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5173\u952e\u65b9\u6cd5\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>getField(String name)&#xff1a;\u83b7\u53d6 public \u4fee\u9970\u7684\u5c5e\u6027<\/li>\n<li>getDeclaredField(String name)&#xff1a;\u83b7\u53d6\u6240\u6709\u5c5e\u6027&#xff08;\u5305\u62ec private&#xff09;<\/li>\n<li>get(Object obj)&#xff1a;\u83b7\u53d6\u5c5e\u6027\u503c<\/li>\n<li>set(Object obj, Object value)&#xff1a;\u8bbe\u7f6e\u5c5e\u6027\u503c&#xff08;\u9759\u6001\u5c5e\u6027\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a null&#xff09;<\/li>\n<li>setAccessible(true)&#xff1a;\u7528\u4e8e\u8bbf\u95ee\u79c1\u6709\u5c5e\u6027<\/li>\n<\/ul>\n<h3>\u53cd\u5c04\u4e0e\u6ce8\u89e3\u7ed3\u5408<\/h3>\n<p>\u6ce8\u89e3&#xff08;Annotation&#xff09;\u662f Java 5 &#043; \u5f15\u5165\u7684\u7279\u6027&#xff0c;\u4e0e\u53cd\u5c04\u7ed3\u5408\u53ef\u4ee5\u5b9e\u73b0\u5f3a\u5927\u7684\u529f\u80fd&#xff08;\u5982 Spring \u7684&#064;Autowired\u3001MyBatis \u7684&#064;Select&#xff09;\u3002<\/p>\n<h4>\u793a\u4f8b&#xff1a;\u81ea\u5b9a\u4e49\u6ce8\u89e3\u4e0e\u53cd\u5c04\u89e3\u6790<\/h4>\n<p>import java.lang.annotation.*;<br \/>\nimport java.lang.reflect.Field;<\/p>\n<p>\/\/ 1. \u5b9a\u4e49\u81ea\u5b9a\u4e49\u6ce8\u89e3<br \/>\n&#064;Target(ElementType.FIELD) \/\/ \u6ce8\u89e3\u4f5c\u7528\u5728\u5c5e\u6027\u4e0a<br \/>\n&#064;Retention(RetentionPolicy.RUNTIME) \/\/ \u6ce8\u89e3\u4fdd\u7559\u5230\u8fd0\u884c\u65f6&#xff08;\u53cd\u5c04\u53ef\u89c1&#xff09;<br \/>\npublic &#064;interface Column {<br \/>\n    String name(); \/\/ \u6570\u636e\u5e93\u5217\u540d<br \/>\n    boolean nullable() default true; \/\/ \u662f\u5426\u5141\u8bb8\u4e3anull<br \/>\n}<\/p>\n<p>\/\/ 2. \u4f7f\u7528\u6ce8\u89e3\u7684\u5b9e\u4f53\u7c7b<br \/>\nclass User {<br \/>\n    &#064;Column(name &#061; &#034;user_name&#034;, nullable &#061; false)<br \/>\n    private String username;<\/p>\n<p>    &#064;Column(name &#061; &#034;user_age&#034;)<br \/>\n    private int age;<\/p>\n<p>    private String email; \/\/ \u6ca1\u6709\u6ce8\u89e3<\/p>\n<p>    \/\/ \u6784\u9020\u65b9\u6cd5\u3001getter\u3001setter\u7701\u7565<br \/>\n    public User(String username, int age) {<br \/>\n        this.username &#061; username;<br \/>\n        this.age &#061; age;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ 3. \u901a\u8fc7\u53cd\u5c04\u89e3\u6790\u6ce8\u89e3<br \/>\npublic class AnnotationReflectionDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        try {<br \/>\n            Class&lt;?&gt; clazz &#061; User.class;<br \/>\n            \/\/ \u83b7\u53d6\u6240\u6709\u5c5e\u6027<br \/>\n            Field[] fields &#061; clazz.getDeclaredFields();<\/p>\n<p>            System.out.println(&#034;\u89e3\u6790User\u7c7b\u7684\u6ce8\u89e3\u4fe1\u606f&#xff1a;&#034;);<br \/>\n            for (Field field : fields) {<br \/>\n                \/\/ \u5224\u65ad\u5c5e\u6027\u662f\u5426\u6709&#064;Column\u6ce8\u89e3<br \/>\n                if (field.isAnnotationPresent(Column.class)) {<br \/>\n                    \/\/ \u83b7\u53d6\u6ce8\u89e3\u5b9e\u4f8b<br \/>\n                    Column column &#061; field.getAnnotation(Column.class);<\/p>\n<p>                    System.out.println(&#034;\u5c5e\u6027\u540d&#xff1a;&#034; &#043; field.getName());<br \/>\n                    System.out.println(&#034;\u6570\u636e\u5e93\u5217\u540d&#xff1a;&#034; &#043; column.name());<br \/>\n                    System.out.println(&#034;\u662f\u5426\u5141\u8bb8\u4e3anull&#xff1a;&#034; &#043; column.nullable());<br \/>\n                    System.out.println(&#034;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#034;);<br \/>\n                } else {<br \/>\n                    System.out.println(&#034;\u5c5e\u6027\u540d&#xff1a;&#034; &#043; field.getName() &#043; &#034;&#xff08;\u65e0&#064;Column\u6ce8\u89e3&#xff09;&#034;);<br \/>\n                    System.out.println(&#034;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#034;);<br \/>\n                }<br \/>\n            }<\/p>\n<p>        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u89e3\u6790User\u7c7b\u7684\u6ce8\u89e3\u4fe1\u606f&#xff1a;<br \/>\n\u5c5e\u6027\u540d&#xff1a;username<br \/>\n\u6570\u636e\u5e93\u5217\u540d&#xff1a;user_name<br \/>\n\u662f\u5426\u5141\u8bb8\u4e3anull&#xff1a;false<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n\u5c5e\u6027\u540d&#xff1a;age<br \/>\n\u6570\u636e\u5e93\u5217\u540d&#xff1a;user_age<br \/>\n\u662f\u5426\u5141\u8bb8\u4e3anull&#xff1a;true<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n\u5c5e\u6027\u540d&#xff1a;email&#xff08;\u65e0&#064;Column\u6ce8\u89e3&#xff09;<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u662f ORM \u6846\u67b6&#xff08;\u5982 MyBatis&#xff09;\u5b9e\u73b0\u5bf9\u8c61\u4e0e\u6570\u636e\u5e93\u8868\u6620\u5c04\u7684\u6838\u5fc3\u539f\u7406&#xff1a;\u901a\u8fc7\u6ce8\u89e3\u6807\u8bb0\u5c5e\u6027\u4e0e\u5217\u7684\u6620\u5c04\u5173\u7cfb&#xff0c;\u518d\u901a\u8fc7\u53cd\u5c04\u89e3\u6790\u6ce8\u89e3\u751f\u6210 SQL \u8bed\u53e5\u3002<\/p>\n<h3>\u53cd\u5c04\u7684\u4f18\u7f3a\u70b9<\/h3>\n<h4>\u4f18\u70b9<\/h4>\n<li>\u7075\u6d3b\u6027\u9ad8&#xff1a;\u7a81\u7834\u7f16\u8bd1\u671f\u9650\u5236&#xff0c;\u80fd\u591f\u52a8\u6001\u64cd\u4f5c\u7c7b\u548c\u5bf9\u8c61<\/li>\n<li>\u89e3\u8026&#xff1a;\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6&#xff08;\u5982 XML&#xff09;\u6307\u5b9a\u7c7b\u540d&#xff0c;\u65e0\u9700\u786c\u7f16\u7801&#xff0c;\u4fbf\u4e8e\u6269\u5c55<\/li>\n<li>\u6846\u67b6\u57fa\u7840&#xff1a;\u662f\u4e3b\u6d41\u6846\u67b6&#xff08;Spring\u3001MyBatis \u7b49&#xff09;\u7684\u6838\u5fc3\u6280\u672f<\/li>\n<li>\u53ef\u6269\u5c55\u6027\u5f3a&#xff1a;\u53ef\u4ee5\u5728\u4e0d\u4fee\u6539\u539f\u6709\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u6269\u5c55\u529f\u80fd<\/li>\n<h4>\u7f3a\u70b9<\/h4>\n<li>\u6027\u80fd\u5f00\u9500&#xff1a;\u53cd\u5c04\u64cd\u4f5c\u9700\u8981\u89e3\u6790\u5b57\u8282\u7801&#xff0c;\u6027\u80fd\u6bd4\u76f4\u63a5\u8c03\u7528\u4f4e&#xff08;\u7ea6\u6162 10-100 \u500d&#xff09;<\/li>\n<li>\u5b89\u5168\u6027\u95ee\u9898&#xff1a;\u53ef\u4ee5\u8bbf\u95ee\u79c1\u6709\u6210\u5458&#xff0c;\u7834\u574f\u5c01\u88c5\u6027<\/li>\n<li>\u4ee3\u7801\u53ef\u8bfb\u6027\u5dee&#xff1a;\u53cd\u5c04\u4ee3\u7801\u8f83\u590d\u6742&#xff0c;\u4e0d\u5982\u76f4\u63a5\u8c03\u7528\u76f4\u89c2<\/li>\n<li>\u7f16\u8bd1\u671f\u68c0\u67e5\u7f3a\u5931&#xff1a;\u9519\u8bef\u53ea\u80fd\u5728\u8fd0\u884c\u65f6\u53d1\u73b0<\/li>\n<p>\u4f18\u5316\u53cd\u5c04\u6027\u80fd\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\u7f13\u5b58Class\u3001Method\u3001Field\u7b49\u5bf9\u8c61&#xff0c;\u907f\u514d\u9891\u7e41\u83b7\u53d6<\/li>\n<li>\u5c3d\u91cf\u4f7f\u7528setAccessible(true)\u5173\u95ed\u8bbf\u95ee\u68c0\u67e5&#xff08;\u53ef\u63d0\u5347\u6027\u80fd&#xff09;<\/li>\n<li>\u975e\u5fc5\u8981\u573a\u666f\u907f\u514d\u4f7f\u7528\u53cd\u5c04<\/li>\n<\/ul>\n<h3>\u53cd\u5c04\u5728 JavaWeb \u4e2d\u7684\u5e94\u7528<\/h3>\n<p>\u53cd\u5c04\u662f JavaWeb \u5f00\u53d1\u7684\u6838\u5fc3\u6280\u672f\u4e4b\u4e00&#xff0c;\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5178\u578b\u5e94\u7528\u573a\u666f&#xff1a;<\/p>\n<h4>1. Servlet \u5bb9\u5668\u521d\u59cb\u5316<\/h4>\n<p>Tomcat \u7b49 Servlet \u5bb9\u5668\u901a\u8fc7\u53cd\u5c04\u521d\u59cb\u5316 Servlet&#xff1a;<\/p>\n<p>\/\/ Tomcat\u5185\u90e8\u5de5\u4f5c\u539f\u7406\u7b80\u5316<br \/>\npublic class ServletContainer {<br \/>\n    public void initServlet(String servletClassName) {<br \/>\n        try {<br \/>\n            \/\/ 1. \u901a\u8fc7\u7c7b\u540d\u52a0\u8f7dServlet\u7c7b<br \/>\n            Class&lt;?&gt; servletClass &#061; Class.forName(servletClassName);<\/p>\n<p>            \/\/ 2. \u5b9e\u4f8b\u5316Servlet<br \/>\n            Object servlet &#061; servletClass.getConstructor().newInstance();<\/p>\n<p>            \/\/ 3. \u8c03\u7528init\u65b9\u6cd5<br \/>\n            Method initMethod &#061; servletClass.getMethod(&#034;init&#034;, ServletConfig.class);<br \/>\n            initMethod.invoke(servlet, new MyServletConfig());<\/p>\n<p>            System.out.println(&#034;Servlet\u521d\u59cb\u5316\u5b8c\u6210&#xff1a;&#034; &#043; servletClassName);<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h4>2. Spring IOC \u5bb9\u5668<\/h4>\n<p>Spring \u7684 IOC&#xff08;\u63a7\u5236\u53cd\u8f6c&#xff09;\u5bb9\u5668\u901a\u8fc7\u53cd\u5c04\u521b\u5efa\u548c\u7ba1\u7406 Bean&#xff1a;<\/p>\n<p>&lt;!&#8211; Spring\u914d\u7f6e\u6587\u4ef6 &#8211;&gt;<br \/>\n&lt;bean id&#061;&#034;userService&#034; class&#061;&#034;com.example.UserService&#034;&gt;<br \/>\n    &lt;property name&#061;&#034;userDao&#034; ref&#061;&#034;userDao&#034;\/&gt;<br \/>\n&lt;\/bean&gt;<\/p>\n<p>Spring \u5bb9\u5668\u89e3\u6790\u914d\u7f6e\u6587\u4ef6&#xff0c;\u901a\u8fc7\u53cd\u5c04\u521b\u5efaUserService\u5b9e\u4f8b&#xff0c;\u5e76\u8c03\u7528setUserDao\u65b9\u6cd5\u6ce8\u5165\u4f9d\u8d56\u3002<\/p>\n<h4>3. \u81ea\u5b9a\u4e49 MVC \u6846\u67b6<\/h4>\n<p>\u7b80\u5355 MVC \u6846\u67b6\u901a\u8fc7\u53cd\u5c04\u5904\u7406\u8bf7\u6c42&#xff1a;<\/p>\n<p>\/\/ \u7b80\u5316\u7684\u63a7\u5236\u5668<br \/>\n&#064;Controller<br \/>\npublic class UserController {<br \/>\n    &#064;RequestMapping(&#034;\/user\/list&#034;)<br \/>\n    public String listUsers() {<br \/>\n        \/\/ \u5904\u7406\u7528\u6237\u5217\u8868\u8bf7\u6c42<br \/>\n        return &#034;userList&#034;;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u6846\u67b6\u901a\u8fc7\u53cd\u5c04\u89e3\u6790&#064;RequestMapping\u6ce8\u89e3<br \/>\npublic class DispatcherServlet {<br \/>\n    public void doGet(HttpServletRequest request, HttpServletResponse response) {<br \/>\n        String path &#061; request.getRequestURI(); \/\/ \u83b7\u53d6\u8bf7\u6c42\u8def\u5f84<\/p>\n<p>        \/\/ \u626b\u63cf\u6240\u6709&#064;Controller\u7c7b<br \/>\n        for (Class&lt;?&gt; clazz : controllerClasses) {<br \/>\n            \/\/ \u89e3\u6790&#064;RequestMapping\u6ce8\u89e3&#xff0c;\u627e\u5230\u5339\u914d\u7684\u65b9\u6cd5<br \/>\n            for (Method method : clazz.getDeclaredMethods()) {<br \/>\n                if (method.isAnnotationPresent(RequestMapping.class)) {<br \/>\n                    RequestMapping mapping &#061; method.getAnnotation(RequestMapping.class);<br \/>\n                    if (mapping.value().equals(path)) {<br \/>\n                        \/\/ \u53cd\u5c04\u8c03\u7528\u65b9\u6cd5\u5904\u7406\u8bf7\u6c42<br \/>\n                        Object controller &#061; clazz.getConstructor().newInstance();<br \/>\n                        String view &#061; (String) method.invoke(controller);<br \/>\n                        \/\/ \u8f6c\u53d1\u5230\u89c6\u56fe<br \/>\n                        request.getRequestDispatcher(view &#043; &#034;.jsp&#034;).forward(request, response);<br \/>\n                        return;<br \/>\n                    }<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u603b\u7ed3\u4e0e\u5b9e\u8df5<\/h3>\n<h4>\u77e5\u8bc6\u70b9\u56de\u987e<\/h4>\n<li>\u53cd\u5c04\u673a\u5236&#xff1a;\u7a0b\u5e8f\u8fd0\u884c\u65f6\u83b7\u53d6\u7c7b\u4fe1\u606f\u5e76\u64cd\u4f5c\u7c7b\u6210\u5458\u7684\u80fd\u529b<\/li>\n<li>\u6838\u5fc3\u7c7b&#xff1a;Class&#xff08;\u5165\u53e3&#xff09;\u3001Constructor&#xff08;\u6784\u9020\u65b9\u6cd5&#xff09;\u3001Method&#xff08;\u65b9\u6cd5&#xff09;\u3001Field&#xff08;\u5c5e\u6027&#xff09;<\/li>\n<li>\u83b7\u53d6 Class \u5bf9\u8c61\u7684\u65b9\u5f0f&#xff1a;Class.forName()\u3001\u7c7b\u540d.class\u3001\u5bf9\u8c61.getClass()<\/li>\n<li>\u53cd\u5c04\u64cd\u4f5c&#xff1a;\n<ul>\n<li>\u521b\u5efa\u5bf9\u8c61&#xff1a;\u901a\u8fc7Constructor.newInstance()<\/li>\n<li>\u8c03\u7528\u65b9\u6cd5&#xff1a;\u901a\u8fc7Method.invoke()<\/li>\n<li>\u64cd\u4f5c\u5c5e\u6027&#xff1a;\u901a\u8fc7Field.get()\u548cField.set()<\/li>\n<\/ul>\n<\/li>\n<li>\u4e0e\u6ce8\u89e3\u7ed3\u5408&#xff1a;\u901a\u8fc7\u53cd\u5c04\u89e3\u6790\u6ce8\u89e3&#xff0c;\u5b9e\u73b0\u7075\u6d3b\u914d\u7f6e<\/li>\n<li>\u4f18\u7f3a\u70b9&#xff1a;\u7075\u6d3b\u6027\u9ad8\u4f46\u6027\u80fd\u6709\u5f00\u9500&#xff0c;\u662f\u6846\u67b6\u5f00\u53d1\u7684\u57fa\u7840<\/li>\n<h4>\u5b9e\u8df5\u4efb\u52a1<\/h4>\n<li>\n<p>\u7b80\u6613 ORM \u5de5\u5177&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa&#064;Table\u6ce8\u89e3&#xff08;\u6807\u8bb0\u7c7b\u4e0e\u6570\u636e\u5e93\u8868\u7684\u6620\u5c04&#xff09;<\/li>\n<li>\u521b\u5efa&#064;Column\u6ce8\u89e3&#xff08;\u6807\u8bb0\u5c5e\u6027\u4e0e\u8868\u5b57\u6bb5\u7684\u6620\u5c04&#xff09;<\/li>\n<li>\u7f16\u5199SqlGenerator\u7c7b&#xff0c;\u901a\u8fc7\u53cd\u5c04\u89e3\u6790\u5e26\u6ce8\u89e3\u7684\u5b9e\u4f53\u7c7b<\/li>\n<li>\u751f\u6210\u63d2\u5165\u6570\u636e\u7684 SQL \u8bed\u53e5&#xff08;\u5982INSERT INTO user (user_name, age) VALUES (?, ?)&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u52a8\u6001\u4ee3\u7406\u5b9e\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efaUserService\u63a5\u53e3\u548cUserServiceImpl\u5b9e\u73b0\u7c7b<\/li>\n<li>\u4f7f\u7528InvocationHandler\u548c\u53cd\u5c04\u5b9e\u73b0\u52a8\u6001\u4ee3\u7406<\/li>\n<li>\u5728\u4ee3\u7406\u4e2d\u6dfb\u52a0\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd&#xff08;\u8c03\u7528\u65b9\u6cd5\u524d\u6253\u5370 \u201c\u5f00\u59cb\u6267\u884c\u201d&#xff0c;\u8c03\u7528\u540e\u6253\u5370 \u201c\u6267\u884c\u7ed3\u675f\u201d&#xff09;<\/li>\n<\/ul>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb265\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf5\u6b21\u3002Java\u53cd\u5c04\u673a\u5236\u5141\u8bb8\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u83b7\u53d6\u7c7b\u4fe1\u606f\u5e76\u64cd\u4f5c\u7c7b\u6210\u5458\uff08\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u6784\u9020\u5668\u7b49\uff09\uff0c\u662fJava\u6846\u67b6\u8bbe\u8ba1\u7684\u6838\u5fc3\u6280\u672f\u3002\u901a\u8fc7java.lang.reflect\u5305\u7684Class\u3001Constructor\u3001Method\u548cField\u7b49\u6838\u5fc3\u7c7b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u521b\u5efa\u5bf9\u8c61\u3001\u8c03\u7528\u65b9\u6cd5\u3001\u4fee\u6539\u5c5e\u6027\u7b49\u64cd\u4f5c\u3002<\/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":[99,1056,1423,98,371,190],"topic":[],"class_list":["post-58382","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-javaweb","tag-mvc","tag-spring-boot","tag-371","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \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\/58382.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb265\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf5\u6b21\u3002Java\u53cd\u5c04\u673a\u5236\u5141\u8bb8\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u83b7\u53d6\u7c7b\u4fe1\u606f\u5e76\u64cd\u4f5c\u7c7b\u6210\u5458\uff08\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u6784\u9020\u5668\u7b49\uff09\uff0c\u662fJava\u6846\u67b6\u8bbe\u8ba1\u7684\u6838\u5fc3\u6280\u672f\u3002\u901a\u8fc7java.lang.reflect\u5305\u7684Class\u3001Constructor\u3001Method\u548cField\u7b49\u6838\u5fc3\u7c7b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u521b\u5efa\u5bf9\u8c61\u3001\u8c03\u7528\u65b9\u6cd5\u3001\u4fee\u6539\u5c5e\u6027\u7b49\u64cd\u4f5c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/58382.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-16T01:04:41+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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58382.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/58382.html\",\"name\":\"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-16T01:04:41+00:00\",\"dateModified\":\"2025-08-16T01:04:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/58382.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/58382.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58382.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3\"}]},{\"@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":"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \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\/58382.html","og_locale":"zh_CN","og_type":"article","og_title":"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb265\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf5\u6b21\u3002Java\u53cd\u5c04\u673a\u5236\u5141\u8bb8\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u83b7\u53d6\u7c7b\u4fe1\u606f\u5e76\u64cd\u4f5c\u7c7b\u6210\u5458\uff08\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u6784\u9020\u5668\u7b49\uff09\uff0c\u662fJava\u6846\u67b6\u8bbe\u8ba1\u7684\u6838\u5fc3\u6280\u672f\u3002\u901a\u8fc7java.lang.reflect\u5305\u7684Class\u3001Constructor\u3001Method\u548cField\u7b49\u6838\u5fc3\u7c7b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u521b\u5efa\u5bf9\u8c61\u3001\u8c03\u7528\u65b9\u6cd5\u3001\u4fee\u6539\u5c5e\u6027\u7b49\u64cd\u4f5c\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/58382.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-16T01:04:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/58382.html","url":"https:\/\/www.wsisp.com\/helps\/58382.html","name":"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-16T01:04:41+00:00","dateModified":"2025-08-16T01:04:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/58382.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/58382.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/58382.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"JavaWeb 30 \u5929\u5165\u95e8\uff1a\u7b2c\u5341\u4e00\u5929 \u2014\u2014Java \u53cd\u5c04\u673a\u5236\u8be6\u89e3"}]},{"@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\/58382","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=58382"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/58382\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=58382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=58382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=58382"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=58382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}