- 在controller层的方法上加上@ResponseBody注解
@GetMapping("/selectOne")
@ResponseBody
public LabMsg selectOne(Integer labNum) {
LabMsg labMsg = labMsgService.queryById(labNum);
System.out.println(labMsg);
return labMsg;
}
- 在pom.xml引入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
- 在springmvc.xml中加入如下代码
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<property name="features">
<array>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
- 效果图