{"id":152,"date":"2020-07-28T17:27:10","date_gmt":"2020-07-28T09:27:10","guid":{"rendered":"http:\/\/121.89.208.222\/?p=152"},"modified":"2020-12-10T14:23:35","modified_gmt":"2020-12-10T06:23:35","slug":"java%e9%80%9a%e8%bf%87%e5%8f%8d%e5%b0%84%e8%8e%b7%e5%8f%96%e6%96%b9%e6%b3%95%e7%9a%84%e8%bf%94%e5%9b%9e%e5%80%bc%e7%9a%84%e7%b1%bb%e5%9e%8b%e4%bb%a5%e5%8f%8a%e5%8f%82%e6%95%b0%e5%8c%96%e7%9a%84","status":"publish","type":"post","link":"http:\/\/moyisuiying.com\/index.php\/javastudy\/152.html","title":{"rendered":"Java\u901a\u8fc7\u53cd\u5c04\u83b7\u53d6\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u4ee5\u53ca\u53c2\u6570\u5316\u7684\u5b9e\u9645\u7c7b\u578b\uff08\u4e0b\u7bc7\uff09"},"content":{"rendered":"\n<p>\u7b14\u8005\u6700\u8fd1\u5728\u5b66\u4e60mybatis\u7684\u6846\u67b6\uff0c\u5728\u5199\u6e90\u7801\u7684\u65f6\u5019\u9047\u5230\u4e86\u4e00\u4e9b\u5173\u4e8e\u901a\u8fc7\u53cd\u5c04\u83b7\u53d6\u8fd4\u56de\u503c\u7c7b\u578b\u7684\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u7684\u95ee\u9898\uff0c\u5e76\u4e14\u5df2\u7ecf\u5199\u6709\u4e00\u7bc7\u5173\u4e8e\u7b80\u5355\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u7684\u83b7\u53d6\uff0c\u8bf8\u5982public User getOne(int id);\u83b7\u53d6\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u662fUser\uff0cpublic List&lt; User > getAll();\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662fList&lt; User >,\u5176\u53c2\u6570\u5316\u7c7b\u578b\u6570\u7ec4\u662f {User},\u4e5f\u5c31\u662f\u53c2\u6570\u5316\u7c7b\u578b\u662f&lt;> \u91cc\u9762\u5305\u542b\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u6bd4\u5982public Map getAll();\u7684\u8fd4\u56de\u503c\u662fMap\uff0c\u5176\u53c2\u6570\u5316\u7c7b\u578b\u6570\u7ec4\u662f {String,Integer}\uff0c\u5177\u4f53\u53ef\u53c2\u8003\u7b14\u8005\u4e4b\u524d\u5199\u7684\u6587\u7ae0\uff1a<a href=\"http:\/\/moyisuiying.com\/index.php\/javastudy\/170.html\">Java\u901a\u8fc7\u53cd\u5c04\u83b7\u53d6\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u4ee5\u53ca\u53c2\u6570\u5316\u7684\u5b9e\u9645\u7c7b\u578b\uff08\u4e0a\u7bc7\uff09<\/a><br>\u8be5\u6587\u7ae0\u5bf9\u4e00\u4e9b\u7b80\u5355\u7684\u8fd4\u56de\u503c\u7684\u53c2\u6570\u7c7b\u578b\u6709\u4e86\u6bd4\u8f83\u8be6\u7ec6\u7684\u8bb2\u89e3\uff0c\u90a3\u4e48\u5bf9\u4e8e\u66f4\u52a0\u8d1f\u8d23\u7684\u53c2\u6570\u5316\u7c7b\u578b\uff0c\u6bd4\u5982public Map&lt; T,V > getAll()\u4e2d\uff0c\u5047\u82e5\u5728\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u8fd9\u4e2aT\u4e3aDog.java\u7c7b\uff0cV\u4e3aCat.java\u7c7b\uff0c\u90a3\u4e48\u5728\u83b7\u53d6\u5176\u8fd4\u56de\u503c\u53c2\u6570\u5316\u6570\u7ec4\u7684\u5b9e\u9645\u7c7b\u578b\u65f6\uff0c\u5176\u53c2\u6570\u5316\u6570\u7ec4\u4e3a {Dog,Cat}\uff0c\u5bf9\u5e94\u7684\u5168\u9650\u5b9a\u7c7b\u540d\u4e3a\uff1a\uff5bentity.Dog,entity.Cat},\u6bd4\u8f83\u590d\u6742\u7684\u8be5\u600e\u4e48\u83b7\u53d6\u5462\uff1f\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u51e0\u4e2a\u5c0f\u4f8b\u5b50\u8fdb\u884c\u8be6\u7ec6\u8bb2\u89e3\u3002<br>1.\u9996\u5148\u5efa\u7acb\u7528\u4e8e\u6d4b\u8bd5\u7684StudentDao.java\u63a5\u53e3\u4ee5\u53ca\u5176\u5b9e\u73b0\u7c7bStudentDaoImpl.java\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package dao;\n\nimport java.util.Map;\n\n\/**\n * @author \u964c\u610f\u968f\u5f71\n TODO :\u5b66\u751fdao\u6d4b\u8bd5\u7c7b\n *2020\u5e747\u670826\u65e5  \u4e0b\u534811:02:10\n *\/\npublic interface StudentDao&lt;T,V> {\n    \/**\n     * \u83b7\u53d6\u6240\u6709\u5bf9\u8c61\n     * @return \u8fd4\u56de\u4e00\u4e2amap\n     *\/\n    public Map&lt;T,V> getAll();\n    \/**\n     * \u83b7\u53d6\u4e00\u4e2aT\u5bf9\u8c61\n     * @return \u8fd4\u56deT\n     *\/\n    public T getT();\n    \/**\n     * \u83b7\u53d6\u4e00\u4e2aV\u5bf9\u8c61\n     * @return \u8fd4\u56deV\n     *\/\n    public  V getV();\n\n}<\/code><\/pre>\n\n\n\n<p>\u8be5\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7bStudentDaoImpl.java\u7684\u6e90\u7801\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package dao;\n\nimport java.util.List;\nimport java.util.Map;\n\n\/**\n * @author \u964c\u610f\u968f\u5f71\n TODO :\u5b66\u751fdao\u6d4b\u8bd5\u7c7b\n *2020\u5e747\u670826\u65e5  \u4e0b\u534811:02:10\n *\/\npublic interface StudentDao&lt;T,V> {\n    \/**\n     * \u83b7\u53d6\u6240\u6709\u5bf9\u8c61\n     * @return \u8fd4\u56de\u4e00\u4e2amap\n     *\/\n    public Map&lt;T,V> getAll();\n    \/**\n     * \u83b7\u53d6\u4e00\u4e2aT\u5bf9\u8c61\n     * @return \u8fd4\u56deT\n     *\/\n    public T getT();\n    \/**\n     * \u83b7\u53d6\u4e00\u4e2aV\u5bf9\u8c61\n     * @return \u8fd4\u56deV\n     *\/\n    public  V getV();\n    \/**\n     * @return \u8fd4\u56deT\u7684\u96c6\u5408\n     *\/\n    public List&lt;T> getAllT();\n\n}<\/code><\/pre>\n\n\n\n<p>2.\u6211\u4eec\u53c2\u8003\u7740\u4e0a\u4e00\u7bc7\uff1a<a href=\"http:\/\/moyisuiying.com\/index.php\/javastudy\/170.html\">Java\u901a\u8fc7\u53cd\u5c04\u83b7\u53d6\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u4ee5\u53ca\u53c2\u6570\u5316\u7684\u5b9e\u9645\u7c7b\u578b\uff08\u4e0a\u7bc7\uff09<\/a>\u6765\u8fdb\u884c\u6d4b\u8bd5\u770b\u770b\u662f\u5426\u80fd\u83b7\u53d6\u6211\u4eec\u60f3\u8981\u7684\u7ed3\u679c\u3002\u9996\u5148\u5efa\u7acb\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package test;\n\nimport java.lang.reflect.Method;\nimport java.lang.reflect.ParameterizedType;\nimport java.lang.reflect.Type;\n\nimport org.junit.jupiter.api.Test;\n\nimport dao.StudentDao;\nimport dao.StudentDaoImpl;\nimport entity.Cat;\nimport entity.Dog;\n\nclass StudentDaoTest {\n\n    @Test\n    void test() throws Exception {\n        \/\/\u7236\u63a5\u53e3\u5145\u5f53\u58f0\u660e\u90e8\u5206\n        StudentDao&lt;Dog, Cat> studentDao  = new StudentDaoImpl();\n         \/\/\u6839\u636eStudentDao\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61\u83b7\u53d6\u5b57\u8282\u7801\u5bf9\u8c61\n        Class&lt;?> studentDaoClass =studentDao.getClass();\n        \/\/\u83b7\u53d6UserDao\u6240\u6709\u7684\u65b9\u6cd5\n        Method&#91;] methods = studentDaoClass.getMethods();\n        for(Method method: methods) {\n            \/\/\u83b7\u53d6\u65b9\u6cd5\u7684\u540d\u79f0\n            String methodName = method.getName();\n            \/\/\u5224\u65ad\u662f\u5426\u662fstudentDao\u4e2d\u7684get\u65b9\u6cd5\uff0c\n            if(methodName.startsWith(\"get\")&amp;&amp; !methodName.startsWith(\"getClass\")) {\n                \/\/\u8fd4\u56de\u4e00\u4e2aType\u5bf9\u8c61\uff0c\u8868\u793a\u7531\u8be5\u65b9\u6cd5\u5bf9\u8c61\u8868\u793a\u7684\u65b9\u6cd5\u7684\u6b63\u5f0f\u8fd4\u56de\u7c7b\u578b\u3002\n              Type genericReturnType = method.getGenericReturnType();\n              \/\/\u83b7\u53d6\u5b9e\u9645\u8fd4\u56de\u7684\u53c2\u6570\u540d\n              String returnTypeName = genericReturnType.getTypeName();\n\n              System.out.println(methodName+\"\u7684\u8fd4\u56de\u53c2\u6570\u662f\uff1a\"+returnTypeName);\n              \/\/\u5224\u65ad\u662f\u5426\u662f\u53c2\u6570\u5316\u7c7b\u578b\n              if(genericReturnType instanceof ParameterizedType) {\n                  \/\/\u5982\u679c\u662f\u53c2\u6570\u5316\u7c7b\u578b,\u5219\u5f3a\u8f6c\n                  ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;\n                \/\/\u83b7\u53d6\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u6570\u7ec4\uff0c\u6bd4\u5982List&lt;Dog>\uff0c\u5219\u83b7\u53d6\u7684\u662f\u6570\u7ec4&#91;Dog]\uff0cMap&lt;Dog, Cat> \u5219\u83b7\u53d6\u7684\u662f\u6570\u7ec4&#91;Dog, Cat]\n                  Type&#91;] actualTypeArguments = parameterizedType.getActualTypeArguments();\n                  System.out.println(methodName+\"\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u53c2\u6570\u5316\u7c7b\u578b\uff0c\u5176\u7c7b\u578b\u4e3a\uff1a\");\n                  for(Type type:actualTypeArguments) {\n                      \/\/\u5f3a\u8f6c\n                      Class&lt;?> actualTypeArgument = (Class&lt;?>) type;\n                     \/\/\u83b7\u53d6\u5b9e\u9645\u53c2\u6570\u7684\u7c7b\u540d\n                      String name = actualTypeArgument.getName();\n                      System.out.print(\"  \"+name);\n                  }\n                  System.out.println();\n\n              }else {\n                  \/\/\u4e0d\u662f\u53c2\u6570\u5316\u7c7b\u578b,\u76f4\u63a5\u83b7\u53d6\u8fd4\u56de\u503c\u7c7b\u578b\n                  Class&lt;?> returnType = method.getReturnType();\n                  \/\/\u83b7\u53d6\u8fd4\u56de\u503c\u7c7b\u578b\u7684\u7c7b\u540d\n                  String name = returnType.getName();\n                  System.out.println(methodName+\"\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e0d\u662f\u53c2\u6570\u5316\u7c7b\u578b\u5176\u7c7b\u578b\u4e3a\uff1a\"+name);\n\n              }\n\n            }\n\n\n        }\n        }\n\n    }<\/code><\/pre>\n\n\n\n<p>\u8fdb\u884cJUnit\u6d4b\u8bd5\uff0c\u5176\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200727164048432.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/figure >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200727164048432.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/figure><\/noscript>\n\n\n\n<p>\u53d1\u73b0\u80fd\u8fd0\u884c\u6253\u5370\u8f93\u51fa\u4e00\u90e8\u5206\uff0c\u4e2d\u9014\u51fa\u73b0\u5f02\u5e38\u76f4\u63a5\u4e2d\u65ad\u8fd0\u884c\u4e86\u3002\u6839\u636eJUnit\u6d4b\u8bd5\u7684 \u63d0\u793a\uff1a<br><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200727164138325.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200727164138325.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p><\/noscript>\n\n\n\n<p>\u5728\u8fdb\u884c\u5bf9public Map getAll();\u8fd9\u4e2a\u53c2\u6570\u5316\u65b9\u6cd5\u8fdb\u884c\u89e3\u6790\u7684\u65f6\u5019\uff0c\u5f3a\u8f6c\u9047\u5230\u5f02\u5e38\u4ece\u800c\u4e2d\u65ad\u7a0b\u5e8f\u7684\u8fd0\u884c\u3002\u4e0b\u9762\u6211\u4eec\u4ed4\u7ec6\u5206\u6790\u770b\u770b\u8fd9\u4e2a\u539f\u56e0\u662f\u5565\uff1a<br>2.1\u9996\u5148\u83b7\u53d6\u5b57\u8282\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class&lt;?> studentDaoClass =studentDao.getClass();<\/code><\/pre>\n\n\n\n<p>\u83b7\u53d6\u5b57\u8282\u7801\u540e\uff0c\u6211\u4eec\u77e5\u9053\u5728\u5b57\u8282\u7801\u4e2d\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u548c\u4ee3\u7801\u4e2d\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u4e00\u81f4\u7684\uff0c\u6bd4\u5982public Map getAll();\uff0c\u90a3\u4e48\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u5c31\u662fMap;\u867d\u7136\u6211\u4eec\u5728\u5b9e\u4f8b\u5316\u65f6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>StudentDao&lt;Dog, Cat> studentDao  = new StudentDaoImpl&lt;>();<\/code><\/pre>\n\n\n\n<p>\u5df2\u7ecf\u4f7f\u7528\u4e86\u5b9e\u9645\u7c7b\u578b\uff0c\u4f46\u662f\u6211\u4eec\u83b7\u53d6\u7684\u5b57\u8282\u7801\u5bf9\u8c61studentDaoClass \u4e2d\u662f\u6ca1\u6709\u5177\u4f53\u7c7b\u578b\u7684\u4fe1\u606f\u7684\uff0c\u56e0\u4e3a\u6211\u4eec\u83b7\u53d6\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u7684\u65f6\u5019\u4f1a\u83b7\u5f97\u7684\u662fMap\uff0c\u7136\u540e\u5728<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Class&lt;?> actualTypeArgument = (Class&lt;?>) type;<\/code><\/pre>\n\n\n\n<p>\u8fdb\u884c\u8f6c\u6362\u7684\u65f6\u5019\uff0c\u7531\u4e8eMap\u4e2d\u7684T\u548cV\u662f\u6cdb\u578b\uff0c\u800c\u6cdb\u578b\u662f\u4e0d\u652f\u6301\u5f3a\u8f6c\u7684\uff0c\u6240\u4ee5\u4f1a\u62a5\u9519\uff0c\u4ece\u800c\u7ed3\u675f\u7a0b\u5e8f\u8fd0\u884c\u3002\u663e\u7136\uff0c\u5728\u4e0a\u8ff0\u7684\u60c5\u51b5\u4e0b\u6211\u4eec\u662f\u65e0\u6cd5\u8fdb\u884c\u83b7\u53d6\u5230\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7684\u6b63\u786e\u7c7b\u578b\u7684\u3002\u56e0\u6b64\u6211\u4eec\u8981\u60f3\u83b7\u53d6\u51fd\u6570\u4e2d\u7684\u8fd4\u56de\u503c\u7684\u5177\u4f53\u7c7b\u578b\uff0c\u5c31\u5fc5\u987b\u8981\u4fee\u6539StudentDaoImpl.java\uff0c\u6539\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package dao;\n\nimport java.util.List;\nimport java.util.Map;\n\nimport entity.Cat;\nimport entity.Dog;\n\n\n\/**\n * @author \u964c\u610f\u968f\u5f71\n TODO :StudentDao\u63a5\u53e3\u7684\u5b9e\u73b0\u4e86\n *2020\u5e747\u670827\u65e5  \u4e0a\u534812:35:32\n *\/\npublic class StudentDaoImpl implements StudentDao&lt;Dog,Cat>{\n\n    @Override\n    public Map&lt;Dog, Cat> getAll() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }\n\n    @Override\n    public Dog getT() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }\n\n    @Override\n    public Cat getV() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }\n\n    @Override\n    public List&lt;Dog> getAllT() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }\n\n\n\n\n}<\/code><\/pre>\n\n\n\n<p>\u4e5f\u5c31\u662f\u5728\u5b50\u7c7b\u5b9e\u73b0\u7684\u65f6\u5019\u5c31\u8be5\u6307\u5b9a\u6cdb\u578b\u7684\u5177\u4f53\u7c7b\u578b\uff0c\u7136\u540e<br>\u8fd0\u884cJUnit\u6d4b\u8bd5\uff0c\u5176\u7ed3\u679c\u4e3a\uff1a<br><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200727211031763.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200727211031763.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p><\/noscript>\n\n\n\n<p>\u4ece\u7ed3\u679c\u4e2d\u6211\u4eec\u53d1\u73b0\uff0c\u8fd0\u884c\u6210\u529f\uff0c\u5e76\u4e14\u6253\u5370\u8f93\u51fa\uff0c\u4f46\u662f\u53d1\u73b0\u5982\u679c\u662f\u4e0d\u662f\u53c2\u6570\u5316\u7684\u6bcf\u4e2a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u90fd\u56de\u6253\u5370\u4e24\u6b21\uff0c\u5e76\u4e14\u6bcf\u6b21\u7684\u8fd4\u56de\u503c\u7684\u53c2\u6570\u5316\u5b9e\u9645\u7c7b\u578b\u90fd\u4e0d\u4e00\u6837\uff1b\u800c\u53c2\u6570\u5316\u7684\u6bcf\u4e2a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u90fd\u503c\u6253\u5370\u4e00\u6b21\uff0c\u5e76\u4e14\u6253\u5370\u7684\u7ed3\u679c\u5747\u6b63\u786e\u3002\u5176\u539f\u56e0\u662f\u4e3a\u4f55\u5462\uff1f<br>\u5176\u5b9e\u539f\u56e0\u662f\u56e0\u4e3a\uff0cStudentDao\u662f\u7236\u63a5\u53e3\uff0c\u5176\u5b9e\u73b0\u7c7bStudentDaoImpl\u7ee7\u627f\u4e86StudentDao\u63a5\u53e3\u7684\u6240\u6709\u65b9\u6cd5\uff0c\u5f53\u6211\u4eec<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u7236\u63a5\u53e3\u5145\u5f53\u58f0\u660e\u90e8\u5206\n        StudentDao&lt;Dog, Cat> studentDao  = new StudentDaoImpl();\n         \/\/\u6839\u636eStudentDao\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61\u83b7\u53d6\u5b57\u8282\u7801\u5bf9\u8c61\n        Class&lt;?> studentDaoClass =studentDao.getClass();<\/code><\/pre>\n\n\n\n<p>\u83b7\u53d6\u7684\u662fStudentDaoImpl\u7684\u5b57\u8282\u7801\u5bf9\u8c61\uff0cstudentDaoClass \u4e2d\u5305\u542b\u4e86\u81ea\u5df1\u5b9a\u4e49\u7684\u65b9\u6cd5\u5217\u8868\u4ee5\u53ca\u7236\u7c7b\u63a5\u53e3\u7684\u65b9\u6cd5\u5217\u8868\u3002\u7531\u4e8e\u7236\u7c7bStudentDao\u63a5\u53e3\u4e2d\u662f\u6cdb\u578b\uff0cpublic T getT();\u548cpublic V getV();\u7684\u8fd4\u56de\u503c\u5bf9\u8c61\u90fd\u662fObject\uff0c\u800cMap getAll();\u548cList getAllT();\u7684\u8fd4\u56de\u5bf9\u8c61\u5206\u522b\u662fMap,List.<br>StudentDaoImpl\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Override\n    public Dog getT() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }\n\n    @Override\n    public Cat getV() {\n        \/\/ TODO Auto-generated method stub\n        return null;\n    }<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u5206\u522b\u662fDog\u548cCat\uff0c\u8fd9\u65f6\u5019\u5b50\u7c7bStudentDaoImpl\u548cStudentDao\u4e2d\u7684\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e0d\u4e00\u6837\uff0c\u5b50\u7c7b\u7684\u65b9\u6cd5\u65e0\u6cd5\u8986\u76d6\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u5b57\u8282\u7801studentDaoClass \u4e2d\u5b9e\u9645\u4e0a\u5305\u542b\u6709\u56db\u4e2a\u65b9\u6cd5 public Object getT();public Dog getT(); \u548cpublic Object getV()\uff1bpublic Cat getV();<br>\u53e6\u5916\uff0c\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u96c6\u5408\u7684\uff0c\u4e0d\u8003\u8651\u53c2\u6570\u5316\u7c7b\u578b\uff0c\u6bd4\u5982public Map getAll();\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662fMap; public List getAllT()\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u662fList\uff1b<br>\u56e0\u6b64\uff0c\u65e0\u8bba\u662f\u5728StudentDao\u8fd8\u662f\u5728StudentDaoImpl\u4e2d\uff0cpublic Map&lt; T,V &gt; getAll()\uff0cpublic Map&lt; Dog\uff0cCat &gt; getAll()\u8fd4\u56de\u503c\u7c7b\u578b\u90fd\u662fMap\uff1bpublic List getAllT();\u548cpublic List&lt; Dog &gt; getAllT();\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u90fd\u662fList\uff0c\u8fd9\u8bf4\u660e\u5b50\u7c7b\u7684public Map&lt; Dog, Cat &gt; getAll() \uff1b\u548cpublic List&lt; Dog&gt; getAllT() \u5b8c\u5168\u8986\u76d6\u4e86\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u56e0\u6b64studentDaoClass\u53ea\u6709\u5b50\u7c7bStudentDaoImpl\u7684<br>public Map&lt; Dog,Cat&gt; getAll()\u548cpublic List&lt; Dog&gt; getAllT();\u65b9\u6cd5\u3002<br>\u7efc\u4e0a\u6240\u8ff0\uff0cstudentDaoClass\u4e2d\u5b9e\u9645\u4e0a\u662f\u6709\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u516b\u4e2a\uff08StudentDao\u6709\u56db\u4e2a\uff0cStudentDaoImpl\u6709\u56db\u4e2a\uff09\u65b9\u6cd5\u4e2d\u7684\u516d\u4e2a\u65b9\u6cd5\u3002\u5206\u522b\u662f\uff1a<br>public Object getT();public Dog getT(); \u548cpublic Object getV()\uff1bpublic Cat getV();\u4ee5\u53capublic Map&lt; Dog,Cat&gt; getAll()\u548cpublic List&lt; Dog&gt; getAllT();\u8fd9\u516d\u4e2a\u65b9\u6cd5\u3002\u56e0\u6b64\u5728\u6211\u4eec\u83b7\u53d6\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u65f6\uff0c\u6253\u5370\u8f93\u51fa\u7684\u662f\u4e0a\u8ff0\u7ed3\u679c\u3002<br><strong>3.\u672c\u6b21\u5b9e\u9a8c\u9879\u76ee\u6e90\u7801\u4ee5\u53ca\u6253\u5305\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u9700\u8981\u7684\u8bf7\u81ea\u884c\u4e0b\u8f7d\uff0c\u89e3\u538b\u540e\u76f4\u63a5\u5bfc\u5165eclipse\u5373\u53ef\uff1a<\/strong><a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/javademo.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/07\/javademo.rar<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u53cd\u5c04\u83b7\u53d6\u8fd4\u56de\u503c\u7c7b\u578b\u7684\u5b9e\u9645\u7c7b\u578b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[18,13,22,27,28],"_links":{"self":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/152"}],"collection":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":1,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":214,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions\/214"}],"wp:attachment":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}