有没有办法使用纯Java servlet而不是spring mvc request mapping来将URL映射到方法?
就像是:
@GET(/path/of/{id})
Run Code Online (Sandbox Code Playgroud)
它也可以使用"普通的vanilla"servlet(哎呀,Spring MVC和JAX-RS也构建在servlet API之上),它只需要更多的样板.
@WebServlet("/path/of/*")
public class PathOfServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getPathInfo().substring(1);
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
就这样.感谢新的Servlet 3.0 @WebServlet注释,您不需要任何web.xml输入.