springboot学习总结(一)
1 springboot简介 它是有把spring的东西都封装起来,使用大量注解,去掉了大量的xml配置。基于maven下可以直接使用,只需要引用依赖。所以要学习springboot之前要先学习springmvc的spring,尤其需要了解其中的注解式开发。其中springboot内置了tomcat引入springbootweb的依赖就可以存在controller层,并且可以进行web开发。 springboot可以快速构建,,基于gradle或者maven都可以构建。 2springboot热部署 这个需要引入devtools这个依赖,并且在application.properties中配置打开热部署。和关于修改那些文件可以自动重启。 3springboot引擎模板 1 freemarker 即xxx.ftl文件头文件与html文件一样。里面可以使用jstl表达式。并且与springmvc一样可以配置前缀后缀。和encoding。还有context格式。其中controller层开发与springmvc相同。 2 thymeleaf 这个模板可以使用html模型。后缀可以是.html即xxxx.html,其中可以使用el表达式,如<h1 th:name=${name}> helloword</h1> 其中th:需要在头文件引入thymeleaf模板。 thymeleaf模板其中有一个日期格式转换。
<input th:value="${#dates.format(user.birthdaty,yyyy-MM-dd)}">
其中使用#dates.format第一个参数是你controller传过来的日期值,第二个参数是你要转换成什么格式。 th:text与th:utext的区别 th:text是后台传过来的带有html元素的东西无法解析。直接按照文本格式输出到页面上。 th:utext能将html元素解析出来。按格式显示到页面上。 url的写法
<a th:href="@{http://www.baidu.com}">网站地址</a>
需要用@{xxxx}把网址引进去。 form的写法基本一样。
<form th:action="@{/th/postform}" th:object="${user}" th:method="post">
<input type="text" th:field="*{name}">
<input type="submit" th:value="提交">
</form>
其中th:field=“name”这个意思是,这个input的id,name,value都与name一样。如id=“name” 判断th:if参照如下代码
<div th:if="${user.age} == 18">18</div>
<div th:if="${user.age} gt 18">大于18</div>
<div th:if="${user.age} lt 18">小于18</div>
<div th:if="${user.age} ge 18">大于等于18</div>
<div th:if="${user.age} le 18">小于等于18</div>
选择也参照如下代码
select>
<option>选择框</option>
<option th:selected="${user.name eq ck} ">ck</option>
<option th:selected="${user.name eq aa} ">aa</option>
<option th:selected="${user.name eq bb}">bb</option>
</select>
其中当谁的值符合条件就将谁的值默认显示出来 foreach与jstl基本相同
table>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>年龄备注</th>
<th>生日</th>
</tr>
<tr th:each="person:${userlist}">
<td th:text="${person.name}"></td>
<td th:text="${person.age}"></td>
<td th:text="${person.age gt 18} ? 你老了:你很年轻" >18岁</td>
<td th:text="${#dates.format(user.birthdaty,yyyy-MM-dd hh:mm:ss)}"></td>
</tr>
</table>
userlist是后台传过来的list集合。 switch:case
```
<div th:switch="${user.name}">
<p th:case="ck">ck</p>
<p th:case="#{roles.manager }">普通管理员</p>
<p th:case="#{roles.superadmin }">超管</p>
<p th:case="*">其他用户</p>
</div>```
其中#{roles.xxxx}这个是创建的一个资源文件.message.properties
里边
roles.manager=manager
roles.superadmin=superadmi
