스타일 시트가 내 프로젝트에서 작동하지 않습니다. 내 프로젝트에서 Spring Boot, Thymeleaf, Config를 사용하고 있습니다. 내 구조 Structurethymeleaf css Spring MVC annotation
내 login.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Login</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
<link th:href="@{/static/login.css}" href="../static/login.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="container">
<form class="form-signin" action="#" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<input class="form-control" placeholder="Email address">
<input type="password" class="form-control" placeholder="Password">
<br>
<button class="btn btn-primary btn-lg btn-block" type="submit">Sign in</button>
</form>
</div>
</body>
</html>
내 스타일 시트 Login.css
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
max-width: 400px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin input[type="text"],
.form-signin input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
내 컨트롤러
private UserServiceImpl userService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "login";
}
}`
내 설정 파일
@Configuration @EnableWebMvc //mvc:annotation-driven @ComponentScan({ "controller" }) public class SpringWebConfig extends WebMvcConfigurerAdapter{
@Bean
public SpringResourceTemplateResolver templateResolver(){
// SpringResourceTemplateResolver automatically integrates with Spring's own
// resource resolution infrastructure, which is highly recommended.
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setOrder(1);
templateResolver.setPrefix("classpath:/templates/");
templateResolver.setSuffix(".html");
// HTML is the default value, added here for the sake of clarity.
templateResolver.setTemplateMode(TemplateMode.HTML);
// Template cache is true by default. Set to false if you want
// templates to be automatically updated when modified.
templateResolver.setCacheable(true);
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine(){
// SpringTemplateEngine automatically applies SpringStandardDialect and
// enables Spring's own MessageSource message resolution mechanisms.
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
// Enabling the SpringEL compiler with Spring 4.2.4 or newer can
// speed up execution in most scenarios, but might be incompatible
// with specific cases when expressions in one template are reused
// across different data types, so this flag is "false" by default
// for safer backwards compatibility.
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Bean
public ThymeleafViewResolver viewResolver(){
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
return viewResolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}` Wrong result 결과는 잘못된 것입니다. Login.css가 작동하지 않습니다. 실수는 어디 있습니까?
login.css의 생성 경로는 무엇입니까? 콘솔 오류 확인 – SAP
WARN 5764 --- [nio-8080-exec-7] osweb.servlet.PageNotFound : DispatcherServle의 URI [/static/login.css]가있는 HTTP 요청에 대한 매핑이 없습니다 이름이 'dispatcherServlet'인 t –