PathVariableController.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 2013-2018 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.robot.remote.smartrobotremote.demos.web;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. /**
  23. * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
  24. */
  25. @Controller
  26. public class PathVariableController {
  27. // http://127.0.0.1:8080/user/123/roles/222
  28. @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET)
  29. @ResponseBody
  30. public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) {
  31. return "User Id : " + userId + " Role Id : " + roleId;
  32. }
  33. // http://127.0.0.1:8080/javabeat/somewords
  34. @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET)
  35. @ResponseBody
  36. public String getRegExp(@PathVariable("regexp1") String regexp1) {
  37. return "URI Part : " + regexp1;
  38. }
  39. }