我正在查看与路由匹配的 servlet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
for (Map.Entry<Function<HttpServletRequest, Matcher>, Handler<Matcher>> handlerEntry : handlerMap.entrySet()) {
Matcher matcher = handlerEntry.getKey().apply(req);
if (matcher != null) {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html");
handlerEntry.getValue().handle(req, resp, matcher);
return;
}
}
resp.setStatus(404);
}
参考:https ://github.com/spullara/twickery/blob/master/src/main/java/twickery/web/Router.java#L59
您可以在此处查看视图模板:https ://github.com/spullara/twickery/tree/master/src/main/resources/templates
我对它们如何链接在一起感到困惑,我假设以某种方式从 servlet 返回,在某个地方返回,然后将其用作“模型”注入视图。
有人可以为我澄清一下吗?