一、在页面上插入背景图片路径的写法
<div class="ad" th:style="'background:url(' + @{/static/img/banner_sj.png} + ') no-repeat center; height:160px;'"></div>
二、Input框赋值写法
<input type="radio" name="checkbox" th:attr="data-labelauty=''+${obj.name}+''" />
三、图片嵌套layui模板时 路径传参写法
<img th:src="@{'/proxyFile/file/download?path={{item.picUrl}}'}" class="hvr-bounce-in" />
四、href多个参数传参 写法(&需要替换成&)
<td><a href="{{ctx}}f/guide/xyda?id={{item.id}}&f={{item.id}}">跳转地址</a></td>
五、传值(多个参数)
第一种:地址之后拼接
<td><a href="{{ctx}}f/guide/xyda?id={{item.id}}&f={{item.id}}">跳转地址</a></td>
第二种:地址传参
前台写法:
<a th:href="@{'/f/guide/xyda/'+${xyy.id}}">跳转地址</a>
后台接收:
@RequestMapping("/xyda/{id}")
public String view(@PathVariable String id,Model model){
return "url";
}
第三种:官网推荐写法
<img th:src="@{/proxyFile/file/download(path=${xyy.path},name=${xyy.name})}" />
六、css、js、jpg的引用
JS引用:
<script type="text/javascript" th:src="@{/static/js/jquery-1.11.0.min.js}"></script>
CSS引用:
<link rel="stylesheet" th:href="@{/static/css/jquery.sPage.css}"/>
图片引用:
<img th:src="@{/static/img/icon_lj.png}" />
七、公共页面的引用与创建
公共页面位置
引用代码:
<th:block th:include="include :: top"/>
公共页面结构:
<!-- 通用CSS -->
<head th:fragment="header">
<link rel="stylesheet" href="../static/css/hover-min.css" th:href="@{/static/css/hover-min.css}"/>
</head>
<div th:fragment="top">
<div class="head">
<ul>
<div class="logo">
头部公共内容
</div>
</ul>
</div>
<script>
$(function () {
$(".head li").each(function(){
$(this).removeClass("cask");
})
})
</script>
</div>
<div th:fragment="footer">
<div class="foot">
底部公共内容
</div>
</div>
八、数据格式化问题,如果有小数显示小数,没有小数或者结尾为0(如:15.00)显示整数(显示为:15)
第一种实现方式:
实现思路:thymeleaf框架调用Java实例方法
后台编写工具类:
/**
* Copyright (DigitalChina) 2016-2020, DigitalChina.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.springboot.mybatis.utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* 处理积分
*/
public class FormatterNumber {
public String valueFormat(double value) {
DecimalFormat df = new DecimalFormat("#####.##");
String xs = df.format(new BigDecimal(value));
return xs;
}
}
前台调用如下:
<span th:text="${new me.springboot.mybatis.utils.FormatterNumber().valueFormat(data.modelScore)}"></span>
第二种实现方式:
实现思路:采用thymeleaf框架的${T(fullclasspath).function()}接口解决
后台编写静态类
/**
* Copyright (DigitalChina) 2016-2020, DigitalChina.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.springboot.mybatis.utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
* 处理积分
*/
public class FormatterNumber {
public static String valueFormat(double value) {
DecimalFormat df = new DecimalFormat("#####.##");
String xs = df.format(new BigDecimal(value));
return xs;
}
}
前台调用如下:
<input type="text" th:value="${T(me.springboot.mybatis.utils.FormatUtil).valueFormat(data.modelScore)}" />