Why doesn't ModelAndView add a property?

42 Views Asked by At

i have such a RestController

@Controller
public class ExchangeRateController {

    private final static Logger LOGGER = LoggerFactory.getLogger(ExchangeRateController.class);
    
    @GetMapping(value = "/current")
    public ModelAndView geExchangeRate(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("Response.html");
        modelAndView.addObject("resultUrl",url);
        modelAndView.addObject("embedUrl",embedUrl);
        return modelAndView;

    }

}

Inside, I get the URL of the image and want to embed it using Model on my page.But it gives me an error 404 or an empty page, although if to take these addresses and just write in an html file, then everything works.How can this be done so that they are added to the place of scr and href?

<!DOCTYPE HTML>
<html>
<head>

</head>

<body>

<iframe src="${resultUrl}" width="980" height="560" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
<p><a href="${embedUrl}">text</a></p>

</body>
</html>
2

There are 2 best solutions below

0
On

Use th:src and th:href.

<iframe th:src="${resultUrl}" width="980" height="560" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
<p><a th:href="${embedUrl}">text</a></p>
0
On

Try to use @Controller instead of @RestController and change @RequestMapping("/current")