精华内容
下载资源
问答
  • public class ListTest { static List> list =null; public static void main(String[]args) { ...System.out.println(list.isEmpty());// ① System.out.println(CollectionUtils.isEmpty(list));// ② ...
    public class ListTest {
     
    static List> list =null;
     
    public static void main(String[]args) {
     
    System.out.println(list.isEmpty());//    ①
     
    System.out.println(CollectionUtils.isEmpty(list));//   ②
     
    }
     
    }
    

    结果:
    ①这儿会java.lang.NullPointerException
    ②则不会

    展开全文
  • 结论 jar包冲突,需要更换 spring-context的版本,具体...java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.unwrapOptional(Ljava/lang/Object;)Ljava/lang/Object; at org.springframework...

    结论

    jar包冲突,需要更换 spring-context的版本,具体如下

    springBoot启动测试类报错:

    java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.unwrapOptional(Ljava/lang/Object;)Ljava/lang/Object;
    
    	at org.springframework.validation.DataBinder.<init>(DataBinder.java:180)
    	at org.springframework.boot.bind.RelaxedDataBinder.<init>(RelaxedDataBinder.java:83)
    	at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:268)
    	at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:256)
    	at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:232)
    	at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:183)
    	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:168)
    	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:154)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:68)
    	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:337)
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:111)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    	at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager
    

    报错原因,引入了 spring-context 包。目的是为了 Spring通过应用上下文(Application Context)装载bean的定义并把它们组装起来,可能这么说大家不太理解,举个例子就明白了,就是使用@Service来注入bean的

           <dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>5.2.4.RELEASE</version>
    		</dependency>
    

    正确解决报错,修改jar包版本。改为如下配置

          <dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>4.3.12.RELEASE</version>
    		</dependency>
    
    展开全文
  • (三)JAVA工具类ObjectUtils.Null详解

    千次阅读 2018-01-21 17:30:59
    一、ObjectUtils.Null类作为一个空占位符,其中null具有另外一个含义。 例如在HashMap中的HashMap.get(java.lang.Object) 方法返回null如果这个Map包含null(也就是有一个key对应的值为null),或者这里就不存在...

    一、ObjectUtils.Null类作为一个空占位符,其中null具有另外一个含义。

    • 例如在HashMap中的HashMap.get(java.lang.Object) 方法返回null如果这个Map包含null(也就是有一个key对应的值为null),或者这里就不存在对应的key,这个空的占位符可以区分这两种情况。

      如下代码HashMap中存储有一个字段username值为null

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("username", null);
            System.out.println(map.get("username"));
            System.out.println(map.get("password"));这里写代码片

    输出结果是:

    null
    null

    根据如上的结果我们是没有办法区分Map中是否存在字段username、password的,要想区分Map中存在的字段username值为null和不存在字段password的情况我们可以使用空占位符的方法:

            map.put("username", ObjectUtils.NULL);
    
            System.out.println(ObjectUtils.NULL == map.get("username"));
            System.out.println(ObjectUtils.NULL == map.get("username1"));
            System.out.println(null == map.get("username1"));

    输出的结果是:

    true
    false
    true
    
    展开全文
  • java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.unwrapOptional(Ljava/lang/Object;)Ljava/lang/Object; [2018-12-27 03:16:35,175] Artifact ssmproject01:war exploded: Artifact is bein....
    java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.unwrapOptional(Ljava/lang/Object;)Ljava/lang/Object;
    [2018-12-27 03:16:35,175] Artifact ssmproject01:war exploded: Artifact is being deployed, please wait...
    27-Dec-2018 15:16:35.477 警告 [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
    27-Dec-2018 15:16:38.175 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    15:16:38 DEBUG CharacterEncodingFilter:213 - Initializing filter 'characterEncodingFilter'
    27-Dec-2018 15:16:38.474 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
    27-Dec-2018 15:16:38.474 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/ssm] startup failed due to previous errors
    [2018-12-27 03:16:38,521] Artifact ssmproject01:war exploded: Error during artifact deployment. See server log for details.
    27-Dec-2018 15:16:44.870 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\AboutJAVA\apache-tomcat-8.5.33-windows-x64\apache-tomcat-8.5.33\webapps\manager]
    27-Dec-2018 15:16:44.941 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\AboutJAVA\apache-tomcat-8.5.33-windows-x64\apache-tomcat-8.5.33\webapps\manager] has finished in [71] ms
    

    完全看不懂的错误。

    反正不是我代码的错

     

    所以就是maven导包的错!!

    我有个spring的包是4.+的而其他都是统一的5.+改一下就解决了

     

    具体要找自己的包。看看哪些是不是有冲突。或者不一致。这个问题的原因一般都是不一样的。但是原理都是一样的。包的版本或者包之间有所冲突

    展开全文
  • hasText(String) (or ObjectUtils.isEmpty(Object)) 废弃的原因是有人提交了issue后被官方接纳了。 issue地址 Deprecate StringUtils.isEmpty(Object) and replace remaining usage (e.g. with ObjectUtils.isEmpty...
  • CollectionUtils.isEmpty

    2021-09-01 16:47:05
    CollectionUtils.isEmpty(null): true  CollectionUtils.isEmpty(new ArrayList()): true   CollectionUtils.isEmpty({a,b}): false 判断集合是否不为空 CollectionUtils.isNotEmpty(null): false  ...
  • /** * @func 判断Object是否为空 * @author 皮锋 * @param object * @date 2016/12/16 * @returns {Boolean} */ function isEmptyObject(object) { var t; for (t in object) return !... ...
  • java.lang.nosuchmethoderror java.lang.String.isEmpty()Z. 昨天eclipse突然不能启动.然后用eclipsec.exe跑了一下.找到了原因.换了个工作空间. 重新加载tomcat. 启动的时候就报错了.java.lang.nosuchmethoderror...
  • org.apache.commons.lang包下面的 ...StringUtils.isEmpty(string) org.springframework.util 包下面的 StringUtils.isEmpty(Object obj); 转载:https://blog.csdn.net/Jg_0829/article/details/99298021 ...
  • CollectionUtils.isEmpty和 == null的区别

    千次阅读 2020-01-14 15:15:07
    CollectionUtils.isNotEmpty() 包含null,size=0等多种情况 而== null 只能用来判断... if (CollectionUtils.isEmpty(orderDTO.getOrderDetailList())) { log.error("[创建订单]购物车不能为空,customerOrderFor...
  • 两者都是用来判断字符是否为空方法,先看下源码。 /** * <p>Checks if a String is empty ("") or null.</p> 检查String是否为空(“”)或null。... * StringUtils.isEmpty(null) = true * St...
  • 今天在尝试自己做一个转换器时,被系统提示isEmpty被启用,但是学习视频中没有: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210109195235937.png?x-oss-process=image /watermark,type_ZmFuZ3poZW5...
  • @Test public void testStr() { /*----------------【Start】isEmpty方法检查-----------------*/ List<String> strList1 = Lists.newArrayList(); System.out.println(Collection...
  • StringUtils.isEmpty()的使用

    千次阅读 2017-07-11 10:34:15
    isEmpty (hegx)) ; System. out .println(StringUtils. isEmpty (str)) ; } } 输出结果为: true true 从结果来看为什么在判断字符春是否为空的情况的时候可以使用这个,因为我们很...
  • objectUtils 使用可能会出现的问题

    千次阅读 2020-10-13 09:49:54
    当一个类没有实现toString方法的时候,objectUtils会通过调用object的toString方法对对象实例化,所以objectUtils.isEmpty可能会对为空的对象返回false 例如: String s1 = ObjectUtils.identityToString(null); ...
  • as of 5.3, in favor of hasLength(String) and hasText(String) (or ObjectUtils.isEmpty(Object)) Check whether the given object (possibly a String) is empty. This is effectively a shortcut for !has...
  • List<XXXDTO>... ObjectUtils.isEmpty(p.getPhone())).forEach(System.out::println); 2.返回【名字里包含“白”】的集合 xxxList.stream().filter(p -> p.getName.contains("白")).collect(C
  • 1.Controller对象参数添加注解 import javax.validation.Valid; // ... @PostMapping("insert") public ResultVo ... if(ObjectUtils.isEmpty(clientInfoVo)){ return ResultVo.fail("新增对象不能为空
  • Apache-commons-lang3 ObjectUtils 使用

    千次阅读 2019-09-05 23:34:33
    Object工具类 allNotNull(Object… values) 检查所有元素是否为空,返回一个boolean 如果有一个元素为空返回false,所有元素不为空或元素为empty返回true ...ObjectUtils.allNotNull(null) ...
  • ... 会员登录 用户中心 ...public void registerCoupon(long userId) { ...RegisterMarketing registerMarketing = registerMarketingService.queryRegisterMarketing();...ObjectUtils.isEmpty(registerMarketing)) {
  • java比较日期大小

    2021-06-30 19:06:15
    ObjectUtils.isEmpty(recordDeviceOperateReqVo.getStartStartuptime())) && (!ObjectUtils.isEmpty(recordDeviceOperateReqVo.getEndStartuptime()))){ if((recordDeviceOperateReqVo.getStartStartuptime...
  • 1、对象判空 User user = (User)session.getAttribute(...// 工具类:ObjectUtils.isEmpty(Object obj) // import org.springframework.util.ObjectUtils; 2.ObjectUtils.isEmpty(dog) 2、包装类型的数组判空 Inte...
  • java常用判空条件

    2021-08-17 10:22:26
    字符串判空 StringUtils.isEmpty()和...apache.commons.lang3下的ObjectUtils.isEmpty() public static boolean isEmpty(Object object) { if (object == null) { return true; } else if (object instance
  • boolean b1 = org.springframework.util.ObjectUtils.isEmpty(map); 为null或者 里面没有东西的时候
  • if (ObjectUtils.isEmpty(o1)){ redisTemplate.opsForValue().set(key,1); } Object o2 = redisTemplate.opsForValue().get(key); o2一直是null,明明我在前面做了判空, 而且debug的时候,set方法也执行了,但是...
  • 流方式获取照片

    2021-10-09 08:49:38
    public byte[] lookRwqdPicture(Integer id) throws IOException { CheckPicture pic = ...ObjectUtils.isEmpty(pic.getName())) { Path path = Paths.get(pic.getZpfwqlj(), pic.getName()); ...
  • 从List对象集合中取出某个字段的集合 list.stream().map(p ->...ObjectUtils.isEmpty() # 判断Object是否为空 map型对象转为实体对象 CoCustomerDTO info = JSON.parseObject(JSON.toJSONString(ma
  • 使用org.springframework.util包下的ObjectUtils.isEmpty(Object obj),源码如下 public static boolean isEmpty(Object obj) { if (obj == null) { return true; } if (obj.getClass().isArray()) { ...
  • 注意非空判断

    2020-12-09 14:10:26
    ObjectUtils.isEmpty(user)){ result.success=ResultStatus.SUCCESS.isFlag(); result.code=ResultStatus.SUCCESS.getCode(); result.msg=ResultStatus.SUCCESS.getMsg(); Map<String, String> map = n
  • Java Work

    千次阅读 2020-12-20 14:55:38
    对于对象或数组使用ObjectUtils.isEmpty()判定,可以尝试使用Optional.ofNullable() 对于数组使用ArrayUtils.isEmpty()判空(null和length=0) 对于字符串使用 StringUtils.isBlank()判空(null和空字符串) 工具类 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,982
精华内容 2,792
关键字:

objectutils.isempty