2013年9月22日星期日

Mybatis incoming parameters of the problem

I passed parameter type is List but related mapper file, insert statement has been given.
Below is the code :

java file related code
int test = 10;
List > list = new ArrayList > ();
for (int i = 0; i Map map = new HashMap ();
map.put ("id", i);
map.put ("name", "name")
list.add (map);
}
this.TestMapper.addTest (list);

Testmapper.xml file code :


reported error : java.lang.reflect.InvocationTargetException

seeking answers which is why there is an error
------ Solution ------------------------ --------------------
first tag wrong, can not be used with the insert select, followed by cycle right , insert placed outside the loop .
Example :
insert into TACCOUNTSBATCH
(relationID,
batchID,
batchYear,
batchProperty,
fetchStartTime,
fetchEndTime,
storageTime,
modifyTime,
validStatus
) values

(# {item.relationID, jdbcType = VARCHAR}, # {item.batchID, jdbcType = VARCHAR}, # {item.batchYear, jdbcType = VARCHAR},
# {item.batchProperty, jdbcType = VARCHAR}, # {item.fetchStartTime, jdbcType = TIMESTAMP},
# {item.fetchEndTime, jdbcType = TIMESTAMP},
# {item.storageTime, jdbcType = TIMESTAMP}, # {item.modifyTime, jdbcType = TIMESTAMP},
# {item.validStatus, jdbcType = CHAR})


------ Solution ------------------------- -------------------
parameterType = "list" into the list you sure you write can access it directly in mybatis ; map of the id and name?
------ For reference only -------------------------------------- -
nobody knows the reason. . .
------ For reference only ---------------------------------------


I was originally thinking this way but when I see someone like me to write feel like pass into the list foreach parses the list and then item.XXX where XXX is the Map in the key but I do not know why I'm wrong here . . .
------ For reference only -------------------------------------- -



Thank issue has been resolved that a program is not taking this latest statement that I do not have to update the system that led to such a stupid mistake Also you this method is also possible ; but because the database using postgresql does not support multiple lines separated by "," sql touches can mybatis support the use of item Get list of entities or the map's key ~ ~ Thank you and scattered divided downstairs

没有评论:

发表评论