1. 在springmvc-servlet.xml里加上 <mvc:annotation-driven />
写道
<!-- anotation配置,coin目录下的@Controller @Service等注解都能支持 -->
<context:component-scan base-package="coin"
resource-pattern="**/*Controller.class" />
<mvc:annotation-driven />
<!-- velocity配置, resourceLoaderPath=/velocity指向${WebRoot}/velocity位置 -->
<bean id="velocityViewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".vm" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="dateToolAttribute" value="dateTool" />
<property name="numberToolAttribute" value="numberTool" />
<property name="toolboxConfigLocation" value="WEB-INF/toolbox.xml" />
</bean>
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/velocity" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
</props>
</property>
</bean>
<context:component-scan base-package="coin"
resource-pattern="**/*Controller.class" />
<mvc:annotation-driven />
<!-- velocity配置, resourceLoaderPath=/velocity指向${WebRoot}/velocity位置 -->
<bean id="velocityViewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".vm" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="dateToolAttribute" value="dateTool" />
<property name="numberToolAttribute" value="numberTool" />
<property name="toolboxConfigLocation" value="WEB-INF/toolbox.xml" />
</bean>
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/velocity" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
</props>
</property>
</bean>
2. 在Controller返回值上加上 @ResponseBody
写道
@RequestMapping("/register.do")
@ResponseBody
public Map<String, Object> ignore(ModelAndView modelAndView, Long pageIndex, Long pageLength,
Long coinTypeId, String ignoreCodes) {
}
@ResponseBody
public Map<String, Object> ignore(ModelAndView modelAndView, Long pageIndex, Long pageLength,
Long coinTypeId, String ignoreCodes) {
}
3.在pom.xml配置文件里引用 jackson-mapper-asl
写道
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>