1、org.springframework.web.servlet.view.json.MappingJacksonJsonView
2、调用
3、
<!-- jsonview -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean id="jsonView"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
2、调用
@Autowired(required = true)
@Qualifier("jsonView")
private View jsonView;
3、
ModelAndView mav = new ModelAndView(jsonView);
try {
Boolean flag = Boolean.FALSE;
if (StringUtils.isNotBlank(spam) && SPAM_TRUE.equals(spam)) {
flag = Boolean.TRUE;
}
List<String> ipList = null;
if(flag){
ipList = resultIpFilterStatService.getNotExpiredIps();
} else {
ipList = userLoginIPService.getNewDisabledIPList();
}
mav.addObject(JsonResponse.RESPONSE_KEY, new JsonResponse(JsonResponse.Code.successful, "获取成功", ipList));
return mav;
} catch (Exception e) {
logger.error(e.getMessage(), e);
mav.addObject(JsonResponse.RESPONSE_KEY, new JsonResponse(JsonResponse.Code.failed, "获取IP禁封列表错误"));
return mav;
}