SpringMVC-通过路径传收参数
还有一种通过路径传输参数,效果如下
实现:
package com.aurora.path; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("path") @ResponseBody public class PathController { // path/账号/密码 // 接收路径参数,String account,String password ->接收param格式参数 @RequestMapping("{account}/{password}") public String login(@PathVariable(value = "account") String username, @PathVariable String password){ System.out.println("username = " + username + ", password = " + password); return "username = " + username + ", password = " + password; } }