本文整理匯總了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());
}
}
示例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);
}
示例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);
}