当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpServletRequest.getAttribute方法代码示例

本文整理汇总了Java中org.springframework.mock.web.MockHttpServletRequest.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest.getAttribute方法的具体用法?Java MockHttpServletRequest.getAttribute怎么用?Java MockHttpServletRequest.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mock.web.MockHttpServletRequest的用法示例。


在下文中一共展示了MockHttpServletRequest.getAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPage

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testPage() throws Exception{
	//模拟请求拿到返回值
	
	MvcResult result = movkMVC.perform(MockMvcRequestBuilders.get("/emps").param("pn", "3")).andReturn();
	//请求成功以后,请求域中会有pageInfo:我们可以取出pageinfo进行验证
	MockHttpServletRequest request = result.getRequest();	
	PageInfo pi = (PageInfo)request.getAttribute("PageInfo");
	System.out.println("当前页码:"+pi.getPageNum());
	System.out.println("总页码:"+pi.getPages());
	System.out.println("总记录数:"+pi.getTotal());
	System.out.println("在页面需要连续显示的页码");
	int[]  nums= pi.getNavigatepageNums();
	for(int i:nums){
		System.out.println(" "+i);
	}
	
	//获取员工数据
	List<Employee> list= pi.getList();
	for(Employee employee : list ){
		System.out.println("ID:" +employee.getEmpId()+"==>Name:"+employee.getEmpName());
	}
	
}
 
开发者ID:DevilChen,项目名称:SSM_Employee,代码行数:25,代码来源:MvcTest.java

示例2: renderView

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
private Map<?, ?> renderView() throws Exception{
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    v.setServletContext(req.getServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            new GenericWebApplicationContext(req.getServletContext()));

    final Cas30ResponseView view = new Cas30ResponseView(v);
    view.setServicesManager(this.servicesManager);
    view.setCasAttributeEncoder(new DefaultCasAttributeEncoder(this.servicesManager));

    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:Cas30ResponseViewTests.java

示例3: renderView

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
private Map<?, ?> renderView() throws Exception {
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));

    final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
    final View viewDelegated = new View() {
        @Override
        public String getContentType() {
            return MediaType.TEXT_HTML_VALUE;
        }

        @Override
        public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            map.forEach(request::setAttribute);
        }
    };

    final Cas30ResponseView view = new Cas30ResponseView(true, encoder, servicesManager,
            "attribute", viewDelegated, true);
    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:Cas30ResponseViewTests.java


注:本文中的org.springframework.mock.web.MockHttpServletRequest.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。