인터넷에서 Mybatis로 List 입출력 방법은 많은데 Map관련 방법은 잘 보이지 않는다. 그동안 인터넷으로 구글을 통해 Stackoverflow나 모르는 사람들의 블로그를 통해 도움받은것도 있고해서 다른 어떤 누구에게 도움을 드리고자 알아낸 방법을 여기다 정리합니다.

아래 방법들은 Mybatis Annotation 방식입니다. Mybatis Annotation 방식을 이해한 후 보시기 바랍니다.




* Map<String, Object> SELECT


@Select("SELECT *  FROM Table_Name LIMIT 1")

public Map<String, Object> selectRow();







* List<Map<String,Object>> SELECT


 @Select("SELECT * FROM Table_Name WHERE STRAND = #{strand}") 

 public List<Map<String,Object>> selectAll(String strand);







* Map<String, String> INSERT


@Insert("INSERT INTO Table_Name "+

"(AAA, BBB, CCC) " +

"VALUES " +

"(#{map.AAA},#{map.BBB},#{map.CCC}) "

)

public int insertRow(@Param("map") Map<String, String> rowData);






* List<Map<String,String>> INSERT



@Insert(

"<script> "+

"INSERT INTO Table_Name " +

"(AAA, BBB, CCC) "+

"VALUES "+

"<foreach collection='list' item='item' index='index' separator=' ), ( ' open='( ' close=' )'> " +

" #{item.AAA},#{item.BBB},#{item.CCC} " +

"</foreach> " +

"</script> ")

public int insertAll(@Param("list") List<Map<String,String>> listRowData);



Posted by 온천거북
,