Thymeleaf 用法踩过的坑

一、在页面上插入背景图片路径的写法

二、Input框赋值写法

三、图片嵌套layui模板时 路径传参写法

四、href多个参数传参 写法(&需要替换成&)

跳转地址

五、传值(多个参数)

第一种:地址之后拼接 

跳转地址

第二种:地址传参

前台写法:
跳转地址

后台接收:
@RequestMapping("/xyda/{id}")
public String view(@PathVariable String id,Model model){
    return "url";
}

第三种:官网推荐写法

六、css、js、jpg的引用

JS引用:

CSS引用:

图片引用:

 七、公共页面的引用与创建

公共页面位置

Thymeleaf 用法踩过的坑_第1张图片

引用代码:

公共页面结构:



    

底部公共内容

八、数据格式化问题,如果有小数显示小数,没有小数或者结尾为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;
	}
}

前台调用如下:

        第二种实现方式:

实现思路:采用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;
	}
}

前台调用如下:

 

 

 

 

 

 

 

你可能感兴趣的:(Thymeleaf,js,javascript,html,css)