我知道http 302响应是由浏览器直接处理的,因此您无法访问源代码中的任何请求属性.但我想知道是否有任何方法可以拦截302重定向响应.让我解释一下自己:
302 Location: B302用空字段拦截响应,然后转到B.这是我的Angular http拦截器代码:
@Injectable()
export class CasInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('->Interceptor');
console.log(req);
return next.handle(req).map((event: HttpEvent<any>) => {
const response = event as HttpResponseBase;
console.log('<-Interceptor');
console.log(response);
return event;
});
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下对象向 Rest Contoller 发出 POST 请求:
{
"relationship.name": "someting"
}
Run Code Online (Sandbox Code Playgroud)
我想将其映射到 POJO:
public class Request {
private String relationshipName;
// Getters, setter and contructor
}
Run Code Online (Sandbox Code Playgroud)
我该怎么点呢?
我有一个抽象实体,其注释为@MappedSuperclass:
@MappedSuperclass
public abstract class BaseEntity {
public abstract T getId();
public abstract void setId(T id);
}
Run Code Online (Sandbox Code Playgroud)
然后,我从中继承实体,并在每个实体中定义其ID:
@Entity
public class EntityA {
@Id
private int id;
// ....
}
@Entity
public class EntityB {
@Id
private long id;
// ....
}
Run Code Online (Sandbox Code Playgroud)
现在,我想创建一个通用的JpaRepository,它接受从我的基本实体扩展的任何类:
public interface BaseRepository<T extends BaseEntity, ID extends Serializable> extends JpaRepository<T, ID> {
}
Run Code Online (Sandbox Code Playgroud)
但是Spring抛出一个异常,说BaseEntity没有ID:
java.lang.IllegalArgumentException: This class [BaseEntity] does not define an IdClass
Run Code Online (Sandbox Code Playgroud)
请检查他的答案中Plog的评论。我可以解决将每个存储库类型注入服务的构造方法