nash
nash

Reputation: 3110

Can Mybatis annotation mappers return arrays?

I would like to return an array from an annotation based Mybatis mapper to avoid the memory overhead of boxed primitives. Is this possible?

I tried

@Select("select id from some_table")
public long[] selectIds();

with no luck.

Upvotes: 2

Views: 1736

Answers (3)

PANKAJ kSHARMA
PANKAJ kSHARMA

Reputation: 125

MyBatis mapper can return array of Object,but not array of primitives

please see the example below:-

@Results({
    @Result(property = "id", column = "id"),
    @Result(property = "name", column = "name"),
    @Result(property = "staffNumber", column = "staff_number")
  })    
@Select("select * from USERS")
User[] finduserArr();

Upvotes: 1

Diego Lopez
Diego Lopez

Reputation: 594

It can as of version 3.1. Try with 3.1.1.

Upvotes: 0

Alfabravo
Alfabravo

Reputation: 7569

Try adding @MapKey annotation. It produces a Map with id as key and a Hashmap (key = column Name, value = value) as value

Check nested mybatis map for further reference

Upvotes: 0

Related Questions