BVB Source Codes

spring-mvc-showcase Show RedirectController.java Source code

Return Download spring-mvc-showcase: download RedirectController.java Source code - Download spring-mvc-showcase Source code - Type:.java
  1. package org.springframework.samples.mvc.redirect;
  2.  
  3. import javax.inject.Inject;
  4.  
  5. import org.joda.time.LocalDate;
  6. import org.springframework.core.convert.ConversionService;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.PathVariable;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  13. import org.springframework.web.util.UriComponents;
  14. import org.springframework.web.util.UriComponentsBuilder;
  15.  
  16. @Controller
  17. @RequestMapping("/redirect")
  18. public class RedirectController {
  19.        
  20.         private final ConversionService conversionService;
  21.  
  22.         @Inject
  23.         public RedirectController(ConversionService conversionService) {
  24.                 this.conversionService = conversionService;
  25.         }
  26.  
  27.         @RequestMapping(value="/uriTemplate", method=RequestMethod.GET)
  28.         public String uriTemplate(RedirectAttributes redirectAttrs) {
  29.                 redirectAttrs.addAttribute("account", "a123");  // Used as URI template variable
  30.                 redirectAttrs.addAttribute("date", new LocalDate(2011, 12, 31));  // Appended as a query parameter
  31.                 return "redirect:/redirect/{account}";
  32.         }
  33.  
  34.         @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET)
  35.         public String uriComponentsBuilder() {
  36.                 String date = this.conversionService.convert(new LocalDate(2011, 12, 31), String.class);
  37.                 UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date)
  38.                                 .build().expand("a123").encode();
  39.                 return "redirect:" + redirectUri.toUriString();
  40.         }
  41.  
  42.         @RequestMapping(value="/{account}", method=RequestMethod.GET)
  43.         public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) {
  44.                 return "redirect/redirectResults";
  45.         }
  46.  
  47. }
  48.  
downloadRedirectController.java Source code - Download spring-mvc-showcase Source code
Related Source Codes/Software:
tushare - TuShare is a utility for crawling historical data ... 2017-01-12
raml-spec - RAML Specification http://raml.... 2017-01-12
android-stackblur - Android StackBlur is a library that can perform a ... 2017-01-12
sound-redux - A Soundcloud client built with React / Redux ... 2017-01-12
httpstat - curl statistics made simple 2017-01-12
discover-flask - Full Stack Web Development with Flask. ... 2017-01-12
micro - Async HTTP microservices made easy ... 2017-01-12
gobot - Golang framework for robotics, drones, and the Int... 2017-01-11
mas - 2017-01-13
Zappa - Serverless Python Web Services ... 2017-01-12
FrameworkBenchmarks - Source code for the framework benchmarking project... 2017-02-22
buildbot - Python-based continuous integration testing framew... 2017-02-22
rufus - The Reliable USB Formatting Utility ... 2017-02-22
uiGradients - Beautiful colour gradients for design and code ... 2017-02-22
Haxl - A Haskell library that simplifies access to remote... 2017-02-21
duktape - Duktape - embeddable Javascript engine with a focu... 2017-02-21
scala-best-practices - A collection of Scala best practice 2017-02-21
hammerspoon - Staggeringly powerful OS X desktop automation with... 2017-02-21
DGElasticPullToRefresh - Elastic pull to refresh for iOS developed in Swift 2017-02-21
evercookie - evercookie is a javascript API that produces extre... 2017-02-21

 Back to top