日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java自定义配置文件_自定义配置文件如何配置

發(fā)布時(shí)間:2025/3/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java自定义配置文件_自定义配置文件如何配置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

@Component

public?class?RoleDirectiveModel?implements?TemplateDirectiveModel?{

/**

*

*?@param?environment?環(huán)境變量

*?@param?params?指令參數(shù)(存儲(chǔ)你所需要的值,隨便是什么Key-Value你懂的)

*?@param?loopVars?循環(huán)變量?返回值

*?@param?templateDirectiveBody?指令內(nèi)容

*?除了params外,其他的都能是Null。

*?@throws?TemplateException

*?@throws?IOException

*/

@Override

public?void?execute(Environment?environment,?Map?params,?TemplateModel[]?loopVars,?TemplateDirectiveBody?templateDirectiveBody)?throws?TemplateException,?IOException?{

System.out.println("=========");

TemplateScalarModel?user=(TemplateScalarModel)params.get("user");

TemplateScalarModel?role=(TemplateScalarModel)params.get("role");

if("123456".equals(user.getAsString())?&&?"admin".equals(role.getAsString())?){

loopVars[0]=TemplateBooleanModel.TRUE;

}

List?otherRights=new?ArrayList<>();

otherRights.add("add");

otherRights.add("update");

otherRights.add("delete");

loopVars[1]=new?SimpleSequence(otherRights);

templateDirectiveBody.render(environment.getOut());

}

}

這是自定義指令的定義類

這是加載自定義指令的freemarker?java配置類import?com.example.demo.model.tag.RoleDirectiveModel;

import?com.example.demo.model.tag.SortMethod;

import?freemarker.template.TemplateModelException;

import?lombok.extern.slf4j.Slf4j;

import?org.springframework.beans.factory.annotation.Autowired;

import?org.springframework.context.annotation.Configuration;

import?javax.annotation.PostConstruct;

@Slf4j

@Configuration

public?class?FreeMarkerAutoConfiguration?{

@Autowired

private?freemarker.template.Configuration?configuration;

@Autowired

private?RoleDirectiveModel?roleDirectiveModel;

@Autowired

private?SortMethod?sortMethod;

@PostConstruct

public?void?setSharedVariable()?{

try?{

//自定義標(biāo)簽

configuration.setSharedVariable("role",?roleDirectiveModel);

configuration.setSharedVariable("sort_int",sortMethod);

}?catch?(Exception?e)?{

log.error("Custom?tags?failed?to?load:{}",?e.getMessage());

}

}

}

與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的java自定义配置文件_自定义配置文件如何配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。