Java Code Examples for org.springframework.ui.Model#addAttribute()
The following examples show how to use
org.springframework.ui.Model#addAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticleController.java From mayday with GNU General Public License v3.0 | 6 votes |
/** * 修改文章页面 * * @param model * @return */ @GetMapping(value = "/edit") public String editArticle(Model model, @RequestParam(value = "article_id") Integer article_id) { try { // 获取所有分类 List<Category> categorys = categoryService.findCategory(); // 获取所有标签 List<Tag> tags = tagService.findTags(); // 获取文章信息 ArticleCustom articleCustom = articleService.findByArticleId(article_id); model.addAttribute("categorys", categorys); model.addAttribute("tags", tags); model.addAttribute("articleCustom", articleCustom); } catch (Exception e) { log.error(e.getMessage()); } return "admin/admin_edit_article"; }
Example 2
Source File: BaseTreeableController.java From es with Apache License 2.0 | 6 votes |
@RequestMapping(value = "{source}/move", method = RequestMethod.POST) @PageableDefaults(sort = {"parentIds=asc", "weight=asc"}) public String move( HttpServletRequest request, @RequestParam(value = "async", required = false, defaultValue = "false") boolean async, @PathVariable("source") M source, @RequestParam("target") M target, @RequestParam("moveType") String moveType, Searchable searchable, Model model, RedirectAttributes redirectAttributes) { if (this.permissionList != null) { this.permissionList.assertHasEditPermission(); } if (target.isRoot() && !moveType.equals("inner")) { model.addAttribute(Constants.ERROR, "不能移动到根节点之前或之后"); return showMoveForm(request, async, source, searchable, model); } baseService.move(source, target, moveType); redirectAttributes.addFlashAttribute(Constants.MESSAGE, "移动节点成功"); return redirectToUrl(viewName("success")); }
Example 3
Source File: PostsController.java From expper with GNU General Public License v3.0 | 6 votes |
@RequestMapping(value = "posts/{id:\\d+}", method = RequestMethod.GET) @Timed public String showPost(@PathVariable Long id, Model model) { Post post = postService.getPost(id); if (post == null || post.getStatus() != PostStatus.PUBLIC) { throw new PageNotFoundException("没有找到文章(" + id + ")"); } countingService.incPostHits(id); Vote vote = null; if (SecurityUtils.isAuthenticated()) { vote = voteService.checkUserVote(id, userService.getCurrentUserId()); } model.addAttribute("vote", vote); model.addAttribute("post", post); model.addAttribute("counting", countingService.getPostCounting(id)); return "posts/show"; }
Example 4
Source File: BasePage.java From ExamStack with GNU General Public License v2.0 | 5 votes |
@RequestMapping(value = { "/user-login-page" }, method = RequestMethod.GET) public String loginPage(Model model, @RequestParam(value = "result", required = false, defaultValue = "") String result) { if("failed".equals(result)){ model.addAttribute("result", "无效的用户名或者密码"); } return "login"; }
Example 5
Source File: DictTypeController.java From lemon with Apache License 2.0 | 5 votes |
@RequestMapping("dict-type-input") public String input(@RequestParam(value = "id", required = false) Long id, Model model) { if (id != null) { DictType dictType = dictTypeManager.get(id); model.addAttribute("model", dictType); } return "dict/dict-type-input"; }
Example 6
Source File: ErrorController.java From Spring-Security-Third-Edition with MIT License | 5 votes |
@ExceptionHandler(Throwable.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public String exception(final Throwable throwable, final Model model) { logger.error("Exception during execution of SpringSecurity application", throwable); String errorMessage = (throwable != null ? throwable.getMessage() : "Unknown error"); model.addAttribute("error", errorMessage); return "error"; }
Example 7
Source File: TablonController.java From spring-cloud-aws-sample with Apache License 2.0 | 5 votes |
@RequestMapping("/anuncio/nuevo") public String nuevoAnuncio(Model model, @RequestParam String nombre, @RequestParam String asunto, @RequestParam String comentario, @RequestParam String filename, @RequestParam MultipartFile file) { if (!file.isEmpty()) { try { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(file.getContentType()); TransferManager transferManager = TransferManagerBuilder.defaultTransferManager(); transferManager.upload(bucket, filename, file.getInputStream(), objectMetadata); } catch (Exception e) { model.addAttribute("message", "You failed to upload " + filename + " => " + e.getMessage()); return "error"; } } else { model.addAttribute("message", "You failed to upload " + filename + " because the file was empty."); return "error"; } Anuncio anuncio = new Anuncio(nombre, asunto, comentario); anuncio.setFoto(s3.getUrl(bucket, filename)); repository.save(anuncio); return "anuncio_guardado"; }
Example 8
Source File: BackgroundJobRpcController.java From proctor with Apache License 2.0 | 5 votes |
/** * sets spring model jobs attribute * @return new spring view name */ @RequestMapping(value = "/list", method = RequestMethod.GET) public String doGetJobList(final Model model) { final List<BackgroundJob<?>> jobs = manager.getRecentJobs(); model.addAttribute("session", SessionViewModel.builder() .setUseCompiledCSS(configuration.isUseCompiledCSS()) .setUseCompiledJavaScript(configuration.isUseCompiledJavaScript()) .build()); model.addAttribute("jobs", jobs); return ProctorView.JOBS.getName(); }
Example 9
Source File: QuestionPageAdmin.java From ExamStack with GNU General Public License v2.0 | 5 votes |
/** * 添加试题页面 * * @param model * @return */ @RequestMapping(value = "/admin/question/question-add", method = RequestMethod.GET) public String questionAddPage(Model model) { List<Field> fieldList = questionService.getAllField(null); model.addAttribute("fieldList", fieldList); return "question-add"; }
Example 10
Source File: ExamPageAdmin.java From ExamStack with GNU General Public License v2.0 | 5 votes |
/** * 模拟考试列表 * @param model * @param request * @param page * @return */ @RequestMapping(value = "/admin/exam/model-test-list", method = RequestMethod.GET) private String modelTestListPage(Model model, HttpServletRequest request, @RequestParam(value="page",required=false,defaultValue="1") int page) { Page<Exam> pageModel = new Page<Exam>(); pageModel.setPageNo(page); pageModel.setPageSize(10); List<Exam> examList = examService.getExamList(pageModel,3); String pageStr = PagingUtil.getPageBtnlink(page, pageModel.getTotalPage()); model.addAttribute("examList", examList); model.addAttribute("pageStr", pageStr); return "model-test-list"; }
Example 11
Source File: AccountController.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@PostMapping("register") public String register( @Valid RegisterForm form, BindingResult bindingResult, Model model) { List<String> errors = toList(bindingResult); String path; if(errors.isEmpty()) { path = REGISTER_SUCCESS_PATH; Optional<Account> optionalAcct = accountService.tryCreateUser( form.getEmail(), form.getUsername(), form.getPassword()); if(optionalAcct.isPresent()) { emailService.validationLink(optionalAcct.get()); } else { emailService.failedRegistration( form.getUsername(), form.getEmail()); } } else { path = REGISTER_FORM_PATH; model.addAttribute("errors", errors); } return path; }
Example 12
Source File: XxlApiUserController.java From xxl-api with GNU General Public License v3.0 | 5 votes |
@RequestMapping @PermessionLimit(superUser = true) public String index(Model model) { List<XxlApiBiz> bizList = xxlApiBizDao.loadAll(); model.addAttribute("bizList", bizList); return "user/user.list"; }
Example 13
Source File: LoanController.java From hermes with Apache License 2.0 | 5 votes |
@RequestMapping("/charge") public String charge(String amount, String accountId, Model model) { String eL = "^//d*[1-9]//d*$";// 正整数 if (Strings.empty(amount) || Pattern.compile(eL).matcher(amount).matches()) { throw new ServiceException("充值操作:金额=" + amount + ",不是正整数"); } if (Strings.empty(accountId)) { throw new ServiceException("充值操作:债权人ID 为空"); } UserAccount userAccount = loanService.accountCharge(amount, accountId); model.addAttribute("account", userAccount); return "loan/loanCharge"; }
Example 14
Source File: AppController.java From cachecloud with Apache License 2.0 | 5 votes |
/** * 命令曲线 * @param firstCommand 第一条命令 */ @RequestMapping("/commandAnalysis") public ModelAndView appCommandAnalysis(HttpServletRequest request, HttpServletResponse response, Model model, Long appId, String firstCommand) throws ParseException { // 1.获取app的VO AppDetailVO appDetail = appStatsCenter.getAppDetail(appId); model.addAttribute("appDetail", appDetail); // 2.返回日期 TimeBetween timeBetween = getTimeBetween(request, model, "startDate", "endDate"); // 3.是否超过1天 if (timeBetween.getEndTime() - timeBetween.getStartTime() > TimeUnit.DAYS.toMillis(1)) { model.addAttribute("betweenOneDay", 0); } else { model.addAttribute("betweenOneDay", 1); } // 4.获取top命令 List<AppCommandStats> allCommands = appStatsCenter.getTopLimitAppCommandStatsList(appId, timeBetween.getStartTime(), timeBetween.getEndTime(), 20); model.addAttribute("allCommands", allCommands); if (StringUtils.isBlank(firstCommand) && CollectionUtils.isNotEmpty(allCommands)) { model.addAttribute("firstCommand", allCommands.get(0).getCommandName()); } else { model.addAttribute("firstCommand", firstCommand); } model.addAttribute("appId", appId); // 返回标签名 return new ModelAndView("app/appCommandAnalysis"); }
Example 15
Source File: SkuInfoController.java From lemon with Apache License 2.0 | 5 votes |
@RequestMapping("sku-info-input") public String input(@RequestParam(value = "id", required = false) Long id, Model model) { if (id != null) { SkuInfo skuInfo = skuInfoManager.get(id); model.addAttribute("model", skuInfo); } String hql = "from SkuCategory where skuCategory is null"; List<SkuInfo> skuCategories = this.skuInfoManager.find(hql); model.addAttribute("skuCategories", skuCategories); return "asset/sku-info-input"; }
Example 16
Source File: ConsoleController.java From lemon with Apache License 2.0 | 5 votes |
/** * 准备迁移流程. */ @RequestMapping("console-migrateInput") public String migrateInput( @RequestParam("processInstanceId") String processInstanceId, Model model) { model.addAttribute("processInstanceId", processInstanceId); model.addAttribute("processDefinitions", processEngine .getRepositoryService().createProcessDefinitionQuery().list()); return "bpm/console-migrateInput"; }
Example 17
Source File: AdminUserAdminController.java From pybbs with GNU Affero General Public License v3.0 | 4 votes |
@RequiresPermissions("admin_user:list") @GetMapping("/list") public String list(Model model) { model.addAttribute("adminUsers", adminUserService.selectAll()); return "admin/admin_user/list"; }
Example 18
Source File: StudentController.java From ssm-Online_Examination with Apache License 2.0 | 4 votes |
@RequestMapping(value = "savescore.do") public String SaveScore(@RequestParam int allscore, @RequestParam String examname, Model model){ model.addAttribute("score",allscore); return "page/student/score"; }
Example 19
Source File: DisplayController.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 4 votes |
@GetMapping("/") public String index(Model model) { List<Message> newest = new ArrayList<>(messageService.newestMessages(10).getContent()); model.addAttribute("newest", newest); return INDEX_PATH; }
Example 20
Source File: TagAdminController.java From pybbs with GNU Affero General Public License v3.0 | 4 votes |
@RequiresPermissions("tag:edit") @GetMapping("/edit") public String edit(Integer id, Model model) { model.addAttribute("tag", tagService.selectById(id)); return "admin/tag/edit"; }