简体   繁体   中英

how can I convert postgresql array to java array in getJdbcTemplate().query

I am using spring to interact with postgresql. Here is my problem.

Person have three attributes:

  1. name(String)
  2. hobbies(String[])
  3. gender(boolean)

If I try to get a list of person from database using the method below

List<Person> person=  getJdbcTemplate().query("select * from person where name=?",new BeanPropertyRowMapper<person>(Person.class),name);

The compiler prompts

Failed to convert property value of type 'org.postgresql.jdbc.PgArray' to required type 'java.lang.String[]' for property 'hobbies';

Is there any way to map pgarray to java array?

By implementing our own RowMapper

public class PersonRowMapper implements RowMapper<Person> 

Now, we can manipulate the result of rs.getArray(), then return person.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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