1.在添加入html以后静态文件如css,js,img等无法加载:
a.在application.properties文件中加入一下(程序扫描静态文件路径,指示thymeleaf所执行的html标准,静态文件必须放在static下)
#视图层控制
spring.mvc.view.prefix=classpath:/templates/ //该处为扫描html文件夹
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
spring.thymeleaf.mode=LEGACYHTML5
b.在springboor-web.xml中添加thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--thymeleaf的依赖中不能添加版本-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
c.在引用静态资源时都要在引用之前加上static,形如static/...
2.html跳转链接
springboot中所有的连接跳转都需经过服务器进行跳转
若无拦截字符串则:
controller前加注解@RequestMapping("/")
若controller类前加了拦截器注解则:
在该类下的跳转方法中跳转后出现的html页面里的所有静态资源前需加 ../
3.form表单与后端springboot交互
在跳转form表单之前的controller类中的拦截跳转方法中需先传一个包含from表单中所有属性的对象到html页面中,在form中input与对象的属性对应绑定
<form role="form" action="#" th:action="@{/userlogin}" th:object="${user}" >
<input type="text" th:field="*{name}">
<input type="password" th:field="*{password}">
<button type="submit" class="btn8">登录!</button>
</form>
4.修改/删除传值
<a th:href="@{/viewgoods/} + ${i.id}" class="btn btn-sm btn-success updateBtn">修改</a>
<a th:href="@{/viewgoods/} + ${i.id}" class="btn btn-sm btn-danger deleteBtn">删除</a>
所传值数据类型前后一致,否者hibate中查询不出
5.单选框
<input type="radio" value="0" th:attr ="checked=#{goods_a.goods_ishot == false?true:false}">
6.add上传
7.前端一直获取不到img_path属性
在实体类种img_path属性不知什么原因set和get方法的属性名首字母都是小写,在springboot中需要格式化第一个改为大写
setimg_path和getimg_path改为setImg_path和getImg_path
8.thymeleaf前端
<th:block th:each ="i,iStat:${goodlist}">
</th:block>
i为遍历的对象,iStat为对象在集合中的下标
<th:block th:if="${(iStat.index) % 2 eq 0}">
</th:block>
<th:block th:unless="${(iStat.index) % 2 eq 0}">
</th:block>
unless为后面表达式的取反,即表达式不成立
9.springboot from经拦截器返回的页面刷新后导致from的数据重复提交
返回页面时通过重定向解决
return "redirect:select";
相当于浏览器重新请求select的拦截字符,需要重新定义select的拦截器返回页面
10.删除提交确认框
在a标签中thymeleaf调用onchlik js代码(一直不能传参)
th:οnclick="|delcfm(${i.id})|"
js代码也有一定的规则
<script th:inline="javascript">
/*<![CDATA[*/
function delcfm(url) {
$('#url').val('/delete'+ url);//给会话中的隐藏属性URL赋值
$('#delcfmModel').modal();
}
function urlSubmit(){
var url=$.trim($("#url").val());//获取会话中的隐藏属性URL
th:window.location.href=url;
}
/*]]>*/
</script>
11.from中的button必须加上type="button"不然默认为submit
12.fileinput的设置不生效
先导入fileinput的css和js才引入设置的js,不然报没有fileinput标签的错误
13.点击提交以后跳出的js,confirm确定窗口,点击取消以后任然提交了表单。
onClick="return confirm_update()" 在onClick='moth()' 中改为onClick='return moth()'