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

如何给网站做关键词优化/信息流优化师招聘

如何给网站做关键词优化,信息流优化师招聘,自己用模板做网站,泰安市住房和城乡建设厅网站1:写在前面 spring在spring3版本后提供了el表达式的功能,表达式的计算,对象的访问,方法的调用等。对应的顶层接口是org.springframework.expression.ExpressionParser。 参考如下文章列表: https://www.cnblogs.com/…

1:写在前面

spring在spring3版本后提供了el表达式的功能,表达式的计算,对象的访问,方法的调用等。对应的顶层接口是org.springframework.expression.ExpressionParser
参考如下文章列表:

https://www.cnblogs.com/ooo0/p/10987630.html
https://www.cnblogs.com/leiOOlei/p/3543222.html

2:字符串常量作为表达式

2.1:测试代码

public static void stringContantExp() {// 定义表达式解析器对象ExpressionParser expressionParser = new SpelExpressionParser();// 设置字符串常量的表达式,'test spring el'就是我们定义的表达式,只不过这里是一个字符串的常量Expression expression = expressionParser.parseExpression("'test spring el'");// 获取表达式的值String value = (String) expression.getValue();System.out.println("表达式的值是:" + value);// 设置调用字符串普通方法的EL表达式expression = expressionParser.parseExpression("'test spring el'.charAt(0)");System.out.println("通过表达式访问对象普通方法获取的值是:" + expression.getValue());// 设置调用字符串get方法的EL表达式expression = expressionParser.parseExpression("'test spring el'.getClass()");System.out.println("通过表达式访问对象get方法获取的值是:" + expression.getValue());// 通过EL访问属性expression = expressionParser.parseExpression("'test spring el'.bytes.length");System.out.println("通过表达式访问属性的值是:" + expression.getValue());
}

2.2:运行

表达式的值是:test spring el
通过表达式访问对象普通方法获取的值是:t
通过表达式访问对象get方法获取的值是:class java.lang.String
通过表达式访问属性的值是:14

3:操作对象的属性

3.1:测试代码

public class Role2{//赋值long型private Long id;//字符串赋值private String roleName;//字符串赋值private String note;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getRoleName() {return roleName;}public void setRoleName(String roleName) {this.roleName = roleName;}public String getNote() {return note;}public void setNote(String note) {this.note = note;}public Role2(long l, String role_name, String note) {this.id = l;this.roleName = role_name;this.note = note;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}
public static void testObjPropEl() {/* 从根对象中读取属性开始 */// 表达式解析器ExpressionParser parser = new SpelExpressionParser();// 定义根对象Role2 role = new Role2(1L, "role_name", "note");// 定义要访问的属性note的表达式Expression exp = parser.parseExpression("note");// 从根对象role中访问属性noteString note = (String) exp.getValue(role);System.out.println(note);/* 从根对象中读取属性结束 *//* 设置根对象属性开始 */// 使用role作为根对象创建计算上下文对象EvaluationContext ctx = new StandardEvaluationContext(role);// 设置根对象的note属性的值为new_noteparser.parseExpression("note").setValue(ctx, "new_note");// 获取根对象的note属性的值,并指定以String类型返回note = parser.parseExpression("note").getValue(ctx, String.class);System.out.println(note);/* 设置根对象属性结束 *//* 调用根对象的getRoleName方法开始 */// 调用getRoleName方法String roleName = parser.parseExpression("getRoleName()").getValue(ctx, String.class);System.out.println(roleName);/* 调用根对象的getRoleName方法结束 */}

3.2:运行

note
new_note
role_name

4:操作集合

4.1:测试代码

private static void testListEl() {ExpressionParser parser = new SpelExpressionParser();List<String> list = new ArrayList<>();list.add("value-0");list.add("value-1");// 创建上下文,并将集合设置到上下文中EvaluationContext ctx = new StandardEvaluationContext();ctx.setVariable("list", list);// 获取索引位置1的值String pos1El = "#list[1]";String value = parser.parseExpression(pos1El).getValue(ctx, String.class);System.out.println("索引位置1的值是:" + value);// 设置索引位置0的值为新值String pos0El = "#list[0]";parser.parseExpression(pos0El).setValue(ctx, "new-value-0");value = parser.parseExpression(pos0El).getValue(ctx, String.class);System.out.println("索引位置0的新值是:" + value);
}

4.2:运行

索引位置1的值是:value-1
索引位置0的新值是:new-value-0

5:基于EL表达式创建bean(xml)

5.1:类

public class Item {private String name;private int total;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getTotal() {return total;}public void setTotal(int total) {this.total = total;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}
public class Customer {private Item item;private String itemName;public Item getItem() {return item;}public void setItem(Item item) {this.item = item;}public String getItemName() {return itemName;}public void setItemName(String itemName) {this.itemName = itemName;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}

5.2:配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="itemBean" class="yudaosourcecode.speltest.Item"><property name="name" value="itemA" /><property name="total" value="10" /></bean><bean id="customerBean" class="yudaosourcecode.speltest.Customer"><property name="item" value="#{itemBean}" /><property name="itemName" value="#{itemBean.name}" /></bean>
</beans>

5.3:测试代码

@Test
publicvoid createbeanwitheltest() {ClassPathXmlApplicationContext ac= new ClassPathXmlApplicationContext("speltest/createbeanwitheltest.xml");System.out.println(ac.getBean("customerBean"));
}

5.4:运行

{"item":{"name":"itemA","total":10},"itemName":"itemA"}

6:基于EL表达式创建bean(annotation)

6.1:类

@Component("itemBean")
public class Item {@Value("itemA_byannotation")//直接注入Stringprivate String name;@Value("102")//直接注入integerprivate int total;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getTotal() {return total;}public void setTotal(int total) {this.total = total;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}
@Component("customerBean")
public class Customer {@Value("#{itemBean}")private Item item;@Value("#{itemBean.name}")private String itemName;public Item getItem() {return item;}public void setItem(Item item) {this.item = item;}public String getItemName() {return itemName;}public void setItemName(String itemName) {this.itemName = itemName;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}

6.2:配置文件

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="yudaosourcecode.speltest.byannotation" />
</beans>

6.3:测试类

@Test
public void createbeanwithelannotationtest() {ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("speltest/createbeanwithelannotationtest.xml");System.out.println(ac.getBean("customerBean"));
}

6.4:运行

{"item":{"name":"itemA_byannotation","total":102},"itemName":"itemA_byannotation"}

7:基于方法调用创建bean(annotation)

7.1:类

@Component("customerBean")
public class Customer {// 调用toUpperCase方法将lei转大写设置为值@Value("#{'lei'.toUpperCase()}")private String name;// 调用名称为priceBean的getSpecialPrice方法作为amount的值@Value("#{priceBean.getSpecialPrice()}")private double amount;public String getName() {return name;}public void setName(String name) {this.name = name;}public double getAmount() {return amount;}public void setAmount(double amount) {this.amount = amount;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}
@Component("priceBean")
public class Price {public double getSpecialPrice() {return new Double(99.99);}
}

7.2:配置文件

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="yudaosourcecode.speltest.bymethodinvovationannotation" />
</beans>

7.3:测试代码

@Test
public void bymethodinvovationannotation() {ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("speltest/bymethodinvovationannotation.xml");System.out.println(ac.getBean("customerBean"));
}

7.4:运行

{"amount":99.99,"name":"LEI"}

8:基于方法调用创建bean(xml)

8.1:类

public class Customer {private String name;private double amount;public String getName() {return name;}public void setName(String name) {this.name = name;}public double getAmount() {return amount;}public void setAmount(double amount) {this.amount = amount;}@Overridepublic String toString() {return JSON.toJSONString(this);}
}
public class Price {public double getSpecialPrice() {return new Double(66.99);}
}

8.2:配置文件

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="customerBean" class="yudaosourcecode.speltest.bymethodinvovationxml.Customer
"><property name="name" value="#{'dongshidaddy'.toUpperCase()}" /><property name="amount" value="#{priceBean.getSpecialPrice()}" /></bean><bean id="priceBean" class="yudaosourcecode.speltest.bymethodinvovationxml.Price" /></beans>

8.3:测试代码

@Test
public void bymethodinvovationxml() {ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("speltest/bymethodinvovationxml.xml");System.out.println(ac.getBean("customerBean"));
}

8.4:运行

{"amount":66.99,"name":"DONGSHIDADDY"}

9:运算符

9.1:类

@Component("customerBean")
public class MyOperatorBean {@Value("#{1 == 1}") //trueprivate boolean testEqual;@Value("#{1 != 1}") //falseprivate boolean testNotEqual;@Value("#{numberBean.no == 999 and numberBean.no < 900}") //falseprivate boolean testAnd;@Value("#{'1' + '@' + '1'}") //1@1private String testAddString;@Value("#{1 - 1}") //0.0private double testSubtraction;@Value("#{1 * 1}") //1.0private double testMultiplication;@Value("#{10 / 2}") //5.0private double testDivision;@Value("#{2 ^ 2}") //4.0private double testExponentialPower;// 三目@Value("#{20 < 100 ? true : false}")private boolean warning;...snip getter and setter...@Overridepublic String toString() {return JSON.toJSONString(this);}
}
@Component("numberBean")
public class Number {@Value("999")private int no;public int getNo() {return no;}public void setNo(int no) {this.no = no;}}

9.2:配置文件

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="yudaosourcecode.speltest.eloperatortest" />
</beans>

9.3:测试类

@Test
public void eloperatortest() {ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("speltest/eloperatortest.xml");System.out.println(ac.getBean("customerBean"));
}

9.4:运行

{"testAddString":"1@1","testAnd":false,"testDivision":5.0,"testEqual":true,"testExponentialPower":4.0,"testMultiplication":1.0,"testNotEqual":false,"testSubtraction":0.0,"warning":true}
http://www.lbrq.cn/news/1394263.html

相关文章:

  • 安徽省做网站/建站系统软件有哪些
  • 东莞网站建设网站推广/今日发生的重大国际新闻
  • 网站制作主题思路/好口碑关键词优化地址
  • 口碑最好的装饰公司/seo的工作流程
  • 我的世界充钱网站怎么做/2022年新闻热点事件
  • 东莞市手机网站建设平台/成人计算机培训机构哪个最好
  • 成都双语网站开发/汕头网站建设平台
  • 门户网站 营销/最近国际新闻大事20条
  • 如何制作一个软件/赣州seo外包
  • 河南网站建设公司哪个好呀/北京aso优化
  • 印后设备网站建设/整站seo优化哪家好
  • wordpress链接翻译/优化网站怎么真实点击
  • 公司网站建设方案书/活动软文怎么写
  • 山东省青州市建设局网站/登封网站关键词优化软件
  • 做网站在哪里买空间域名/子域名查询工具
  • 如何整理网站/网页生成app
  • 青海高端网站建设价格/南京seo推广公司
  • 网站开发工程师课程/竞价托管哪家公司好
  • 网络工程师职业分析/搜索引擎优化的简写是
  • 网站建设维护 知乎/最近七天的新闻大事
  • 北京电商平台网站建设/2023b站推广大全
  • 广西壮锦网站建设策划书/关键词优化的作用
  • 网站的定位/友情链接的形式
  • 莞城东莞网站建设/网站设计方案
  • 青岛的网站建设公司哪家好/企业seo外包公司
  • 做网站需要哪些费用支出/广州网络推广外包平台
  • 中山医疗网站建设/海外广告优化师
  • 哈尔滨专业官网建站企业/网络推广比较经典和常用的方法有
  • 调用wordpress编辑器/seo推广软件品牌
  • 苹果电脑做网站好用吗/网站推广的10种方法
  • Android APP防止应用被动态调试
  • 审美积累 | 界面设计拆分 | Redesign Health - Services 医疗页面设计
  • 【GPT入门】第49课 LlamaFacotory 训练千问
  • 心路历程-了解网络相关知识
  • Map 和 Set
  • electron进程间通信-从主进程到渲染器进程