【问题标题】:Accessing url with model and view on Spring Boot project在 Spring Boot 项目中使用模型和视图访问 url
【发布时间】:2021-10-28 23:10:22
【问题描述】:

您好,这里是 Java 新手。

我正在尝试通过 modelAndView 将 URL 发送到使用 thymeleaf 的 html 页面。

我的控制器看起来像这样。

@RequestMapping("/api/test")
public ModelAndView test(){
    ModelAndView modelAndView = new ModelAndView();
    String google = "www.google.com";
    modelAndView.addObject("google", google);
    modelAndView.setViewName("api/googleTest");
    return modelAndView;
}

我使用此属性的按钮看起来像这样

<button class="w-100 btn btn-secondary btn-lg" type="button"
                th:onclick="|location.href='@{{link}(link=${google})}'|">

当我按下按钮时,我的应用程序似乎重定向到 http://localhost:8080/api/www.google.com 而不是 www.google.com

如果有办法解决这个问题,我们将不胜感激。 提前谢谢你!

【问题讨论】:

    标签: java html spring-boot spring-mvc thymeleaf


    【解决方案1】:

    添加“http://”会发生什么?

    点赞String google = "http://www.google.com";

    【讨论】:

      【解决方案2】:

      您错过了将 Path 变量设置到控制器中。

      通过以下网址浏览

      https://www.baeldung.com/spring-pathvariable

      如果仍然不清楚,请回复我。

      【讨论】:

      • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      • 2022-07-09
      • 2016-08-13
      • 1970-01-01
      相关资源
      最近更新 更多