当前位置: 首页 > news >正文

打开网址资料网站企业网站建设的几种形式

打开网址资料网站,企业网站建设的几种形式,如何做网站推广自己的产品,黑群晖安装wordpress0. 我只是个普通码农#xff0c;不值得挽留 Spring SpEL表达式的使用 常见的应用场景:分布式锁的切面借助SpEL来构建key 比较另类的的应用场景:动态校验 个人感觉可以用作控制程序的走向#xff0c;除此之外#xff0c;spring的一些模块的自动配置类#xff0c;也会在Cond…0. 我只是个普通码农不值得挽留 Spring SpEL表达式的使用 常见的应用场景:分布式锁的切面借助SpEL来构建key 比较另类的的应用场景:动态校验 个人感觉可以用作控制程序的走向除此之外spring的一些模块的自动配置类也会在Conditional注解中使用SpEL来实现有条件的加载特定的bean. 1. UML 1.1 ExpressionParser 解释器设计模式的体现了 单纯的(非模板表达式)spel表达式将通过 SpelExpressionParser 创建 InternalSpelExpressionParser 来实现 parseExpression() 的底层逻辑. // org.springframework.expression.spel.standard.InternalSpelExpressionParser#doParseExpressionOverrideprotected SpelExpression doParseExpression(String expressionString, Nullable ParserContext context)throws ParseException {try {this.expressionString expressionString;// 1.对相关的符号进行分词Tokenizer tokenizer new Tokenizer(expressionString);this.tokenStream tokenizer.process();this.tokenStreamLength this.tokenStream.size();this.tokenStreamPointer 0;this.constructedNodes.clear();// 2.构建 ASTSpelNodeImpl ast eatExpression();Assert.state(ast ! null, No node);Token t peekToken();if (t ! null) {throw new SpelParseException(t.startPos, SpelMessage.MORE_INPUT, toString(nextToken()));}Assert.isTrue(this.constructedNodes.isEmpty(), At least one node expected);// 3. 返回创建好的表达式实例return new SpelExpression(expressionString, ast, this.configuration);}catch (InternalParseException ex) {throw ex.getCause();}}1.2 ParserContext 这里前后缀例如支持模板表达式的实现类TemplateParserContext使用了#{ 、 }TemplateAwareExpressionParser(支持模板的ExpressionParser实现类)根据 ParserContext.isTemplate()来决定处理流程有必要给出模板表达式的定义: 可以理解为多个、多种表达式的组合 // org.springframework.expression.common.TemplateAwareExpressionParser#parseExpression(java.lang.String, org.springframework.expression.ParserContext)Overridepublic Expression parseExpression(String expressionString, Nullable ParserContext context) throws ParseException {if (context ! null context.isTemplate()) {return parseTemplate(expressionString, context);}else {return doParseExpression(expressionString, context);}}1.3 Expression 转换并获取表达式对应的数值 1.4 EvaluateContext 支持间接的关联 beanFactory 来注入spring bean该功能很好的体现了 spring-expression 的独立性支持往该上下文中加入静态方法、java bean与 Expression.getValue() 有较大的关系 2. test-classes 因为要debug beanFactory关联的 parser,便懒得构造applicationContext直接SpringbootTest 启动容器了 DisplayName(Spring Expression Language) SpringBootTest public class SpELTest {Value(#{testBean.value})String value;AutowiredApplicationContext appCtx;SpelExpressionParser parser;StandardEvaluationContext stdEvaCtx;PostConstructprivate void postConstruct() throws NoSuchMethodException {parser new SpelExpressionParser();// rootObjectstdEvaCtx new StandardEvaluationContext(new TestBean(rootValue, null));// variablestdEvaCtx.setVariable(testBean, this.appCtx.getBean(testBean));Method parseInt Integer.class.getDeclaredMethod(valueOf, String.class);stdEvaCtx.registerFunction(doValueOf, parseInt);stdEvaCtx.setBeanResolver(new BeanFactoryResolver(this.appCtx));}DisplayName(注解方式)Testvoid t0() {// 这个上下文其实就是表达式、变量的容器(缓存)System.err.println(this.value);}DisplayName(编码方式)Testvoid t1() {// 不需要 {}// spring security 中也使用编码的方式解析权限注解 PrePreAuthorizeExpression expression parser.parseExpression(#testBean.value);System.err.println(expression.getValue(this.stdEvaCtx));}DisplayName(运算)Nestedclass Count {DisplayName(字面量)Testvoid t0() {// 上下文中找不到这个变量报错// spel.SpelEvaluationException: EL1007E: Property or field test cannot be found on null// System.err.println(找不到变量parser.parseExpression(test).getValue(String.class));// 字符串System.err.println(字符串1 parser.parseExpression(test).getValue(String.class));System.err.println(字符串2 parser.parseExpression(\test\).getValue(String.class));// 数字System.err.println(int parser.parseExpression(1).getValue(Integer.class));System.err.println(long parser.parseExpression(1L).getValue(long.class));System.err.println(float parser.parseExpression(1.1).getValue(Float.class));System.err.println(double parser.parseExpression(1.1E1).getValue(double.class));System.err.println(hex parser.parseExpression(0xf).getValue(int.class));// 布尔System.err.println(bool parser.parseExpression(false).getValue(boolean.class));// nullSystem.err.println(parser.parseExpression(null).getValue());}DisplayName(算数)Testvoid t1() {System.err.println(32 parser.parseExpression(32).getValue(Integer.class));System.err.println(3-2 parser.parseExpression(3-2).getValue(Integer.class));System.err.println(3*2 parser.parseExpression(3*2).getValue(Integer.class));System.err.println(3/2 parser.parseExpression(3/2).getValue(Integer.class));System.err.println(3%2 parser.parseExpression(3%2).getValue(Integer.class));System.err.println(3^2 parser.parseExpression(3^2).getValue(Integer.class));}DisplayName(关系运算)Testvoid t2() {System.err.println(32 parser.parseExpression(32).getValue(Boolean.class));System.err.println(3 2 parser.parseExpression(3 2).getValue(Boolean.class));System.err.println(3 ge 2 parser.parseExpression(3 ge 2).getValue(boolean.class));System.err.println(3 LT 2 parser.parseExpression(3 LT 2).getValue(boolean.class));// SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: NE2// System.err.println(3NE2 parser.parseExpression(3NE2).getValue(boolean.class));// 并不能返回 int:0、1会抛出异常System.err.println(2 between {1, 2} parser.parseExpression(2 between {1, 2}).getValue(Boolean.class));// SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: le()// System.err.println(122parser.parseExpression(123).getValue(Boolean.class));}DisplayName(逻辑运算)Testvoid t3() {System.err.println(21 and false parser.parseExpression(21 and false).getValue(boolean.class));System.err.println(21 false parser.parseExpression(21 false).getValue(Boolean.class));// SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: factory_bean_ref()// System.err.println(21 false parser.parseExpression(21 false).getValue(Boolean.class));System.err.println(21 or NOT false and (! NOT false || 11) parser.parseExpression(21 or NOT false and (! NOT false || 11)).getValue(Boolean.class));}DisplayName(三目运算)Testvoid t4() {System.err.println(3 2 ? true : false parser.parseExpression(3 2 ? true : false).getValue(boolean.class));}DisplayName(elivis)Testvoid t5() {System.err.println(null ?: false parser.parseExpression(null ?: false).getValue(Boolean.class));System.err.println(null ?: false parser.parseExpression(null ?: false).getValue(String.class));}DisplayName(正则)Testvoid t6() {System.err.println( parser.parseExpression(123 matches \\d{3}).getValue(boolean.class));System.err.println( parser.parseExpression(123 matches \\d{3}).getValue(Boolean.class));}DisplayName(instanceof)Testvoid t7() {System.err.println(123 instanceof T(String) parser.parseExpression(123 instanceof T(String)).getValue(Boolean.class));System.err.println(123 instanceof T(String) parser.parseExpression(123 instanceof T(java.lang.String)).getValue(Boolean.class));}}DisplayName(类型)Nestedclass Type {DisplayName(class)Testvoid t0() {// java.lang 以外的类均需要全限定名System.err.println(parser.parseExpression(T(String)).getValue(Class.class));System.err.println(parser.parseExpression(T(java.util.Map)).getValue(Class.class));// 访问 静态的属性、方法System.err.println(parser.parseExpression(T(Integer).MAX_VALUE).getValue(int.class));System.err.println(parser.parseExpression(T(Integer).parseInt(3)).getValue(Integer.class));}DisplayName(instance)Testvoid t1() {// java.lang 包 同理System.err.println(parser.parseExpression(new String(苹果一样的甜)).getValue(String.class));System.err.println(parser.parseExpression(new java.util.Date()).getValue(Date.class));}DisplayName(reference)Testvoid t2() {System.err.println(#testBean.value parser.parseExpression(#testBean.value).getValue(stdEvaCtx, String.class));System.err.println(#this.value parser.parseExpression(#this.value).getValue(stdEvaCtx, String.class));System.err.println(#root.value parser.parseExpression(#root.value).getValue(stdEvaCtx, String.class));// rootObject缺省时访问其属性不能加#前缀System.err.println((root属性可以省略#root)value parser.parseExpression(value).getValue(stdEvaCtx, String.class));}DisplayName(assign)Testvoid t3() {System.err.println(#testBean.valuenewValue -- parser.parseExpression(#testBean.valuenewValue).getValue(stdEvaCtx, String.class));System.err.println(#this.valuenewThisValue -- parser.parseExpression(#this.valuenewThisValue).getValue(stdEvaCtx, String.class));System.err.println(#root.valuenewRootValue -- parser.parseExpression(#root.valuenewRootValue).getValue(stdEvaCtx, String.class));System.err.println(valuenewValue -- parser.parseExpression(valuenewValue).getValue(stdEvaCtx, String.class));}DisplayName(func)Testvoid t4() {System.err.println(parser.parseExpression(#doValueOf(20).byteValue()).getValue(stdEvaCtx, Byte.class));}DisplayName(对象属性获取 及 安全导航)Testvoid t5() {System.err.println(parser.parseExpression(value).getValue(stdEvaCtx, String.class));// Value 可以Value 不得行(首字母不敏感)System.err.println(parser.parseExpression(Value).getValue(stdEvaCtx, String.class));// 支持groovy的elivis表达式// 安全导航运算符前面的#root可以省略但后面的#root不可省略System.err.println(parser.parseExpression(#root?.#root).getValue(stdEvaCtx, TestBean.class));System.err.println(parser.parseExpression(value?.#root.value).getValue(stdEvaCtx, String.class));// SpelParseException: Expression [username?.核弹拉链] 8: EL1049E: Unexpected data after .: 核弹拉链// SpEL引入了Groovy语言中的安全导航运算符(对象|属性)?.属性// 常量显然不得行// System.err.println(parser.parseExpression(username?.核弹拉链).getValue(stdEvaCtx, String.class));}DisplayName(对象方法调用)Testvoid t6() {System.err.println(parser.parseExpression(value.substring(1, 6).toUpperCase()).getValue(stdEvaCtx, String.class));System.err.println(parser.parseExpression(toString()).getValue(stdEvaCtx, String.class));}DisplayName(bean引用(BeanFactoryResolver))Testvoid t7() {// BeanName// EvaluationContext.setBeanResolver() 需要借助 beanFactorySystem.err.println(Jsons.NO_OP.stringify(parser.parseExpression(systemProperties).getValue(stdEvaCtx, Properties.class)));System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(testBean).getValue(stdEvaCtx, TestBean.class)));}}DisplayName(集合)Nestedclass Collect {DisplayName(内联数组)Testvoid t0() {System.err.println(Arrays.toString(parser.parseExpression(new int[2]{1, 2}).getValue(int[].class)));System.err.println(Arrays.toString(parser.parseExpression(new String[2][2]).getValue(String[][].class)));// 不支持多维数组创建同时做初始化System.err.println(Arrays.toString(parser.parseExpression(new String[2][2]{1,2},{3,4}).getValue(String[][].class)));}DisplayName(内联集合)Testvoid t1() {System.err.println(parser.parseExpression({}).getValue(List.class));// java.util.Collections$UnmodifiableRandomAccessListSystem.err.println(parser.parseExpression({1, 2,3}).getValue(List.class).getClass().getName());// 此时的 ListList .class java.util.ArrayList// 存在非字面量表达式时集合类型将转为原始类型(可修改的集合)System.err.println(parser.parseExpression({{12,24},{3,44}}).getValue(List.class).getClass().getName());}DisplayName(数组、集合、字典元素访问)Testvoid t2() {System.err.println(parser.parseExpression([0]).getValue(new int[]{1, 2, 3}, Integer.class));System.err.println(parser.parseExpression({1, 2, 3}[0]).getValue(int.class));System.err.println(parser.parseExpression([0]).getValue(Lists.newArrayList(1, 2, 3), int.class));MapString, Integer map Maps.newHashMap();map.put(weng, 4);map.put(chong, 5);map.put(yu, 2);System.err.println(parser.parseExpression([chong]).getValue(map, int.class));}// 很像 streamApi.peek().collect(toList())DisplayName(数组、集合、字典 转换)Testvoid t3() {// array|list|map.![表达式]System.err.println(Arrays.toString(parser.parseExpression(#root.![#this1]).getValue(new int[]{1, 2, 3}, int[].class)));System.err.println(parser.parseExpression(#root.![#this1]).getValue(Lists.newArrayList(1, 2, 3), List.class));MapString, Integer map Maps.newHashMap();map.put(weng, 4);map.put(chong, 5);map.put(yu, 2);System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.![#this.key1]).getValue(map, List.class)));System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.![#this.value1]).getValue(map, List.class)));// 报错: cannot convert from java.util.ArrayList? to java.util.Map?, ?// 集合、数组之间可以随意转换// System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.![#this.value1]).getValue(map, Map.class)));}// 相当于 streamApi.filter.collect(toList)DisplayName(数组、集合、字典 选择)Testvoid t4() {// array|list|map.?[表达式]System.err.println(Arrays.toString(parser.parseExpression(#root.?[#this2]).getValue(new int[]{1, 2, 3}, int[].class)));System.err.println(Arrays.toString(parser.parseExpression(#root.?[#this2]).getValue(Lists.newArrayList(1, 2, 3), int[].class)));MapString, Integer map Maps.newHashMap();map.put(weng, 4);map.put(chong, 5);map.put(yu, 2);// {weng:4,yu:2}System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.?[#this.key!chong]).getValue(map, Map.class)));// 这里转的集合有些怪异// [{weng:4,yu:2}]System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.?[#this.key!chong]).getValue(map, List.class)));System.err.println(Jsons.NO_OP.stringify(parser.parseExpression(#root.?[#this.value2]).getValue(map, Map.class)));}} }附上相关的类 Component(testBean) AllArgsConstructor NoArgsConstructor Data public class TestBean {Value(${angel.spel.key})public String value;private String username; }
http://www.w-s-a.com/news/890165/

相关文章:

  • 建网站的公司叫什么重庆论坛建站模板
  • 湖北网站制作公司银川网站建设哪家不错
  • 网站后台演示地址服装网站建设公司推荐
  • 湖北钟祥建设局网站旅游哪个网站最好
  • 浙江建设工程信息网站辽宁建设工程信息网场内业绩什么意思
  • 郑州做网站公司 汉狮网络专业图片搜集网站怎么做
  • 网站托管是什么品牌推广营销平台
  • 制作网站的难度贵州省兴义市建设局网站
  • 永春建设局网站室内设计师培训班学费多少
  • 做仿站如何获取网站源码windows2012做网站
  • 网站建设最好的公司东莞外贸网站
  • 普兰店网站建设一般做网站什么价格
  • 网站建设的发展目标甘肃网站设计公司
  • 常州西站建设规划室内装修设计学校哪里好
  • 大连网站制作选择ls15227如何编辑网站
  • 网站发稿平台迪士尼网站是谁做的
  • 常州有哪些好的网站建设案例wordpress 360 插件
  • 模板网站有后台么柳城网站建设
  • 地方门户网站制作一级做c爱片的网站
  • 自己上传图片做动漫图网站北京福田汽车
  • 一级a做爰片免费网站录像ps做网站图片水印
  • 网页广告投放成都优化推广公司
  • 网站开发 印花税网页制作站点
  • 创建个人网站有什么好处国外建站系统
  • 桂林学校网站制作2018年网站设计公司
  • 建网站不想用怎样撤销搜狗收录提交入口网址
  • 做简单网站需要学什么软件有哪些南通优普网站建设
  • 网站排版尺寸湖北交投建设集团集团网站
  • 南京网站设计公司有哪些公司看动漫是怎么做视频网站
  • vs做网站怎么做窗体怎么在电脑上自己做网站吗