Package org.xdemo.site.biz.test

Source Code of org.xdemo.site.biz.test.ControllerTest

/**
* xdemo.org
*/
package org.xdemo.site.biz.test;

import java.util.Iterator;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.xdemo.site.biz.portal.demo.service.IDemoService;
import org.xdemo.site.system.bean.sqlinxml.XmlReader;
import org.xdemo.site.system.exception.XdemoException;

/**
* @作者 Goofy
* @邮件 252878950@qq.com
* @日期 2014-1-3
* @描述 测试视图解析器
*/
@Controller
@RequestMapping("/test")
public class ControllerTest {
 
  @Resource IDemoService demoService;
  @Resource XmlReader xmlReader;
 
  private final RequestMappingHandlerMapping handlerMapping;

   @Autowired
   public ControllerTest(RequestMappingHandlerMapping handlerMapping) {
     this.handlerMapping = handlerMapping;
   }
 
  /**
   * 根据配置文件中的视图解析器自动寻找视图,使用默认的约定原则
   */
  @RequestMapping("a")
  public void a(){
    //遍历已映射的所有的url
    Map<RequestMappingInfo, HandlerMethod>  map=this.handlerMapping.getHandlerMethods();
    Iterator<Map.Entry<RequestMappingInfo, HandlerMethod>> it=map.entrySet().iterator();
    while(it.hasNext()){
      Map.Entry<RequestMappingInfo, HandlerMethod> entry=it.next();
      RequestMappingInfo rm=entry.getKey();
      HandlerMethod hm=entry.getValue();
      System.out.println(rm.getPatternsCondition().toString().replace("[", "").replace("]", ""));
    }
   
    System.out.println(xmlReader.getSQL("user-userManager-findAllUser-1"));;
    demoService.save();
  }
 
  /**
   * 如果返回指定路径的话,那么指定一个在视图解析器配置中的一个中间字符串,拼接成完整的页面地址
   * @return
   */
  @RequestMapping("b")
  public String b(){
    System.out.println(1/0);
    return "test/b";
  }
 
  /**
   * 解析FTL,查找ftl前缀路劲下的文件
   * @return
   */
  @RequestMapping("c")
  public String c(){
    return "test/c";
  }
  /**
   * 使用默认的约定原则
   */
  @RequestMapping("d")
  public void d(){}
}
TOP

Related Classes of org.xdemo.site.biz.test.ControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.