thymeleaf 直接调用后台Service之${@myBean.doSomething()}

27 篇文章 1 订阅
1 篇文章 0 订阅

方法说明:

thymeleaf的官方文档中提到了${@myBean.doSomething()}可以访问容器中bean的数据。

前端thymeleaf写法:


	<label>性别: </label>
		<select name="status" th:with="type=${@dict.getType('sys_sex')}">
			<option value="">--请选择--</option>
			<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		</select>
<-- js定义变量 -->
var datas = [[${@dict.getType('sys_sex')}]];	

拼接后台获取的数据 '__${ }__', 前后都是两个下划线 ,加单引号往后台传的时候是字符串,不加单引号往后台传的是数字, __${ }__

<input  class="form-control m-b" th:with="type=${@dict.getLabel('sys_sex','__${hrmResource.sex}__')}" th:value="${type}" >
             

<div class="m-b" th:with="type=${@dict.getLabel('sys_sex','__${hrmResource.bloodType}__')}">[[${type}]]</div>

后台 Spring boot


/**
 * html调用 thymeleaf 实现字典读取
 */
@Service("dict")
public class DictService
{
    @Autowired
    private IDictDataService dictDataService;

    /**
     * 根据字典类型查询字典数据信息
     * 
     * @param dictType 字典类型
     * @return 参数键值
     */
    public List<DictData> getType(String dictType)
    {
        return dictDataService.selectDictDataByType(dictType);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    public String getLabel(String dictType, String dictValue)
    {
        return dictDataService.selectDictLabel(dictType, dictValue);
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值