@Override public void configHandler(Handlers me) { // TODO Auto-generated method stub me.add(new FakeStaticHandler(".html")); }
代码中,实现了.html伪静态,但我有一个方法请求,想修改为.xml作为后续的伪静态,有没有直接备注的方进行给某个方法修改伪静态的后续名呢?
我实现的方法:
package com.seo.silian; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import com.jfinal.handler.Handler; import com.jfinal.kit.HandlerKit; public class SilianHandler extends Handler { private Logger logger = Logger.getLogger(this.getClass()); private String lastName; private String voidName; public SilianHandler(String lastName,String voidName) { // TODO Auto-generated constructor stub this.lastName = lastName; this.voidName = voidName; } @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) { // TODO Auto-generated method stub String requserUrl = request.getRequestURI(); int index = target.lastIndexOf(lastName); if (index != -1 && target.contains(voidName)) { target = target.substring(0, index); } next.handle(target, request, response, isHandled); } }
@Override public void configHandler(Handlers me) { // TODO Auto-generated method stub me.add(new FakeStaticHandler(".html")); me.add(new SilianHandler(".txt","silian")); }
package com.seo.silian; import com.jfinal.core.Controller; public class SilianController extends Controller { public void index(){ // renderText("silian"); } }
当访问:包含"silinan.txt",会当成一个action来执行,之前的.html不冲突。
还有一个问题,我想改成annotation注入的方式,请问有可能实现吗?
例如
@xxx(".txt") public void index(){ // renderText("silian"); }
自动给我处理....