【发布时间】:2023-03-22 14:25:01
【问题描述】:
索引控制器:
@Controller
public class IndexController {
private static final Logger log = LoggerFactory.getLogger(TmtApplication.class);
@Autowired
UsersRepository usersRepository;
@RequestMapping("/index")
String index(){
return "index";
}
}
MVC 配置:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/index").setViewName("index");
registry.addViewController("/login").setViewName("login");
registry.addViewController("/request").setViewName("index");
registry.addViewController("/requests").setViewName("index");
registry.addViewController("/team").setViewName("index");
}
}
在 PHP 中,当我们点击一个新链接时,我们希望在模板的一部分中替换掉一个简单的包含函数:
<a href="index.php?action=notifications">notifications</a>
if (!empty($_GET['action'])) {
$action = $_GET['action'];
$action = basename($action);
if (file_exists("templates/$action.htm")
$action = "index";
include("templates/$action.htm");
} else {
include("templates/index.htm");
}
在我的 index.html 上:
<body>
<div class="container" style="width: 100% !important;">
<div th:replace="fragments/header :: header"></div>
// Include dynamic content here depending on which menu item was clicked
<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>
<div th:replace="fragments/footer :: footer"></div>
</div>
</body>
Springboot/Thymeleaf 的等价物是什么?
【问题讨论】:
标签: java spring-boot thymeleaf templating