html 写一个超链接在一个新的页面链接到一个网址 用thymeleaf 后端用spring boot
在 HTML 中,可以使用以下代码来创建一个超链接,并将其链接到一个新的页面:
<a href="https://www.example.com" target="_blank">Link to Example</a>
在使用 Thymeleaf 和 Spring Boot 的情况下,可以使用 Thymeleaf 的语法来创建超链接。例如,可以在 HTML 文件中添加以下代码:
<a th:href="@{https://www.example.com}" target="_blank">Link to Example</a>
在这个例子中,th:href 属性指定了要链接到的网址,target="_blank" 属性指定链接将在一个新的页面中打开。注意,在使用 @{} 语法时,链接的网址应该以 https:// 或 http:// 开头。
在 Spring Boot 中,可以将这个 HTML 文件作为模板文件使用,并在控制器中将其渲染为一个视图。例如,可以创建一个控制器类,如下所示:
@Controller
public class MyController {
@GetMapping("/my-page")
public String myPage(Model model) {
return "my-page";
}
}
在这个例子中,my-page 是模板文件的名称,它应该位于 src/main/resources/templates/ 目录下。在 my-page 模板文件中,可以使用 Thymeleaf 的语法来创建超链接。例如:
<a th:href="@{https://www.example.com}" target="_blank">Link to Example</a>
当用户访问 /my-page 路径时,Spring Boot 将会使用 Thymeleaf 渲染 my-page 模板文件,并将其作为响应返回给用户。用户点击链接时,将会在一个新的页面中打开 https://www.example.com 网址
原文地址: https://www.cveoy.top/t/topic/fcjH 著作权归作者所有。请勿转载和采集!