简体   繁体   English

为什么列出 <generic> 在使用Java的mybatis的情况下无法正常工作?

[英]Why List<generic> is not working in case of mybatis with java?

My service code here 我的服务代码在这里

public HashMap<String, Object> syncEmployees(Long updatedAt, String userId) {
    HashMap<String, Object> outputMap = new LinkedHashMap<String, Object>();
    **List<String>** outputEmployee = employeeDao.getEmployeeSyncDetails(updatedAt);

        System.out.println("\n\n Size : "+outputEmployee.size()+"\nOutput : "+outputEmployee);

    outputMap.put("employee", outputEmployee);
    return outputMap;
}

Dao code which is return type is list of string List(String) 返回类型的道代码是字符串列表List(String)

**List<String>** getEmployeeSyncDetails(@Param("updatedAt") long updatedAt);

.XML mapper and query where method returns list of xyzModel .XML映射器和查询方法返回xyzModel列表的位置

<resultMap id="xyzmap" type="xyzModel" >
        <result property="userId" column="user_id" />
        <result property="employeeCode" column="employee_code" />
        <result property="designationId" column="designation_id" />

    </resultMap>


<select id="getxyzDetails" resultMap="xyzmap">
    SELECT   
             user_id, ua.employee_code, designation_id
    FROM users
    WHERE  updated_at &gt; #{updatedAt} 
    ORDER BY  updated_at ASC
</select>

And output is like Size : 3 Output : [com.webapp.models. 输出类似于Size:3 Output:[com.webapp.models。 xyzModel @1567524c, com.webapp.models. xyzModel @ 1567524c,com.webapp.models。 xyzModel @7744c2cd, com.webapp.models. xyzModel @ 7744c2cd,com.webapp.models。 xyzModel @43515de7] xyzModel @ 43515de7]

My question is how its is working? 我的问题是它是如何工作的? How xyzmodel is getting populated in list of String actually my problem is XML mapper return xyzModel but if I write any other model like UserModel or String or any other model it is not showing any error or execute perfectly with proper output. xyzmodel是如何填充到String列表中的,实际上我的问题是XML映射器返回xyzModel,但是如果我编写任何其他模型(如UserModel或String)或任何其他模型,则不会显示任何错误或无法以正确的输出完美执行。 If we process this list then only he send error java.lang.ClassCastException 如果我们处理此列表,则只有他发送错误java.lang.ClassCastException

In runtime, there are no types for generics. 在运行时,没有泛型类型。

If you would write the code for getEmployeeSyncDetails yourself, your compiler would warn you about this. 如果您自己编写getEmployeeSyncDetails的代码,则编译器将对此发出警告。

Read here about type erasure in java: https://docs.oracle.com/javase/tutorial/java/generics/erasure.html 在此处阅读有关Java中的类型擦除的信息: https : //docs.oracle.com/javase/tutorial/java/generics/erasure.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM