0

I have the following code...

@RequestMapping(value = "", method = RequestMethod.GET)
public String messages(Model model) {
    model.addAttribute("apikey", "test");
    return "index";
}
<link th:href="@{'https://maps.googleapis.com/maps/api/js?key=' + ${apikey}}" />

But when I run this I get...

<link href="https://maps.googleapis.com/maps/api/js?key=null">

Config is...

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver
            = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/html/");
    viewResolver.setSuffix("");
    return viewResolver;
}

How do I get it to pass the actual value?

Update

I had the file in the wrong folder so I moved the html to WEB-INF/html but now the template isn't even rendering.

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • what about other variables ? Are they coming fine ? also should not it be `viewResolve.setSuffix(".html");` ? – want2learn May 02 '19 at 17:41
  • I read that if empty it gets all postfixes but I tried it the other way and still nothing. I don't have any other vars because I am just setting up the project. – Jackie May 02 '19 at 17:50
  • [`InternalResourceViewResolver`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/view/InternalResourceViewResolver.html) is not Thymeleaf's `ViewResolver` Seems you should use [`ThymeleafViewResolver`](https://www.thymeleaf.org/apidocs/thymeleaf-spring5/3.0.11.RELEASE/org/thymeleaf/spring5/view/ThymeleafViewResolver.html) instead – Denis Zavedeev May 02 '19 at 18:03
  • And have a look at this instead of string concatenation: https://stackoverflow.com/questions/14938344/thymeleaf-construct-url-with-variable – riddle_me_this May 06 '19 at 04:13

0 Answers0