Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将集合('选择*')映射到MyBatis中的字段_Java_Mybatis - Fatal编程技术网

Java 将集合('选择*')映射到MyBatis中的字段

Java 将集合('选择*')映射到MyBatis中的字段,java,mybatis,Java,Mybatis,我累坏了。我想用mybatis faramework代替直接使用sql。 我想选择已填充属性映射的帐户列表 但是让我们从头开始,第一个帐户类 public class Account { private int id; ... private Map<String, String> properties; ... //setters / getters } 基本上,它是有效的,但对于200个帐户,它需要大约2分钟,这是不可接受的 我

我累坏了。我想用mybatis faramework代替直接使用sql。 我想选择已填充属性映射的帐户列表

但是让我们从头开始,第一个帐户类

public class Account {
     private int id;
     ...
     private Map<String, String> properties;
     ...
     //setters / getters
}
基本上,它是有效的,但对于200个帐户,它需要大约2分钟,这是不可接受的

我希望将resultMap与collection一起使用可以加快速度。但问题是怎么做 去做吧。resultMap=帐户应该是什么样子

<resultMap id="account" type="Account">
   <id property="id" column="id">
   ...
   <collection property="properties" javaType="map" column="id" select="getAccountProperties" />
</resultMap>
在这种情况下,所选帐户对象不包含任何属性。
最大的问题是:如何将属性与account对象关联?

如果使用以下resultmap

<resultMap id="account" type="Account">
    <result property="id" column="id">
    <result property="properties" column="id" select="getAccountProperties" />
</resultMap>
然后,对于每个帐户,MyBatis执行getAccountProperties语句,将列id的值作为参数传递,但您必须允许在select标记中接受它:

<select id="getAccountProperties" resultClass="java.util.Map" parameterClass="java.lang.Integer" >
    select * from properties where id=#value#
</select>
<resultMap id="account" type="Account">
    <result property="id" column="id">
    <result property="properties" column="id" select="getAccountProperties" />
</resultMap>
<select id="getAccountProperties" resultClass="java.util.Map" parameterClass="java.lang.Integer" >
    select * from properties where id=#value#
</select>