本文整理汇总了Java中org.springframework.ui.ModelMap.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ModelMap.addAttribute方法的具体用法?Java ModelMap.addAttribute怎么用?Java ModelMap.addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.ui.ModelMap
的用法示例。
在下文中一共展示了ModelMap.addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
/**
* @param type Type of data sought
* @param q Search for a phrase
* @param page Page number
* @param pageSize Number of items per page
* @param modelMap {@link ModelMap}
* @return The ModelAndView for a list of users (or a list of movies( in the future ))
*/
@GetMapping(value = "/search")
public ModelAndView search(
@RequestParam final String type,
@RequestParam final String q,
@RequestParam(defaultValue = "1") final int page,
@RequestParam(defaultValue = "1") final int pageSize,
final ModelMap modelMap
) {
modelMap.addAttribute("type", type);
modelMap.addAttribute("q", q);
modelMap.addAttribute("page", page);
modelMap.addAttribute("pageSize", pageSize);
return new ModelAndView("users", modelMap);
}
示例2: handleAdmin
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping(value="/admin", method = RequestMethod.GET)
public String handleAdmin(ModelMap model, Principal principal ) {
System.out.println("***********LoginController handleAdmin Called***********");
String name = principal.getName();
model.addAttribute("username", name);
model.addAttribute("message", "This is admin area");
return "admin";
}
示例3: all
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequiresPermissions("video:view")
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String all(ModelMap map) {
List<Video> videos = videoService.findAll();
map.addAttribute("videos", videos);
return "/video/index.ftl";
}
示例4: processSignup
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@PostMapping("/sign-up")
public String processSignup(ModelMap model, @Valid SignupForm form, BindingResult result){
if(result.hasErrors()){
model.addAttribute(form);
log.warn("Form contains error {} ", form );
}else{
User user = form.toUser();
signupHelper.signupAndSignInUser(user);
verifyAction.with(user, "/?welcome=1");
return "redirect:/verify";
}
return "sign-up";
}
示例5: index
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping("/hello")
public String index(ModelMap map) {
// 加入一个属性,用来在模板中读取
map.addAttribute("host", "http://blog.didispace.com");
// return模板文件的名称,对应src/main/resources/templates/index.html
return "index";
}
示例6: validUser
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String validUser(String loginName, String password, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
logger.debug("login {loginName:" + loginName + ",password:" + password + "}");
User user = userService.getUserByLoginName(loginName);
if (user != null && user.getPassword().equals(password)) {
model.put("message", "登录成功");
} else {
model.put("message", "用户验证失败");
}
model.addAttribute("loginName", loginName);
return "test";
}
示例7: listUsers
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
/**
* This method will list all existing users.
*/
@RequestMapping(value = {"/adm/list"}, method = RequestMethod.GET)
public String listUsers(ModelMap model) {
List<AdmUser> users = userService.findAllUsers();
model.addAttribute("users", users);
model.addAttribute("loggedinuser", getPrincipal());
return "userslist";
}
示例8: index
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@GetMapping("/")
public String index(ModelMap modelMap, Principal principal) {
long articlesCount = articleService.getArticlesCount(principal.getName());
List<Article> articles = articleService.getArticlesOfOnePage(principal.getName(), 1);
modelMap.addAttribute("articles", articles);
modelMap.addAttribute("articlesCount", articlesCount);
modelMap.addAttribute("isIndex", true);
return "article/index";
}
示例9: afficher
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping(value="/afficherSuppressionToDoList", method = RequestMethod.GET)
public String afficher(final ModelMap pModel) {
//Création d'un objet ToDoList puis Lecture de la table
final List<ToDoList> lToDoLists = service.RechercherToDoList();
pModel.addAttribute("todolist", lToDoLists);
return "suppression";
}
示例10: propertyEncoder
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping ( "propertyEncoder" )
public String propertyEncoder ( ModelMap modelMap,
@RequestParam ( value = "path" , required = false , defaultValue = "none" ) String path,
HttpServletRequest request, HttpSession session )
throws IOException {
setCommonAttributes( modelMap, session, "Property Encoder" );
modelMap.addAttribute( "name", Application.getHOST_NAME() );
return "misc/property-encoder";
}
示例11: preview
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
/**
* 预览项目文档
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/preview", method = RequestMethod.GET)
public String preview(ModelMap model, @RequestParam(value = "id", required = true) Long id) {
List<Module> modules = moduleService.selectByProjectId(id);
model.addAttribute("modules", modules);
model.addAttribute("project", getProject(id));
return "project/preview";
}
示例12: saveStudentUser
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
/**
* This method will be called on form submission, handling POST request for
* saving user in database. It also validates the user input
*/
@RequestMapping(value = {"/studentregistration"}, method = RequestMethod.POST)
public String saveStudentUser(@Valid StudentUser user, BindingResult result,
ModelMap model) {
if (result.hasErrors()) {
return "studentregistration";
}
/*
* Preferred way to achieve uniqueness of field [sso] should be implementing custom @Unique annotation
* and applying it on field [sso] of Model class [User].
*
* Below mentioned peace of code [if block] is to demonstrate that you can fill custom errors outside the validation
* framework as well while still using internationalized messages.
*
*/
if (!userService.isStudentUnique(user.getStudentUserId(), user.getEmail())) {
FieldError ssoError = new FieldError("studentuser", "email", messageSource.getMessage("non.unique.ssoId",
new String[]{user.getEmail()}, Locale.getDefault()));
result.addError(ssoError);
model.addAttribute("loggedinuser", getPrincipal());
return "studentregistration";
}
userService.saveUser(user);
model.addAttribute("success", "User " + user.getFirstName() + " " + user.getLastName() + " registered successfully");
model.addAttribute("loggedinuser", getPrincipal());
//return "success";
return "registrationsuccess";
}
示例13: all
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequiresRoles("admin")
@RequiresPermissions("admin:view")
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String all(ModelMap map) {
List<Admin> admins = adminService.findAll();
map.addAttribute("admins", admins);
return "/account/index.ftl";
}
示例14: updateTodo
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@RequestMapping(value = "/update-todo", method = RequestMethod.GET)
public String updateTodo(ModelMap model, @RequestParam int id) {
Todo todo = service.retrieveTodo(id);
model.addAttribute("todo", todo);
return "todo";
}
示例15: showSignupForm
import org.springframework.ui.ModelMap; //导入方法依赖的package包/类
@GetMapping("/sign-up")
public String showSignupForm(ModelMap model){
model.addAttribute(new SignupForm());
return "sign-up";
}