Hasor 使用 Servlet

2018-10-09 15:37 更新

在 Hasor Web 中使用 Servlet 如下所示,首先编写我们自己的 HttpServlet,然后将它注册到 Hasor 中:

public class DemoHttpServlet extends HttpServlet{
    protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        ...
    }
}


第一种方式 Api 接口注册 Servlet 的地址。

public class DemoModule extends WebModule{
    public void loadModule(WebApiBinder apiBinder) throws Throwable {
        apiBinder.jeeServlet("/your_point.do").with(DemoHttpServlet.class);
    }
}


第二种方式,通过 @MappingTo 注册 Servlet,如下:

@MappingTo("/your_point.do")
public class DemoHttpServlet extends HttpServlet{
    protected void service(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        ...
    }
}


扫描所有 @MappingTo

public class DemoModule extends WebModule{
    public void loadModule(WebApiBinder apiBinder) throws Throwable {
        apiBinder.scanMappingTo();
    }
}


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号