- Jsp 的老方法
${pageContext.request.contextPath}
=Thymeleaf 的新方式@{}
- 如下实例
老式jsp:
<div style="border: solid 1px">
<form enctype="multipart/form-data" method="post" th:action= "${pageContext.request.contextPath}/uploadDownload/testuploadimg">
图片<input type="file" name="file"/>
<input type="submit" value="上传"/>
</form>
</div>
新的thymeleaf:
<div style="border: solid 1px">
<form enctype="multipart/form-data" method="post" th:action= "@{/uploadDownload/testuploadimg}">
图片<input type="file" name="file"/>
<input type="submit" value="上传"/>
</form>
</div>
2.跨域请求:
@Configuration
public class CORSConfiguration {
@Bean
public WebMvcConfigurer configurer(){
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*");
}
};
}
}