小编Sau*_*mar的帖子

在对象上传播不可迭代实例的无效尝试

 data: [],

 ... 
Run Code Online (Sandbox Code Playgroud)

我将 API 调用中的数据加载到data数组中。然后我尝试使用下面的方法将数据数组排列成一个由键、值对(值可以是数组本身)组成的映射。

    const dataMap = {};
    for (let i = 0; i < data.length; i+=1) {
      const key = data[i].product.name;
      const value = data[i];

      if (key in dataMap) {
        dataMap[key].push(value);
      } else {
        dataMap[key] = [value];
      }
    }
Run Code Online (Sandbox Code Playgroud)

但是当我执行以下操作时,出现以下错误。我做错了什么?

{[...dataMap].map(([key, value]) => {}
Run Code Online (Sandbox Code Playgroud)

传播不可迭代实例的无效尝试

这是我的数据图 在此输入图像描述

DataMap 计算正确,但是当我使用以下代码进行迭代时

Object.entries(dataMap).map((key, value) => {
          console.log(key);
          console.log(value)
 })
Run Code Online (Sandbox Code Playgroud)

它打印出以下内容。值是一些我不明白为什么的索引?值应该是一个数组。我的dataMap是一个key,value(值是一个数组)

在此输入图像描述

javascript

7
推荐指数
1
解决办法
9万
查看次数

想要创建一个map <String,Object>,Object可以是String,也可以是Object类

如何创建一个Map<String , Object>.

每次Object都是一个字符串时,在这个映射中.但是现在我想在对象中添加一个类.这是混合字符串和类对象的好方法吗?如果是的话,当我遍历地图时,我如何在类和字符串之间进行区分?

java

6
推荐指数
2
解决办法
8万
查看次数

为什么这不会导致NullPointerException?

public class Null {
    public static void greet() {
        System.out.println("Hello world!");
    }

    public static void main(String[] args) {
        ((Null) null).greet();
    }
}
Run Code Online (Sandbox Code Playgroud)

节目输出:Hello world!.
我以为它会抛出一个NullPointerException.

它为什么会发生?

java

6
推荐指数
2
解决办法
284
查看次数

如何使用JdbcTemplate执行Join查询

我有以下数据库模型

       create table Diary (id bigint NOT NULL AUTO_INCREMENT,
                creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                name varchar(255) not null, 
                description text,
                viewtype varchar(255) not null,
                member bigint,
                primary key (id),
                foreign key (member) references Member(id));


       create table Page (id bigint NOT NULL AUTO_INCREMENT,
                creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                viewtype varchar(255) not null,
                diary bigint,
                member bigint,
                primary key (id),
                foreign key (diary) references Diary(id),
                foreign key (member) references Member(id));

       create table Comment (id bigint NOT NULL AUTO_INCREMENT,
                postingDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                comment text …
Run Code Online (Sandbox Code Playgroud)

spring jdbctemplate

6
推荐指数
1
解决办法
1万
查看次数

MongoRepository查询日期之间

我的pojo

public class PacketData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private final String token = UUID.randomUUID().toString();

    private final ZonedDateTime arrived = ZonedDateTime.now();
}
Run Code Online (Sandbox Code Playgroud)

我打算像下面这样使用。

@Query("?")
List<PacketData> findPacketArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以将以下查询放入上述query批注中,以及如何执行大于和小于逻辑

Query query = new Query().addCriteria(Criteria.where("arrived").gte(startDate).lte(endDate));
Run Code Online (Sandbox Code Playgroud)

spring-data spring-data-mongodb

6
推荐指数
1
解决办法
7269
查看次数

Spring mongodb模板保存在同一个对象中

我有这样的模型如下

@CompoundIndexes(value = {
        @CompoundIndex(name = "catalog_idx", def = "{'code' : 1, 'brand' : 1}", unique = true) })
@Document(collection = Catalog.ENTITY)
public class Catalog extends AbstractModel<String> {

    private static final long serialVersionUID = 1L;

    public static final String ENTITY = "catalog";

    @NotNull(message = "Code is required")
    @Field("code")
    private String code;

    @NotNull(message = "Brand is required")
    @DBRef(lazy = true)
    @Field("brand")
    private Brand brand;
}
Run Code Online (Sandbox Code Playgroud)

当我保存时,mongoTemplate.save(object);我只看到在DB而不是6中创建的2个对象.就在保存我的调试行以保存对象之前.

Catalog [code=StagedCatalog, brand=Brand [code=Brand_3]]
Catalog [code=StagedCatalog, brand=Brand [code=Brand_2]]
Catalog [code=StagedCatalog, brand=Brand [code=Brand_1]]
Catalog …
Run Code Online (Sandbox Code Playgroud)

spring-data spring-mongo spring-mongodb

6
推荐指数
1
解决办法
613
查看次数

Spring boot 2.1.3.RELEASE 发生了非法的反射访问操作

我在使用 JAVA 11 的日志文件中以红线显示以下内容。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/C:/Users/lol/.m2/repository/org/springframework/spring-core/5.1.5.RELEASE/spring-core-5.1.5.RELEASE.jar) to constructor java.math.BigDecimal(java.math.BigInteger,long,int,int)
WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Run Code Online (Sandbox Code Playgroud)

我也得到以下信息。这是否意味着 spring-data-redis 有问题

      java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
        at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
        at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:224)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:218)
        at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:212)
        at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:80)
        at io.netty.util.ResourceLeakDetector.<init>(ResourceLeakDetector.java:171)
        at io.netty.util.ResourceLeakDetector.<init>(ResourceLeakDetector.java:213) …
Run Code Online (Sandbox Code Playgroud)

spring netty spring-data-redis spring-boot

6
推荐指数
1
解决办法
6709
查看次数

什么是flipv和fliph:它是从css3中删除的

      <style>
        <!--
       .verticaltext {
           writing-mode: tb-rl;
           filter: flipv fliph;
        }
       -->
       </style> 
Run Code Online (Sandbox Code Playgroud)

什么是flipv和fliph?即使我删除它们,我可以看到文本垂直?我见过很多地方用过,而有些地方没用......

css css3

5
推荐指数
1
解决办法
1万
查看次数

需要ServletContext来配置默认的servlet处理

我试图找出问题好几天但没有运气.我遇到了这个问题,但由于我没有在这里做任何测试,因此无法弄清楚是什么问题.java.lang.IllegalArgumentException:需要ServletContext来配置默认的servlet处理

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
Run Code Online (Sandbox Code Playgroud)

我正在使用弹簧靴

@ComponentScan
@EnableAutoConfiguration
public class Application {
   .....
}

public class ApplicationWebXml extends SpringBootServletInitializer { …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-boot

5
推荐指数
0
解决办法
1540
查看次数

HashMap包含4个元素,但在调试中只显示3个元素

HashMap用以下代码定义了一个:

final Map<OrderItemEntity, OrderItemEntity> savedOrderItems = new HashMap<OrderItemEntity, OrderItemEntity>();
final ListIterator<DiscreteOrderItemEntity> li = ((BundleOrderItemEntity) oi).getDiscreteOrderItems().listIterator();

while (li.hasNext()) {
    final DiscreteOrderItemEntity doi = li.next();
    final DiscreteOrderItemEntity savedDoi = (DiscreteOrderItemEntity) orderItemService.saveOrderItem(doi);
    savedOrderItems.put(doi, savedDoi);
    li.remove();
}

((BundleOrderItemEntity) oi).getDiscreteOrderItems().addAll(doisToAdd);
final BundleOrderItemEntity savedBoi = (BundleOrderItemEntity) orderItemService.saveOrderItem(oi);
savedOrderItems.put(oi, savedBoi);
Run Code Online (Sandbox Code Playgroud)

我把4件物品放入HashMap.当我调试时,即使size它是4,它只显示3个元素:

调试会话

这是它包含的元素列表.

{DiscreteOrderItemEntity@1c29ef3c=DiscreteOrderItemEntity@41949d95, DiscreteOrderItemEntity@2288b93c=DiscreteOrderItemEntity@2288b93c, BundleOrderItemEntity@1b500292=BundleOrderItemEntity@d0f29ce5, DiscreteOrderItemEntity@9203174a=DiscreteOrderItemEntity@9203174a}
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

java hashmap

5
推荐指数
1
解决办法
590
查看次数