【问题标题】:Path Variable not working - 404 resource not available路径变量不起作用 - 404 资源不可用
【发布时间】:2017-03-02 23:03:47
【问题描述】:

这是我的 java 控制器:

@Controller
@RequestMapping("/resetPassword")

@Service
public class GmiResetPasswordController {
 @RequestMapping(value = "/resetPassword/{id}/{token}", method = RequestMethod.GET)
        public
        @ResponseBody
        AnalystDetails getDetails(Model model, HttpServletRequest request, @PathVariable("id") int id, @PathVariable("token") String token) { 
//getDetails
[...]

我正在尝试使用这个网址:http://localhost:8080/resetPassword/59/3e3ac731-3ac4-45eb-8bf6-5f8e4b00298c

这是我的 Spring Security xml:

<security:http pattern="/resetPassword/**" security="none">
</security:http>

有什么帮助吗??

编辑 将控制器更改为:

@Controller
@RequestMapping("/resetPassword")
public class GmiResetPasswordController {
 @RequestMapping(value = "/{id}/{token}", method = RequestMethod.GET)
        public
        @ResponseBody
        AnalystDetails getDetails(Model model, HttpServletRequest request, @PathVariable(value = "id") int id, @PathVariable(value = "token") String token) {
[...] 
}

还是不行..这是链接:http://localhost:8080/resetPassword/59/52ed96c3-5041-4ff9-be66-0aa2dbeca713

【问题讨论】:

  • 为什么你的控制器被@Service注解了?删除服务注释。您正在控制器级别和方法级别映射到 resetPassword,因此您要映射的 url 是 /resetPassword/resetPassword/{id}/{token} 删除其中之一。

标签: java spring


【解决方案1】:

你的映射应该是这样的:

@Controller
@RequestMapping("/resetPassword")
public class GmiResetPasswordController {

    @RequestMapping(value = "/{id}/{token}", method = RequestMethod.GET)
    @ResponseBody
    public AnalystDetails getDetails(Model model, HttpServletRequest request, @PathVariable("id") int id, @PathVariable("token") String token) { 

        //...

    }

}

【讨论】:

    猜你喜欢
    • 2013-06-10
    • 2014-01-20
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多