<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>web
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">spring
<property name="messageConverters">json
<list>mvc
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>app
</list>測試
</property>spa
</bean>debug
<mvc:annotation-driven />xml
加入的類要放在<mvc:annotation-driven />以前。遊戲
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.3</version>
</dependency>
@RequestMapping(value="/firstTime",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
public Map<String, Object> firstTime(HttpServletRequest request){
logger.debug("requestBody:{}" + request.getAttribute(VerificationService.ATTRIBUTE_KEY));
UserGame userGame = new DataInRequest().getModel(request, UserGame.class);
//更新任務時長和移動次數
userGame.setFinishNumber(1L); //設置完成遊戲數爲1,在查看文檔的時候回查看該數
jdbcService.saveOrUpdate(userGame);
//返回id
Map<String, Object> resultMap = new RespondHead().getRespondHeadMap();
resultMap.put("id", userGame.getId());
return resultMap;
}
返回的map 就會自動轉換爲json