Tao Tao recently followed suit mall project, out of such a 406 error,
this is the Controller code
@RequestMapping("/items/{itemId}")
@ResponseBody
public TbItem getItemById(@PathVariable long itemId) {
TbItem item=itemService.findItemById(itemId);
return item;
}
This is tatao-manager-web in the package depends json conversion:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
This is the po class TbItem
public class TbItem {
private Long id;
private String title;
private String sellPoint;
private Long price;
private Integer num;
private String barcode;
private String image;
private Long cid;
private Byte status;
private Date created;
private Date updated;
//省略getter、setter方法
Note look, the class now has a property of type Date created, suspect the problem lies in this,
1, rely change
<!-- jackson相关依赖包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
A package into a three pack.
2, the profile change springMVC
<!-- MappingJackson2HttpMessageConverter处理responseBody 里面日期类型 xsi:schemaLocation引入版本必须大于等于3.1 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyyMMddHHmmss" />
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
My profile named springmvc.xml, this period is a global setting json response date format, there is another way, you can see the references below.
OK, look pitted, came out,
although the issue is resolved, but in the end is what causes, I can not determine, after further study up on.
Reference:
[1], Jackson Comments