尝试下面的代码,
@Configurationpublic class MyInterceptorConfig extends WebMvcConfigurerAdapter{ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); ObjectMapper mapper = new ObjectMapper() { private static final long serialVersionUID = 1L; @Override protected DefaultSerializerProvider _serializerProvider(SerializationConfig config) { // replace the configuration with my modified configuration. // calling "withView" should keep previous config and just add my changes. return super._serializerProvider(config.withView(TravelRequestView.MyRequests.class)); } }; mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true); converter.setObjectMapper(mapper); converters.add(converter); }
尽管我不想为此功劳,但这是来自
它将检索使用jsonview(TravelRequestView.MyRequests.class)注释的实体的所有变量以及未使用jsonview注释的所有变量。如果您不想要对象的某些属性,请使用不同的视图进行注释。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)