当thymeleaf取到的数据有html标签的时候

/**
 * @author think
 */
@Controller
@RequestMapping("springboot")
public class HelloController {
    
    

    @RequestMapping("test")
    public String hello(Model model){
    
    
        model.addAttribute("username", "<a href=''>数据</a>");
        return "index";
    }
}

想要在html的页面拿到username的值使用原来的语法是拿不到的:

<span th:text="${username}"></span>

要使用这个:

<span th:utext="${username}"></span>

utext可以解析字符串里的HTML标签

猜你喜欢

转载自blog.csdn.net/qq_44739706/article/details/114209914