Restful response skills of springboot

The familiar annotations of springmvc are @Controller @RequestMapper @ResponseBody

Here are a few new things to introduce to you.

@GetMapper

@PostMapper

@***Mapper

@RestController

There is nothing new about these annotations, just some simplification of coding.

@RestController is written on the controller class, which is equivalent to writing @Controller and adding @ResponseBody to each method

@GetMapper("/test")等价于@ReqesutMapper(value="/test", method=RequestMethod.GET)

@PostMapper("/test")等价于@ReqesutMapper(value="/test", method=RequestMethod.POST)

@***Mapper is also several other request methods, there are.

Springmvc uses jackson to process the object to json for the ResponseBody returned object.

So how to deal with the return format of the date type here, springboot needs the following configuration

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

If it is to exclude empty attributes, the following configuration is required

spring.jackson.default-property-inclusion=non_null (here means that non-null properties are included by default)

non_empty non-empty strings, non-empty arrays, non-empty collections, etc.

There are other values, which are not introduced here, and are not very commonly used.

There are also, for example, ignoring a field of an entity, serializing and deserializing using a specified method. are all supported.

For details, please refer to the popular science jackson manual.

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324116427&siteId=291194637