@Target(ElementType.METHOD)
public @interface SubMethod {
public String value() default "get";
}
public abstract class IndexServlet extends HttpServlet {
protected static final String POST = "post";
protected static final String GET = "get";
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.dealRequest( GET, request, response );
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.dealRequest( POST, request, response );
}
public void dealRequest(
String subMehod,
HttpServletRequest request,
HttpServletResponse response ) throws IOException {
String url = request.getRequestURI();
//System.out.println( url );
//通过路劲获得对应的对象和方法
Method method = null;
Object instance = null;
HashMap
if( map == null ){
//没有对应的方法则返回
this.noMethod( response );
return;
} else {
instance = map.get( "instance" );
method = (Method)map.get( "method" );
}
//判断是否是对应的提交方式
//默认为get方式
String m = GET;
SubMethod anns = method.getAnnotation( SubMethod.class );
if( anns != null ) {
m = anns.value();
if( Validation.isNull( m ) ) {
m = GET;
} else {
m = m.toLowerCase();
}
//System.out.println( "-------------------------anns is " + m );
} else {
//System.out.println( "--------只要spring的事务管理就取不到m的值是get或者post,不参与spring的事务就ok---------------anns is null" );
}
} catch ( Exception e ) {
//访问失败
LogUtil.getLogger().warn( e, SystemCode.E5000000001, url );
} finally {
//将session从本地线程存储中移出
manager.clearTerminalSession();
}
//返回数据
this.writeAndClose( response, content );
}
@Component("testImpl")
public class TestImpl {
@SubMethod("post")//这个类不参与spring事务就能取的到post,参与spring事物就不行,想要的结果是取到post这个值。
public String testPostMe( String param ){
System.out.println("================");
return "ok";
}
}
}
多谢解答下。