Answer the question
In order to leave comments, you need to log in
How to separate requests to the server API and to its static resources?
Good day everyone! I ran into the problem of separating requests for the server API and static resources, specifically: index.html. That is, the task is as follows: all requests, for example, to: localhost:8080/administrationPanel/tables/highCategory Should return index.html. But if I'm accessing the server API, then it should look like this: localhost:8080/api/getHighCategory . I didn't install any ViewResolvers because I'm giving away static resources (although maybe I'm wrong here), ResourceHandlerRegistry helps me with this :
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("/");
}
@RequestMapping(value = "/**", method = RequestMethod.GET)
public String welcome() {
return "index.html";
}
@RequestMapping(value = "/administrationPanel", method = RequestMethod.GET)
public String welcome() {
return "index.html";
}
@RequestMapping(value = "/administrationPanel/**", method = RequestMethod.GET)
public String testWelcome() {
return "index.html";
}
@RequestMapping(value = "/api/highCategory", method = RequestMethod.GET)
public String apiCategory() {
//code
return smth;
}
@RequestMapping(value = "/administrationPanel/**"
@RequestMapping(value = "/administrationPanel/smth"
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
Answer the question
In order to leave comments, you need to log in
Did so.
Returning static:
@RequestMapping(path = {"film/*", "serial/*"}, method = RequestMethod.GET)
public String index() {
return "forward:/index.html";
}
@RestController
@RequestMapping("/rest/content")
public class ContentController {
@RequestMapping(method = RequestMethod.GET)
public HttpStatus searchContent(@Param("name") String name) {
System.out.println("search for content with param: " + name);
return HttpStatus.ACCEPTED;
}
@RequestMapping(method = RequestMethod.POST)
public HttpStatus uploadContent(@RequestBody Content content) {
System.out.println("upload content");
return upload != null ? HttpStatus.CREATED : HttpStatus.BAD_REQUEST;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question