Spring EL

合集下载

spring是什么意思

spring是什么意思

spring是什么意思很多人都知道英文spring是有春天的解释的,但就不一定会知道它详细的各种汉语意思了。

下面就让小编给大家分享英语单词spring所包含的汉语意思吧,希望能对你有帮助!spring的汉语意思英 [spr ] 美 [spr ]名词春季; 泉水,小溪; 弹簧,弹性; 跳跃不及物动词跳,跃; 突然发出或出现; 发源; 劈开,裂开及物动词突然跳出; 跳过; 使开裂形容词春天的; 弹簧的,有弹性的例句1. He sprang to his feet and rushed out of the room.他跳起身奔出了房间。

2. The door sprang to.门弹回关上。

spring的单语例句1. Li is taking a long view, saying his business is still at the end of winter and marching to spring.2. Ng said the period before the Spring Festival is the busy season for funeral services.3. As traditional Chinese Spring Festival is coming, lantern factories here have come to a busy production season.4. Oil supply tensions loom large in the countryside at the crucial spring ploughing time and the upcoming busy summer farming season.5. We are particularly busy for each year"s Spring Festival peak travel season, especially this year.6. In this year"s Spring Festival travel rush, passengers could buy train tickets online or by telephone for the first time.7. Of these, buyers from China grew over 200 percent between fall of last year and this spring.8. The hot spring town is striving to create an international buzz with medical tourism projects that promote the hot spring culture of Ruzhou.9. In the northern part of the world, most tulips by now have already been planted in the ground for spring flowering.spring的词典解释1. 春天;春季Spring is the season between winter and summer when the weather becomes warmer and plants start to grow again.e.g. The Labor government of Western Australia has an election due next spring...西澳大利亚工党政府明年春天要举行选举。

springsale的中文意思是什么

springsale的中文意思是什么

springsale的中文意思是什么spring sale的中文意思是什么spring sale在中算是比较常见的词组,不过可能大家会比较少注意,那么现在就一起spring sale的知识吧,希望能够帮到大家! spring sale的中文意思春季拍卖;春季大甩卖参考例句:1. Article 3 The sale of commercial houses includes spot sale and advance sale.第三条商品房销售包括商品房现售和商品房预售。

2. Sellers are going to retire and very motivated. This is a normal sale, not short sale, not REO sale.屋主将会退休并愿意提供便利,这是普通销售,不是卖空或银行拥有屋交易。

3. Some ideas suggested include a golf outing, T-shirt/sweatshirt sale with a student design contest, Chinese pastry sale, and a face painting booth and craft sale at the New Year party.目前的方案包括﹕贩卖高尔夫球装及配件﹐T恤,毛线衣搭配由学生设计的校徽﹐在新年晚会中举行贩卖中式糕点及手工艺品﹐画脸等活动以增进财源。

spring sale的网络释义coiled spring coil spring disc spring disk spring spiral spring 盘簧;States that the goods are freely available for sale in Australia and that there are no known prohibitions on their sale to other countries证明该货物在澳大利亚境内是可以自由买卖的,且无出口限制;Jumble sale Rummage sale清仓大拍卖,杂物拍卖;a liquidation sale a rummage sale清仓拍卖;spring sale的双语例句Mice came to the wheels like human beings to a health club holding a spring membership sale.到跑轮上跑步的`小鼠,就像来到正在举行春季促销的健身俱乐部的人类一样。

Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用

Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用

Spring缓存注解@Cacheable、@CacheEvict、@CachePut使⽤从3.1开始,Spring引⼊了对Cache的⽀持。

其使⽤⽅法和原理都类似于Spring对事务管理的⽀持。

Spring Cache是作⽤在⽅法上的,其核⼼思想是这样的:当我们在调⽤⼀个缓存⽅法时会把该⽅法参数和返回结果作为⼀个键值对存放在缓存中,等到下次利⽤同样的参数来调⽤该⽅法时将不再执⾏该⽅法,⽽是直接从缓存中获取结果进⾏返回。

所以在使⽤Spring Cache的时候我们要保证我们缓存的⽅法对于相同的⽅法参数要有相同的返回结果。

使⽤Spring Cache需要我们做两⽅⾯的事:n 声明某些⽅法使⽤缓存n 配置Spring对Cache的⽀持和Spring对事务管理的⽀持⼀样,Spring对Cache的⽀持也有基于注解和基于XML配置两种⽅式。

下⾯我们先来看看基于注解的⽅式。

1 基于注解的⽀持Spring为我们提供了⼏个注解来⽀持Spring Cache。

其核⼼主要是@Cacheable和@CacheEvict。

使⽤@Cacheable标记的⽅法在执⾏后Spring Cache将缓存其返回结果,⽽使⽤@CacheEvict标记的⽅法会在⽅法执⾏前或者执⾏后移除Spring Cache中的某些元素。

下⾯我们将来详细介绍⼀下Spring基于注解对Cache的⽀持所提供的⼏个注解。

1.1 @Cacheable@Cacheable可以标记在⼀个⽅法上,也可以标记在⼀个类上。

当标记在⼀个⽅法上时表⽰该⽅法是⽀持缓存的,当标记在⼀个类上时则表⽰该类所有的⽅法都是⽀持缓存的。

对于⼀个⽀持缓存的⽅法,Spring会在其被调⽤后将其返回值缓存起来,以保证下次利⽤同样的参数来执⾏该⽅法时可以直接从缓存中获取结果,⽽不需要再次执⾏该⽅法。

Spring在缓存⽅法的返回值时是以键值对进⾏缓存的,值就是⽅法的返回结果,⾄于键的话,Spring⼜⽀持两种策略,默认策略和⾃定义策略,这个稍后会进⾏说明。

SpringEL表达式

SpringEL表达式

SpringEL表达式本篇讲述了Spring Expression Language —— 即Spring3中功能丰富强⼤的表达式语⾔,简称SpEL。

SpEL是类似于OGNL和JSF EL的表达式语⾔,能够在运⾏时构建复杂表达式,存取对象属性、对象⽅法调⽤等。

所有的SpEL都⽀持1.XML和2.Annotation 两种⽅式,格式:#{ SpEL expression }spring中EL表达式的⼀些⽤法:⽐较典型的使⽤时@Value注解,或者spring提供注解的某些属性可以使⽤el表达式,如@Scheduld("${job.sever-cron}")主要说说@Value注解(它基本上就代表了别的⽤法)1、普通字符@Value("string")private String str;2、操作系统属性@Value("#{systemProperties['']}")private String osName;3、bean的属性(可以注⼊⾃⾝bean的属性)@Value("msAlertService.processDataForTerminalActionCron")private String cron;4、⼀些简单的运算(同理,⼀些⽅法调⽤也是可以的)@Value("#{ng.Math.random() * 100.0}")private Double radomDouble;5、⽂件@Value("classpath: terminal.txt")private Resource termianlFile;6、属性⽂件的值@Value("${job.process-data-cron}")private String processDataCron;7、⽹址内容@Value("")private Resource googleSource;2. Xml配置如下:<beans xmlns="/schema/beans"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/schema/beans/schema/beans/spring-beans-3.0.xsd"><bean id="customerBean" class="com.lei.demo.el.Customer"><property name="mapA" value="#{testBean.map['MapA']}" /><property name="list" value="#{testBean.list[0]}" /></bean> <bean id="numberGuess" class="org.spring.samples.NumberGuess"> <property name="randomNumber" value="#{ T(ng.Math).random() * 100.0 }"/> </bean> <bean id="taxCalculator" class="org.spring.samples.TaxCalculator"> <property name="defaultLocale" value="#{ systemProperties['user.region'] }"/> </bean></beans>⼆、使⽤场景1. 求值这部分介绍SpEL接⼝和表达式语⾔的简单使⽤。

1.1SpringBoot环境配置和常用注解

1.1SpringBoot环境配置和常用注解

1.1SpringBoot环境配置和常⽤注解Spring Boot常⽤注解:@Service: 注解在类上,表⽰这是⼀个业务层bean@Controller:注解在类上,表⽰这是⼀个控制层bean@Repository: 注解在类上,表⽰这是⼀个数据访问层bean@Component:注解在类上,表⽰通⽤bean ,value不写默认就是类名⾸字母⼩写@Autowired:按类型注⼊.默认属性required= true;当不能确定Spring 容器中⼀定拥有某个类的Bean 时,可以在需要⾃动注⼊该类Bean 的地⽅可以使⽤@Autowired(required = false),这等于告诉Spring:在找不到匹配Bean时也不抛出BeanCreationException 异常。

@Autowired 和 @Qualifier 结合使⽤时,⾃动注⼊的策略就从byType 转变byName 了。

@Autowired可以对成员变量、⽅法以及构造函数进⾏注释,⽽@Qualifier 的标注对象是成员变量、⽅法⼊参、构造函数⼊参。

正是由于注释对象的不同,所以 Spring 不将 @Autowired 和 @Qualifier 统⼀成⼀个注释类。

@Resource:按名称装配区别:@Resource默认按照名称⽅式进⾏bean匹配,@Autowired默认按照类型⽅式进⾏bean匹配@Resource(importjavax.annotation.Resource;)是J2EE的注解,@Autowired(importorg.springframework.beans.factory.annotation.Autowired;)是Spring的注解@Configuration:注解在类上,表⽰这是⼀个IOC容器,相当于spring的配置⽂件,java配置的⽅式。

IOC容器的配置类⼀般与@Bean 注解配合使⽤,⽤@Configuration 注解类等价与 XML 中配置 beans,⽤@Bean 注解⽅法等价于 XML 中配置 bean。

el表达式详解

el表达式详解
${ername}
在Spring 中,所有逻辑处理单元返回的结果数据,都将作为Attribute 被放
置到HttpServletRequest 对象中返回(具体实现可参见Spring 源码中
org.springframework.web.servlet.view.InternalResourceView.
4) 条件标签&gt;
1.算术运算符有五个:+、-、*或$、/或div、%或mod
2.关系运算符有六个:==或eq、!=或ne、&lt;或lt、&gt;或gt、&lt;=或le、&gt;=或ge
3.逻辑运算符有三个:&amp;&amp;或and、||或or、!或not
4.其它运算符有三个:Empty运算符、条件运算符、()运算符
在EL中,这四个隐含对象只能用来取得范围属性值,即getAttribute(String name),却不能取得
其他相关信息。
例如:我们要取得session中储存一个属性username的值,可以利用下列方法:
session.getAttribute("username") 取得username的值,
另外在鲜少机会下,有可能同一标头名称拥有不同的值,此时必须改为使用headerValues 来取得
这些值。
3)initParam
initParam取得设定web站点的环境参数(Context)
例:一般的方法String userid = (String)application.getInitParameter("userid");
属性范围在EL中的名称

spring什么意思

spring什么意思一年四季,大家最喜欢那个季节?小编比较喜欢spring呢,因为樱花会开的很漂亮呢。

下面店铺为大家带来spring的英语意思和相关用法,欢迎大家一起学习!spring的英语音标英 [sprɪŋ]美 [sprɪŋ]spring的时态过去分词: sprung过去式: sprang现在分词: springingspring的意思n. 春天;弹簧;泉水;adj. 春天的vi. 生长;涌出;vt. 使跳起;使爆炸;spring的近义词vernalspring的同根词词根 springadj.springy 有弹力的springless 无弹性的,无弹簧的springlike 象春天的n.springer 起拱石;弹跳的东西;蹦跳的人springtime 春天;春季;初期springiness 有弹性;轻快spring的词语辨析skip, hop, spring, bound, leap, jump这组词都有“跳,跳跃”的意思,其区别是skip 指两脚交替轻地跳或跨的动作。

hop 指单脚短跳或双足猛力的动作。

也指小鸟、青蛙等的跳。

spring 更强调有力和弹跳的运动。

bound 多指向前向上或向下跳跃、奔跳。

leap 常可与jump换用,但侧重身体猛力向上升起并朝前急冲的动作,有时含突然的意味。

jump 是普通用词,指用双脚向上跳,向下跳,或在同一平面上跳到有一定距离的某一点上,或跳过。

spring的词汇搭配spring festival 春节(中国农历正月初一)in spring 在春天spring and autumn 春秋hot spring 温泉spring tide 大潮;涨潮spring and autumn period 春秋时代early spring 早春spring water 泉水spring的英语例句1. I let the horse drop his head to crop the spring grass.我让马低下头啃吃春天的青草。

使用ds注解 el表达式

在Java中,使用`@Value`注解和EL表达式可以实现动态注入值。

首先,需要在类上添加`@ConfigurationProperties`注解,然后在属性上添加`@Value`注解,并使用EL表达式来指定注入的值。

以下是一个简单的示例:1. 创建一个配置类,用于存储需要注入的属性值:```javaimport org.springframework.boot.context.properties.ConfigurationProperties;import ponent;ComponentConfigurationProperties(prefix = "myapp")public class MyAppConfig {private String name;private int age;// getter 和setter 方法public String getName() {return name;}public void setName(String name) { = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}}```2. 在需要使用这些属性的类中,使用`@Autowired`注解将配置类注入到当前类中,并使用EL表达式引用属性值:```javaimport org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;RestControllerpublic class MyController {Autowiredprivate MyAppConfig myAppConfig;GetMapping("/hello")public String hello() {String name = myAppConfig.getName();int age = myAppConfig.getAge();return "Hello, my name is " + name + " and I am " + age + " years old.";}}```在这个示例中,我们使用了`@ConfigurationProperties`注解来定义一个配置类`MyAppConfig`,并在其中定义了两个属性`name`和`age`。

spring使用Spring表达式(SpringEL)

spring使⽤Spring表达式(SpringEL) Spring还提供了更灵活的注⼊⽅式,那就是Spring表达式,实际上Spring EL远⽐以上注⼊⽅式强⼤,我们需要学习它。

Spring EL拥有很多功能。

使⽤Bean的id来引⽤Bean。

•调⽤指定对象的⽅法和访问对象的属性。

•进⾏运算。

•提供正则表达式进⾏匹配。

•集合配置。

这些都是Spring表达式的内容,使⽤Spring表达式可以获得⽐使⽤Properties⽂件更为强⼤的装配功能,只是有时候为了⽅便测试可以使⽤Spring EL定义的解析类进⾏测试,为此我们先来认识它们。

简要介绍Spring EL的相关类,以便我们进⾏测试和理解。

⾸先是ExpressionParser接⼝,它是⼀个表达式的解析接⼝,既然是⼀个接⼝,那么它就不具备任何具体的功能,显然Spring会提供更多的实现类 代码清单:举例说明Spring EL的使⽤//表达式解析器ExpressionParser parser = new SpelExpressionParser();// 设置表达式Expression exp = parser.parseExpression("'hello world'");String str = (String) exp.getValue();System.out.println(str);//通过EL访问普通⽅法exp = parser.parseExpression("'hello world'.charAt(0)");char ch = (Character) exp.getValue();System.out.println(ch);//通过EL访问的getter⽅法exp = parser.parseExpression("'hello world'.bytes");byte[] bytes = (byte[]) exp.getValue();System.out.println(bytes);//通过EL访问属性,相当于"hello world".getBytes().lengthexp = parser.parseExpression("'hello world'.bytes.length");int length = (Integer) exp.getValue();System.out.println(length);exp = parser.parseExpression("new String('abc')");String abc = (String) exp.getValue();System.out.println(abc);//表达式解析器ExpressionParser parser = new SpelExpressionParser();//创建⾓⾊对象Role2 role = new Role2(1L, "role_name", "note");Expression exp = parser.parseExpression("note");Expression exp = parser.parseExpression("note");//相当于从role中获取备注信息String note = (String) exp.getValue(role);System.out.println(note);//变量环境类,并且将⾓⾊对象role作为其根节点EvaluationContext ctx = new StandardEvaluationContext(role);//变量环境类操作根节点parser.parseExpression("note").setValue(ctx, "new_note");//获取备注,这⾥的String.class指明,我们希望返回的是⼀个字符串note = parser.parseExpression("note").getValue(ctx, String.class);System.out.println(note);//调⽤getRoleName⽅法String roleName = parser.parseExpression("getRoleName()").getValue(ctx, String.class);System.out.println(roleName);//新增环境变量List<String> list = new ArrayList<String>();list.add("value1");list.add("value2");//给变量环境增加变量ctx.setVariable("list", list);//通过表达式去读/写环境变量的值parser.parseExpression("#list[1]").setValue(ctx, "update_value2");System.out.println(parser.parseExpression("#list[1]").getValue(ctx)); EvaluationContext使⽤了它的实现类StandardEvaluationContext,进⾏了实例化,在构造⽅法中将⾓⾊对象传递给它了,那么估值内容就会基于这个类进⾏解析。

Spring2.0-applicationContext.xml中使用el表达式给实体类属性赋值被当成字符串-遁地龙卷风

(-1)写在前面这两天读《javaweb开发王者归来》,学到Spring的PropertyPlaceholderConfigurer 时出现一个问题,我已${}的形式赋值给bean中的属性,用main方法测试后,输出属性的值仍然是${}。

(0)解决问题之路a.我先想到是不是打错了,于是和书上仔细的对照了一下,发现书上说的是PropertyOverrideConfigurer,但实际上配置文件中写的是PropertyPlaceholderConfigurer,换来换去几次没用。

b.问了老师,在老师回去看资料的一瞬间突然有了灵感,我百度了一下,觉得找到了解决方案。

c.我想是不是没导入jar包、spring版本低,导致el表达式无法解析,一开始还一个个判定,后来把能导入的都导了还是不行,d.不断的换描述方式去百度我的问题,晚上有人要走了,提前一起吃一顿饭,吃晚饭去打lol,又百度了一会没有找到,于是在博问、问问上提问,到现在也没收到回复,英雄联盟输了一晚上,中途还断电了。

c.早上的时候想是不是main方法测试的原因,把项目部署到tomcat,在index.jsp中使用还是那样,于是乎我想到了是不是使用方式不对呢,之前也想到过PropertyPlaceholderConfigurer的bean是怎么和使用${}的bean关联到一起的,于是开始百度PropertyPlaceholderConfigurer的使用方法,间接的找到了解决方案。

(1)具体解决方案其实我觉得这个问题碰到的人真不多…,可能都是第一次学spring就读了这本书的人吧..,下面是其中一种方式配置文件<bean class="service.IDaoImp" id="iDaoImp" ><property name="name" value="${}"></property></bean><bean id="property"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"><value>classpath:jdbc.properties</value></property></bean>main方法XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml")); PropertyPlaceholderConfigurer propertyPostProcessor = (PropertyPlaceholderConfigurer)beanFactory.getBean("property"); propertyPostProcessor.postProcessBeanFactory(beanFactory);IDaoImp imp = (IDaoImp)beanFactory.getBean("iDaoImp");System.out.println(imp.getName());IDaoImppublic class IDaoImp{private String name;public String getName() {return name;}public void setName(String name) { = name;}}jdbc.properties=\u738B\u65EDjdbc.age=21。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ExpressionParser parser= new SpelExpressionParser();String el="'Hello Wrold!'";Expression expression=parser.parseExpression(el);String result=(String) expression.getValue();System.out.println(result);输出结果:Hello Wrold!要点:文字需要使用单引号包围调用方法ExpressionParser parser= new SpelExpressionParser();Expression expression=parser.parseExpression("'Hello World!'.charAt(1)"); Character result=(Character) expression.getValue();System.out.println(result);输出结果:e访问属性ExpressionParser parser= new SpelExpressionParser();访问属性既get方法Expression expression=parser.parseExpression("'Hello World!'.bytes"); byte[] result=(byte[]) expression.getValue();System.out.println(result);//访问数组的长度expression=parser.parseExpression("'Hello World!'.bytes.length"); Integer res=(Integer) expression.getValue();System.out.println(res);输出:[B@1546e2512要点:使用. 运算符号,可以访问属性(get方法)数组属性调用构造方法,和普通方法(非getter方法)ExpressionParser parser= new SpelExpressionParser();//访问属性既get方法Expression expression=parser.parseExpression("new String('hello world').toUpperCase()");String result=expression.getValue(String.class);System.out.println(result);输出:HELLO WORLD,上下文//2010-7-30GregorianCalendar calendar=new GregorianCalendar(2010,6,30); //姓名,生日Student stu=new Student("张三",calendar.getTime()); ExpressionParser parser = new SpelExpressionParser();//获取stu对象的name属性值Expression expression = parser.parseExpression("name");//stu对象作为上下文的根对象EvaluationContext context=new StandardEvaluationContext(stu); //表达式计算的时候,指定上下文String name = expression.getValue(context,String.class); System.out.println(name);输出:张三要点:上下文中存放一个根对象,计算表达式的时候,针对根对象进行计算直接计算,不通过上下文//2010-7-30GregorianCalendar calendar=new GregorianCalendar(2010,6,30); //姓名,生日Student stu=new Student("张三",calendar.getTime()); ExpressionParser parser = new SpelExpressionParser();//获取stu对象的name属性值Expression expression = parser.parseExpression("name");String name = expression.getValue(stu,String.class);System.out.println(name);使用EL修改集合或者数组中的元素// 2010-7-30GregorianCalendar calendar = new GregorianCalendar(2010, 6, 30);// 姓名,生日Student stu = new Student("张三", calendar.getTime(), new String[] {"音乐", "足球" });ExpressionParser parser = new SpelExpressionParser();//上下文EvaluationContext context=new StandardEvaluationContext(stu);//将爱好数组中的第一个元素更改成"游戏"parser.parseExpression("favorite[0]").setValue(context,"游戏");//输出System.out.println(stu.getFavorite()[0]);要点:准备一个要操作的根对象,然后将根对象放入到上下文中。

准备ExpressionParser解析器,使用它解析出一个Expression对象,然后调用Value方法更改它的值在xml配置文件和annotation中使用SpEL语法: #{<表达式>}配置文件中使用:<bean id="stu" class="com.wq.vo.Student"><property name="name" value="#{'zhangsan'.toUpperCase()}" /> </bean>表达式用可以引用其它Bean的对象,可以调用这些对象中的属性和方法在annotation中使用Annotation 为@Value(表达式),这个annotation可以使用在field,setter方法和方法参数中参考文档p194语言参考常量表达式:支持:字符串,日期,数字(int,real,hex),布尔,和null.字符串使用单引号包围,其它不需要使用单引号属性,数组,集合,Map集合,索引器索引器可以使用数字和字符方法:可以进行方法调用,并且可以为方法传递参数运算符:关系运算符instanceof运算符matches 正则表达式逻辑运算符: and(表达式中使用and) or(表达式中使用or) not (表达式中应该写成 !)数学运算: “+”用于数字,字符串和日期,减法只能用于数字和日期,乘法和除法用于数字,%求余,“^”用于幂运算:Inventor inventor = new Inventor();StandardEvaluationContext inventorContext = new StandardEvaluationContext(inventor);parser.parseExpression("Name").setValue(inventorContext, "Alexander Seovic2");// alternativelyString aleks = parser.parseExpression("Name = 'AlexandarSeovic'").getValue(inventorContext,String.class);类型运算符“T”使用T运算符运算出来的结果实际上是类中的Class类型的对象。

比如T(ng.Math) 与java代码: Math.class是一致的。

T运算符在什么情况下使用呢?当需要调用类中的静态方法的时候,需要用到,如:T(Math).abs()T后面的括号中应该是类的全名,ng包中的类不用写全名,而其它包必须写全名变量如果表达式中需要引用事前在上下文中定义好的变量,则应该使用 #+变量名: // 2010-7-30GregorianCalendar calendar = new GregorianCalendar(2010, 6, 30);// 姓名,生日Student stu = new Student("张三", calendar.getTime(), new String[] {"音乐", "足球" });ExpressionParser parser = new SpelExpressionParser();// 上下文EvaluationContext context = new StandardEvaluationContext(stu);context.setVariable("name","李四");//使用赋值操作符为stu中的name赋值,值从上下文中的变量获取parser.parseExpression("name=#name").getValue(context);// 输出System.out.println(stu.getName());#this 当前操作的对象#root 上下文中的根对象三元运算符:true?’aa’,’bbb’安全导航运算符:这个运算符保证当要操作的对象为空的时候,不会抛出空指针异常。

如: 表达式中,如果stu为空则会抛出空指针异常,stu?.name就不会抛出空指针了。

相关文档
最新文档