我有一个域对象
- ID
- 版本
我们想在表格中显示它,所以我需要在我的休息请求中得到它。
正如建议的那样,我实施了一个
@Configuration
public class RepoConf extends RepositoryRestMvcConfiguration {
public RepoConf(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
super(context, conversionService);
}
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(Lot.class);
}
}
我检查了加载此 conf 的日志:
2017-12-08 07:58:59.966 INFO 10344 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=repoConf; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [fr/urssaf/genv/back/repository/RepoConf.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]]
我有一个转换器来处理 URL 中的复合 ID:
@Component
class CustomBackendIdConverter implements BackendIdConverter {
@Override
public Serializable fromRequestId(String id, Class<?> entityType) {
switch (entityType.getSimpleName()) {
case "Lot":
String[] parts = id.split("_");
return new LotId(Integer.valueOf(parts[0]), parts[1]);
default:
return null;
}
}
@Override
public String toRequestId(Serializable source, Class<?> entityType) {
switch (entityType.getSimpleName()) {
case "Lot":
LotId id = (LotId) source;
return String.format("%s_%s", id.getIdLot(), id.getVersionLot());
default:
return null;
}
}
@Override
public boolean supports(Class<?> type) {
return Lot.class.equals(type);
}
}
但是当我在 Lot rest 资源上发出请求时,我的 ID 没有显示,例如: http://localhost:9000/lots/1_0 我怎样才能做到这一点?