ddshow

2086 ワード

1、org.springframework.web.servlet.view.json.MappingJacksonJsonView

<!-- 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;
        }