Подключить CSS к html странице spring
подскажите пожалуйста как подключить файл с таблицами сталей css к html странице для веб приложения на speing mvc? Использую шаблонизатор Thymeleaf.
Класс SecurityConfig
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final UsersDetailsService usersDetailsService;
@Autowired
public SecurityConfig(UsersDetailsService usersDetailsService) {
this.usersDetailsService = usersDetailsService;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/auth/login", "/auth/registration", "/error").permitAll()
.anyRequest().hasAnyRole("USER", "ADMIN")
.and()
.formLogin()
.loginPage("/auth/login")
.loginProcessingUrl("/process_login")
.defaultSuccessUrl("/hello", true)
.failureUrl("/auth/login?error")
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/auth/login");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(usersDetailsService).passwordEncoder(getPasswordEncoder());
}
@Bean
public PasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}
Класс AuthController
@Controller
@RequestMapping("/auth")
public class AuthController {
private final UserValidator userValidator;
private final UserService userService;
@Autowired
public AuthController(UserValidator userValidator, UserService userService) {
this.userValidator = userValidator;
this.userService = userService;
}
@GetMapping("/login")
public String loginPage() {
return "auth/login";
}
@GetMapping("/registration")
public String registrationPage(@ModelAttribute("user") User user) {
return "auth/registration";
}
@PostMapping("/registration")
public String performRegistration(@ModelAttribute("user") @Valid User user, BindingResult bindingResult) {
userValidator.validate(user, bindingResult);
if (bindingResult.hasErrors()) {
System.out.println("d");
return "/auth/registration";
}
userService.registerUser(user);
return "redirect:/auth/login";
}
}
Страница регистрации registration.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" th:href="@{/styles/css/style.css}"/>
<title>Title</title>
</head>
<body>
<form th:method="POST" th:action="@{/auth/registration}" th:object="${user}">
<input type="text" th:field="*{surname}" id="surname" placeholder="Фамилия"/>
<div style="color: red" th:if="${#fields.hasErrors('surname')}" th:errors="*{surname}">Username errors</div>
<br/>
<input type="text" th:field="*{name}" id="name" placeholder="Имя"/>
<div style="color: red" th:if="${#fields.hasErrors('name')}" th:errors="*{name}">Username errors</div>
<br/>
<input type="text" th:field="*{patronymic}" id="patronymic" placeholder="Отчество"/>
<div style="color: red" th:if="${#fields.hasErrors('patronymic')}" th:errors="*{patronymic}">Username errors</div>
<br/>
<input type="text" th:field="*{birthDate}" id="birthDate" placeholder="Дата рождения"/>
<div style="color: red" th:if="${#fields.hasErrors('birthDate')}" th:errors="*{birthDate}">Username errors</div>
<br/>
<input type="text" th:field="*{address}" id="address" placeholder="Адрес"/>
<div style="color: red" th:if="${#fields.hasErrors('address')}" th:errors="*{address}">Username errors</div>
<br/>
<textarea th:field="*{note}" id="note" placeholder="Комментарий"/>
<div style="color: red" th:if="${#fields.hasErrors('note')}" th:errors="*{note}">Username errors</div>
<br/>
<input type="text" th:field="*{username}" id="username" placeholder="User name"/>
<div style="color: red" th:if="${#fields.hasErrors('username')}" th:errors="*{username}">Username errors</div>
<br/>
<input type="password" th:field="*{password}" id="password" placeholder="Password"/>
<div style="color: red" th:if="${#fields.hasErrors('password')}" th:errors="*{password}">password errors</div>
<br/>
<input type="submit" value="Sign up!">
</form>
</body>
</html>
