Home > Software engineering >  Why doesn't ModelAndView add a property?
Why doesn't ModelAndView add a property?

Time:06-03

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"  allowFullScreen></iframe>
<p><a href="${embedUrl}">text</a></p>

</body>
</html>

CodePudding user response:

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

CodePudding user response:

Use th:src and th:href.

<iframe th:src="${resultUrl}" width="980" height="560" frameBorder="0"  allowFullScreen></iframe>
<p><a th:href="${embedUrl}">text</a></p>
  • Related