1.pom.xml增加依賴包
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.protobuf-java-format</groupId>
<artifactId>protobuf-java-format</artifactId>
<version>1.4</version>
</dependency>
2.Application增加ProtobufHttpMessageConverter
@Bean
ProtobufHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufHttpMessageConverter();
}
3.Controller編寫
@RequestMapping(value = { "/login.do" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
public ResponseEntity<UserRes> login(RequestEntity<RegShopReq> requestEntity, HttpServletRequest httpServletRequest) {
RegShopReq request = requestEntity.getBody();
System.out.println(request);
UserRes response = UserRes.newBuilder().setStat(1000).setMess("111111").build();
return ResponseEntity.ok(response);
}