问题出现:在ssh项目中通过系统栏目路径跳转至springboot项目中,在controller层return一个界面回去,这样ssh项目中可以直接使用springboot项目中的界面了,可移植性高。但是问题随之而来,跨域以及各种报错。
先说题目的这个问题,好像是将html页面识别成了xml文件了,所以对符号要求特别高,比如必须有,必须有,这些标记我都可以忍受,所以一个一个都改正成标准写法,单标签双标签的全写成双标签了,这样倒是可以直接跳转了。但是,不能忍受的是 在 前台js的for 循环里,居然不认小于号<,这就不能忍了。上网查询后,说是需要转译一下,
图片描述
转译完之后确实页面可以跳转了,但是!但是!html页面js不认它啊,所以还是不中,这个方法还是不行,继续百度,最后找到一个方法是在pom.xml里面添加这么两行
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
即
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--以下两项需要如果不配置,解析themleaft 会有问题-->
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
</properties>
这样html页面该怎么写就怎么写了。
顺便说一下从ssh调转路径到springboot,需要配置什么东西:
在springboot启动类里面添加如下配置
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);//这两句不加不能跨域上传文件,
corsConfiguration.setMaxAge(3600l);//加上去就可以了
return corsConfiguration;
}
/**
* 跨域过滤器
* @return
*/
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig()); // 4
return new CorsFilter(source);
}