本文整理了Java中org.springframework.ui.Model
类的一些代码示例,展示了Model
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Model
类的具体详情如下:
包路径:org.springframework.ui.Model
类名称:Model
[英]Java-5-specific interface that defines a holder for model attributes. Primarily designed for adding attributes to the model. Allows for accessing the overall model as a java.util.Map.
[中]定义模型属性持有者的Java-5特定接口。主要用于向模型添加属性。允许以java语言访问整个模型。util。地图
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@PathVariable(value="id") String id,
@ModelAttribute(value="entityForm") EntityForm entityForm, BindingResult result,
RedirectAttributes ra) throws Exception {
String templatePath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
if (result.hasErrors()) {
model.addAttribute("cmsUrlPrefix", staticAssetService.getStaticAssetUrlPrefix());
}
return templatePath;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@RequestMapping(value = "/{id}/chooseAsset", method = RequestMethod.GET)
public String chooseMediaForMapKey(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable(value = "sectionKey") String sectionKey,
@PathVariable(value = "id") String id,
@RequestParam MultiValueMap<String, String> requestParams) throws Exception {
Map<String, String> pathVars = new HashMap<String, String>();
pathVars.put("sectionKey", AdminAssetController.SECTION_KEY);
assetController.viewEntityList(request, response, model, pathVars, requestParams);
ListGrid listGrid = (ListGrid) model.asMap().get("listGrid");
listGrid.setPathOverride("/" + sectionKey + "/" + id + "/chooseAsset");
listGrid.setListGridType(Type.ASSET);
listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
String userAgent = request.getHeader("User-Agent");
model.addAttribute("isIE", userAgent.contains("MSIE"));
model.addAttribute("viewType", "modal/selectAsset");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.SELECT_ASSET.getType());
model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
// We need these attributes to be set appropriately here
model.addAttribute("entityId", id);
model.addAttribute("sectionKey", sectionKey);
return "modules/modalContainer";
}
代码示例来源:origin: spring-projects/spring-framework
@RequestMapping("/myPath.do")
@ModelAttribute("yourKey")
public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, Model model) {
if (!model.containsAttribute("myKey")) {
model.addAttribute("myKey", "myValue");
}
return "yourValue";
}
}
代码示例来源:origin: stackoverflow.com
@Controller
@RequestMapping("/counter")
@SessionAttributes("mycounter")
public class CounterController {
// Checks if there's a model attribute 'mycounter', if not create a new one.
// Since 'mycounter' is labelled as session attribute it will be persisted to
// HttpSession
@RequestMapping(method = GET)
public String get(Model model) {
if(!model.containsAttribute("mycounter")) {
model.addAttribute("mycounter", new MyCounter(0));
}
return "counter";
}
// Obtain 'mycounter' object for this user's session and increment it
@RequestMapping(method = POST)
public String post(@ModelAttribute("mycounter") MyCounter myCounter) {
myCounter.increment();
return "redirect:/counter";
}
}
代码示例来源:origin: ityouknow/spring-boot-examples
@RequestMapping("/hello")
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
model.addAttribute("name", name);
return "hello";
}
}
代码示例来源:origin: cloudfoundry/uaa
@RequestMapping("/saml_error")
public String error401(Model model, HttpServletRequest request) {
AuthenticationException exception = (AuthenticationException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
model.addAttribute("saml_error", exception.getMessage());
return "external_auth_error";
}
代码示例来源:origin: spring-projects/spring-integration-samples
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String show(@PathVariable("id") Long id, Model model) {
model.addAttribute("loanshark", LoanShark.findLoanShark(id));
model.addAttribute("itemId", id);
return "loansharks/show";
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@Secured(ConsoleSecurityRoles.ROLE_PROCESS_VIEW)
@RequestMapping(value = "/processDefinition/{id}", method = RequestMethod.GET)
public String details(@PathVariable("id") final String id, final Model model) {
final FlowDefinition flowDefinition = processManagementService.getFlowDefinition(id);
model.addAttribute("id", id);
model.addAttribute("definition", flowDefinition);
model.addAttribute("resources", flowDefinition.listAdditionalResources());
ProcessListResult result = processManagementService.findActiveProcessForDefinition(id);
model.addAttribute("result", result);
return "platform/process/definitionDetails";
}
代码示例来源:origin: cloudfoundry/uaa
@RequestMapping(value = "/change_email.do", method = RequestMethod.POST)
public String changeEmail(Model model, @Valid @ModelAttribute("newEmail") ValidEmail newEmail, BindingResult result,
@RequestParam(required = false, value = "client_id") String clientId,
@RequestParam(required = false, value = "redirect_uri") String redirectUri,
RedirectAttributes redirectAttributes, HttpServletResponse response) {
SecurityContext securityContext = SecurityContextHolder.getContext();
if(result.hasErrors()) {
model.addAttribute("error_message_code", "invalid_email");
model.addAttribute("email", ((UaaPrincipal)securityContext.getAuthentication().getPrincipal()).getEmail());
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
return "change_email";
} catch (UaaException e) {
if (e.getHttpStatus() == 409) {
model.addAttribute("error_message_code", "username_exists");
model.addAttribute("email", ((UaaPrincipal)securityContext.getAuthentication().getPrincipal()).getEmail());
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
return "change_email";
代码示例来源:origin: spring-projects/spring-integration-samples
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
LoanShark.findLoanShark(id).remove();
model.addAttribute("page", (page == null) ? "1" : page.toString());
model.addAttribute("size", (size == null) ? "10" : size.toString());
return "redirect:/loansharks?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());
}
代码示例来源:origin: cloudfoundry/uaa
@RequestMapping(value="/change_password.do", method = POST)
public String changePassword(
Model model,
@RequestParam("current_password") String currentPassword,
@RequestParam("new_password") String newPassword,
@RequestParam("confirm_password") String confirmPassword,
HttpServletResponse response,
HttpServletRequest request) {
model.addAttribute("message_code", validation.getMessageCode());
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
return "change_password";
request.getSession().invalidate();
request.getSession(true);
if (authentication instanceof UaaAuthentication) {
UaaAuthentication uaaAuthentication = (UaaAuthentication)authentication;
return "redirect:profile";
} catch (BadCredentialsException e) {
model.addAttribute("message_code", "unauthorized");
} catch (InvalidPasswordException e) {
model.addAttribute("message", e.getMessagesAsOneString());
代码示例来源:origin: cloudfoundry/uaa
@RequestMapping(value = {"/login"}, headers = "Accept=text/html, */*")
public String loginForHtml(Model model,
Principal principal,
HttpServletRequest request,
@RequestHeader(value = "Accept", required = false) List<MediaType> headers)
throws HttpMediaTypeNotAcceptableException {
boolean match =
headers == null || headers.stream().anyMatch(mediaType -> mediaType.isCompatibleWith(MediaType.TEXT_HTML));
if (!match) {
throw new HttpMediaTypeNotAcceptableException(request.getHeader(HttpHeaders.ACCEPT));
}
Cookie[] cookies = request.getCookies();
List<SavedAccountOptionModel> savedAccounts = getSavedAccounts(cookies, SavedAccountOptionModel.class);
savedAccounts.forEach(account -> {
Color color = ColorHash.getColor(account.getUserId());
account.assignColors(color);
});
model.addAttribute("savedAccounts", savedAccounts);
return login(model, principal, Arrays.asList(PASSCODE, MFA_CODE), false, request);
}
代码示例来源:origin: Foreveriss/SpringBoot
@RequestMapping(value = "/message/inner", method = RequestMethod.GET)
public String inner(HttpServletRequest request, Model model) {
request.setAttribute("requestMessage", "mldnjava-request");
request.getSession().setAttribute("sessionMessage", "mldnjava-session");
request.getServletContext().setAttribute("applicationMessage",
"mldnjava-application");
model.addAttribute("url", "www.mldn.cn");
request.setAttribute("url2",
"<span style='color:red'>www.mldn.cn</span>");
return "message/message_show_inner";
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
@RequestMapping(value = "/" + URL, method = RequestMethod.GET)
public String endSession(@RequestParam (value = "id_token_hint", required = false) String idTokenHint,
@RequestParam (value = "post_logout_redirect_uri", required = false) String postLogoutRedirectUri,
@RequestParam (value = STATE_KEY, required = false) String state,
HttpServletRequest request,
HttpServletResponse response,
session.setAttribute(REDIRECT_URI_KEY, postLogoutRedirectUri);
session.setAttribute(STATE_KEY, state);
session.setAttribute(CLIENT_KEY, client);
if (auth == null || !request.isUserInRole("ROLE_USER")) {
m.addAttribute("client", client);
m.addAttribute("idToken", idTokenClaims);
代码示例来源:origin: qiurunze123/miaosha
@RequestMapping(value="/to_detail2/{goodsId}",produces="text/html")
@ResponseBody
public String detail2(HttpServletRequest request, HttpServletResponse response, Model model,MiaoshaUser user,
@PathVariable("goodsId")long goodsId) {
model.addAttribute("user", user);
model.addAttribute("goods", goods);
remainSeconds = 0;
model.addAttribute("miaoshaStatus", miaoshaStatus);
model.addAttribute("remainSeconds", remainSeconds);
request.getServletContext(),request.getLocale(), model.asMap(), applicationContext );
html = viewResolver.getTemplateEngine().process("goods_detail", ctx);
if(!StringUtils.isEmpty(html)) {
代码示例来源:origin: stackoverflow.com
public String editProgram(HttpServletRequest request, HttpServletResponse response) {
if (request.getSession().getAttribute(Constants.LOGGED_IN_USER) != null) {
ProgramEntity program = new ProgramEntity();
if (request.getParameter("id") == null) {// create
program.setType("create");
} else {// edit
program.setType("edit");
program.setCode(request.getParameter("id"));
if (session.getAttribute(Constants.LOGGED_IN_USER) != null) {
model.addAttribute("programBean", new ProgramEntity());
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value = "/scheduler/{flowId}", method = RequestMethod.GET)
@Secured(ConsoleSecurityRoles.ROLE_PROCESS_VIEW)
public String showScheduleView(@PathVariable String flowId, Model model) {
model.asMap().putAll(createModelForShowForm(flowId, null));
return "platform/scheduledTask/definitionStart";
}
代码示例来源:origin: cloudfoundry/uaa
public void transferErrorParameters(Model model, HttpServletRequest request) {
for (String p : Arrays.asList("error_message_code", "error_code", "error_message")) {
if (hasText(request.getParameter(p))) {
model.addAttribute(p, request.getParameter(p));
}
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-portal-core
/**
* Handler for myContacts display
*
* @return view name
*/
@RequestMapping(value = ViewConstants.USER_MY_CONTACTS, method = RequestMethod.GET)
@Secured(PortalUserRoles.USER)
public String dashboardHandler(Model model, HttpServletRequest request, Locale locale) {
model.addAttribute("contacts", contactsService.fetchContacts());
return ViewConstants.USER_MY_CONTACTS;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@PathVariable(value="id") String id) throws Exception {
// Get the normal entity form for this item
String returnPath = super.viewEntityForm(request, response, model, pathVars, id);
EntityForm ef = (EntityForm) model.asMap().get("entityForm");
// Remove List Grid for Additional Fields
ef.removeListGrid("additionalFields");
return returnPath;
}
内容来源于网络,如有侵权,请联系作者删除!