Индекс контроллера:Включить шаблон для применения Springboot/Thymeleaf
@Controller
public class IndexController {
private static final Logger log = LoggerFactory.getLogger(TmtApplication.class);
@Autowired
UsersRepository usersRepository;
@RequestMapping("/index")
String index(){
return "index";
}
}
MVC Config:
@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?
Что означает параметр «» мой-шаблон»вы предоставили сделать? – santafebound
Это значение должно быть вставлено в
–Я вижу, что вы имеете в виду, но это значение всегда должно отличаться в зависимости от того, какой URL-адрес пользователь нажал. Одна из моих ссылок выглядит так, например, '' Make a Request ''. Он должен загрузить index.html и заменить содержимое div на request.html. – santafebound