반응형
https://marobiana.tistory.com/112
일단, 여기서 해보라는건 모두 다 해봤다. 마지막꺼빼고,
마지막에 시도한방법,
dispatcher-servlet.xml
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<!-- <property name="webBindingInitializer">
<bean class="egovframework.example.cmmn.web.EgovBindingInitializer"/>
</property> -->
<property name="messageConverters">
<list>
<!-- -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name = "supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- json -->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
일단, name="webVindingInitializer" 있는 부분을 주석처리해준다!
그러가 그 아래에, messageconverters 를 추가해준다.
pom.xml
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
원래는 org.codehaus.jackson 이아이를 사용했었는데, https://www.egovframe.go.kr/home/qainfo/qainfoRead.do?menuNo=69&qaId=QA_00000000000018084 여기에 의하면, 스프링 4.1버전 이상일 경우에는 deprecate 됬기때문에 fasterxml 에 있는 jackson을 쓰라고 적혀있었다. 그래서 저걸 넣었다. 그리고 저 사이트에 나와있는 dependency 랑 다르다. 사이트에 나와있는대로 했는데 계속 에러가 나서 다른 것을 데려왔다.
그리고 여전히 모르겠지만, @RequestBody 가 아닌, @RequestParam 을 써야 가능하다.
@RequestMapping(value = "/admin/sutudentManagement/list.do" , method = RequestMethod.POST)
@ResponseBody
public String studentList(@RequestParam HashMap<String, Object> paramMap) {
LOGGER.info("paramMap : " + paramMap);
int total = 0;
List<HashMap<String, Object>> rows = new ArrayList<HashMap<String,Object>>();
DataTables dataTables = null;
try {
HashMap<String, Object> searchMap = null;
if(paramMap.containsKey("searchData")) {
searchMap = (HashMap<String, Object>) paramMap.get("searchData");
paramMap.putAll(searchMap);
}
rows = service.selectStudentInfoList();
total = service.selectStudentCount();
dataTables = new DataTables(paramMap, rows, total);
}catch (NullPointerException e) {
LOGGER.error("error: " + e.toString());
} catch (Exception e) {
LOGGER.error("error: " + e.toString());
}
if(dataTables == null) {
return "";
}
return dataTables.getJsonString();
}
반응형