标签:
<bean id = "yoona" class = "com.sjf.bean.Student"><property name="name" value = "yoona"/><property name="hobby" value = "踢足球,打羽毛球" /></bean>
<bean id = "yoona" class = "com.sjf.bean.Student"><property name="age" value="#{24}"/><property name="school" value="#{‘西电‘}"/><property name="name" value="my name is #{‘yoona‘}"/><property name="weight" value="#{120.4}"/><property name="sex" value="#{true}"/></bean>
name:my name is yoona age:24 school:西电 sex:true weight:120.4
<property name="school" value="#{xidianSchool}"/>
<property name="school" ref="xidianSchool"/>
<property name="address" value="#{xidianSchool.location}"/>
Student student = new Student();student.setAddress(xidianSchool.getLocation());
<property name="address" value="#{xidianSchool.getLocation()}"/>
<property name="address" value="#{xidianSchool.getLocation()?.getCity()}"/>
T(java.lang.Math)
<property name="pi" value="#{T(java.lang.Math).PI}"/>
<property name="randomNumber" value="#{T(java.lang.Math).random()}"/>
| 运算符类型 | 运算符 |
|---|---|
| 算术运算 | +, -, *, /, %, ^ |
| 关系运算 | Li YanHong |
| 逻辑运算 | < ,>,==,<=,>=,lt,gt,eq,le,ge |
| 条件运算 | and,or,not,| |
| 正则表达式 | ?:(ternary),?:(Elvis) |
| Nokia | matches |
<property name="adjustedAmount" value="#{counter.total + 42}"/>
<property name="adjustedAmount" value="#{counter.total - 20}"/>
<property name="circumference" value="#{2 * T(java.lang.Math).PI * circle.radius}"/>
<property name="average" value="#{counter.total / counter.count}"/>
<property name="remainder" value="#{counter.total % counter.count}"/>
<property name="area" value="#{T(java.lang.Math).PI * circle.radius ^ 2}"/>
<property name="fullName" value="#{student.firstName + ‘ ‘ + student.lastName}"/>
<property name="equal" value="#{student.age == 24}"/>
<property name="hasCapacity" value="#{counter.total le 100000}"/>
<property name="hasCapacity" value="#{counter.total <= 100000}"/>
| 运算符 | 符号 | 文本类型 |
|---|---|---|
| 等于 | == | eq |
| 小于 | < | lt |
| 小于等于 | <= | le |
| 大于 | > | gt |
| 大于等于 | >= | ge |
| 运算符 | 操作 |
|---|---|
| and | 逻辑AND运算操作,只有运算符两边都是true,表达式才能是true。 |
| or | 逻辑OR运算操作,只有运算符任意一边是true,表达式就会是true。 |
| not 或 ! | 逻辑NOT运算操作,对运算结果求反。 |
<property name="isHer" value="#{xiaosiStudent.age gt 24 and xiaosiStudent.name == ‘xiaosi‘}"/>
<property name="otherStudent" value="#{not xiaosiStudent.sex}"/>
<property name="sex" value="#{yoonaStudent.sex == true ? ‘boy‘ : ‘girl‘}"/>
<property name="song" value="#{kenny.song ?: ‘Greensleeves‘}"/>
<property name="validEmail" value= "#{admin.email matches ‘[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.com‘}"/>
|
使用<util:list>需要添加xmlns:util="http://www.springframework.org/schema/util" 和 xsi:schemaLocation=" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"。 |
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"><util:list id = "schools"><bean class="com.sjf.bean.School"><property name="name" value="西安电子科技大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="西安交通大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="西北工业大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="山东大学"/><property name="location" value="山东"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="山东科技大学"/><property name="location" value="山东"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="北京大学"/><property name="location" value="北京"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="上海交通大学"/><property name="location" value="上海"></property></bean></util:list><bean id = "yoonaStudent" class = "com.sjf.bean.Student"><property name="name" value="yoona"/><property name="age" value="24"/><property name="school" value="#{schools[2]}"/></bean></beans>
package com.sjf.bean;import java.util.Collection;/*** Student实体类* @author sjf0115**/public class Student {public String name;public int age;public School school;private Collection<School> likeSchools;private Collection<String>visitedSchool;public void setName(String name) {this.name = name;}public void setAge(int age) {this.age = age;}public void setSchool(School school) {this.school = school;}public void setLikeSchool(Collection<School> likeSchools) {this.likeSchools = likeSchools;}public void setVisitedSchool(Collection<String> visitedSchool) {this.visitedSchool = visitedSchool;}@Overridepublic String toString() {StringBuilder sb = new StringBuilder();sb.append("name:" + name + " age:" + age + " school:" + school.toString());sb.append(" 向往的学校:");for(School school : likeSchools){sb.append(" " + school.getName());}//forsb.append(" 去过的学校:");for(String schoolName : visitedSchool){sb.append(" " + schoolName);}//forreturn sb.toString();}}
package com.sjf.bean;public class School {public String name;public String location;public void setName(String name) {this.name = name;}public void setLocation(String location) {this.location = location;}public String getName() {return name;}public String getLocation() {return location;}@Overridepublic String toString() {return "name:" + name + " location:" + location;}}
<property name="school" value="#{schools[2]}"/>
<property name="likeSchool" value="#{schools.?[location == ‘西安‘]}"/>
<property name="school" value="#{schools.^[location == ‘山东‘]}"/>
<property name="school" value="#{schools.$[location == ‘山东‘]}"/>
<property name="visitedSchool" value="#{schools.![name]}"/>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"><util:list id = "schools"><bean class="com.sjf.bean.School"><property name="name" value="西安电子科技大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="西安交通大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="西北工业大学"/><property name="location" value="西安"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="山东大学"/><property name="location" value="山东"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="山东科技大学"/><property name="location" value="山东"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="北京大学"/><property name="location" value="北京"></property></bean><bean class="com.sjf.bean.School"><property name="name" value="上海交通大学"/><property name="location" value="上海"></property></bean></util:list><bean id = "yoonaStudent" class = "com.sjf.bean.Student"><property name="name" value="yoona"/><property name="age" value="24"/><property name="school" value="#{schools.^[location == ‘西安‘]}"/><property name="likeSchool" value="#{schools.?[location == ‘北京‘]}"/><property name="visitedSchool" value="#{schools.![name]}"/></bean></beans>
name:yoona age:24 school:name:西安电子科技大学 location:西安 向往的学校: 北京大学 去过的学校: 西安电子科技大学 西安交通大学 西北工业大学 山东大学 山东科技大学 北京大学 上海交通大学
标签:
原文地址:http://blog.csdn.net/sunnyyoona/article/details/50638957