本文整理匯總了Java中org.springframework.ui.Model.asMap方法的典型用法代碼示例。如果您正苦於以下問題:Java Model.asMap方法的具體用法?Java Model.asMap怎麽用?Java Model.asMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.ui.Model
的用法示例。
在下文中一共展示了Model.asMap方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLogin
import org.springframework.ui.Model; //導入方法依賴的package包/類
@GetMapping
public String getLogin(Model model, RedirectAttributes redirectAttributes) {
// Keep flash attributes in the next view
Map<String, Object> attributesMap = model.asMap();
for (String modelKey : attributesMap.keySet()) {
redirectAttributes.addFlashAttribute(modelKey, attributesMap.get(modelKey));
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Object userAccountObject = auth.getPrincipal();
boolean isInstanceOfUserAccount = userAccountObject instanceof UserAccount;
if (!isInstanceOfUserAccount) {
log.info("Redirect from / to /login");
return "redirect:/login";
}
UserAccount userAccount = (UserAccount) userAccountObject;
if (userAccount.hasRole(Role.ADMIN)) {
return "redirect:/admin/studyplans";
} else if (userAccount.hasRole(Role.LECTURER)) {
return "redirect:/lecturer/courses";
} else {
return "redirect:/student/courses";
}
}
示例2: deleteTokenFrom
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Delete token from specified model
*
* @param model
*/
public void deleteTokenFrom(Model model) {
if (model.asMap() == null || model.asMap().get(modelTokenName) == null) {
logger.error("Token not found: " + model);
} else {
model.asMap().put(modelTokenName, null);
}
}
示例3: showLists
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Send user to a page showing all his lists
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ModelAndView showLists(Principal principal, Model model) {
LOGGER.debug("home() method of MvcController called for user: {}", principal.getName());
ModelAndView mav = new ModelAndView("showAllLists", model.asMap());
List<ShoppingList> shoppingLists = repositoryService.getShoppingLists(principal.getName());
mav.addObject("shoppingLists", shoppingLists); //current ShoppingLists of the user to display
if(!model.containsAttribute("newList"))
mav.addObject("newList", new ShoppingListDTO()); //backing object for name of the new ShoppingList
mav.addObject("listToDelete", new ShoppingListDTO()); //backing object for ShoppingList to delete
return mav;
}
示例4: showRegistrationForm
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Shows registration form for unlogged users, if user is logged shows message and link to the home page
* @param model
*/
@RequestMapping(value = "/register", method = RequestMethod.GET)
public ModelAndView showRegistrationForm(Model model) {
LOGGER.debug("showRegistrationForm() called");
ModelAndView mav = new ModelAndView("register", model.asMap());
if(!model.containsAttribute("newUser"))
mav.addObject("newUser", new AppUserDTO());
return mav;
}
示例5: notifyModal
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Da usare direttamente solo quando si vuole fare un redirect dopo aver mostrato un messaggio.
* Se chiamato tante volte, i messaggi si sommano e vengono mostrati tutti all'utente.
* @param title
* @param message
* @param severity a string like YadaConstants.VAL_NOTIFICATION_SEVERITY_OK
* @param redirectSemiurl e.g. "/user/profile"
* @param model
* @see YadaConstants
* @deprecated Use YadaNotify instead
*/
@Deprecated
public void notifyModal(String title, String message, String severity, String redirectSemiurl, Model model) {
if (severity==VAL_NOTIFICATION_SEVERITY_ERROR) {
// Tutte le notifiche di errore vengono loggate a warn (potrebbero non essere degli errori del programma)
log.warn("notifyModal: {} - {}", title, message);
}
// Mette nel model tre array di stringhe che contengono titolo, messaggio e severity.
if (!model.containsAttribute(KEY_NOTIFICATION_TITLE)) {
List<String> titles = new ArrayList<String>();
List<String> bodies = new ArrayList<String>();
List<String> severities = new ArrayList<String>();
model.addAttribute(KEY_NOTIFICATION_TITLE, titles);
model.addAttribute(KEY_NOTIFICATION_BODY, bodies);
model.addAttribute(KEY_NOTIFICATION_SEVERITY, severities);
}
// Aggiunge i nuovi valori
Map<String, Object> modelMap = model.asMap();
((List<String>)modelMap.get(KEY_NOTIFICATION_TITLE)).add(title);
((List<String>)modelMap.get(KEY_NOTIFICATION_BODY)).add(message);
((List<String>)modelMap.get(KEY_NOTIFICATION_SEVERITY)).add(severity);
// Il redirect è sempre uno solo: prevale l'ultimo
if (redirectSemiurl!=null) {
model.addAttribute(KEY_NOTIFICATION_REDIRECT, redirectSemiurl);
}
String newTotalSeverity = calcTotalSeverity(modelMap, severity);
model.addAttribute(KEY_NOTIFICATION_TOTALSEVERITY, newTotalSeverity);
}
示例6: callScriptOnModal
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Add a script id to call when opening the notification modal
* @param scriptId
* @param model
* @deprecated Use YadaNotify instead
*/
@Deprecated
public void callScriptOnModal(String scriptId, Model model) {
if (!model.containsAttribute(KEY_NOTIFICATION_CALLSCRIPT)) {
List<String> scriptIds = new ArrayList<String>();
model.addAttribute(KEY_NOTIFICATION_CALLSCRIPT, scriptIds);
}
Map<String, Object> modelMap = model.asMap();
((List<String>)modelMap.get(KEY_NOTIFICATION_CALLSCRIPT)).add(scriptId);
}