小编use*_*644的帖子

如何在java 8中使用流将一些字段收集到一个列表中?

例如,我有一个名字和姓氏的人.

我想从人员列表中收集一个字符串列表(姓名和姓氏),但似乎我不能每个列表使用两次地图或者每个列表不能使用两次流.我的代码是:

persons.stream()
   .map(Person::getName)
   .collect(Collectors.toSet())
   .stream().map(Person::getSurname) 
   .collect(Collectors.toList())
Run Code Online (Sandbox Code Playgroud)

但它一直告诉我,Person静态方法不能引用非静态方法.

我究竟做错了什么?

java java-8 java-stream collectors

12
推荐指数
2
解决办法
9206
查看次数

名称的持久性单元定义冲突

运行我的 jar 时出现此异常。

java.lang.IllegalStateException: Conflicting persistence unit definitions 
for name 'hibernateUnit': file:/D:/Assignment.jar, file:/D:/Assignment.jar
Run Code Online (Sandbox Code Playgroud)

我的持久性.xml

<persistence version="1.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="hibernateUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>EventImpl</class>           
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format.sql" value="true"/>
            <property name="hibernate.connection.driver_class" value="${db.driver.name}"/>
            <property name="hibernate.connection.url" value="${db.url.value}"/>
            <property name="hibernate.connection.username" value="${db.user.name}"/>
            <property name="hibernate.connection.password" value="${db.user.password}"/>
        </properties>
    </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

我的 applicationContext.xml

<?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:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
    <context:annotation-config/>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:property-placeholder location="db.properties"/>       
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/> …
Run Code Online (Sandbox Code Playgroud)

java spring persistence hibernate entitymanager

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

我可以实际从lambda返回从方法返回并中断其执行吗?

例如:

private String test(Optional myOptional)
{
    myOptional.ifPresent(() -> return "1");
    return "0";
}
Run Code Online (Sandbox Code Playgroud)

所以当我调用test(myOptional)时,它将返回"1";

java lambda optional

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

v-select vuetify 最大元素数

v-select尽管数组 (persons) 有 22 个元素,但似乎只显示了数组中的 20 个元素,但是如果我使用自动完成功能,我可以在列表中看到这 2 个缺少的人,因此在我开始寻找使用自动完成功能之前,它们实际上不会显示. 代码如下:

<v-select
  :items="persons"
  v-model="model.persons"
  label="Persons:"
  item-text="name"
  item-value="id"
  multiple
  chips
  max-height="auto"
  autocomplete
>
  <template slot="selection" slot-scope="data">
    <v-chip
      :selected="data.selected"
      :key="JSON.stringify(data.item)"
      close
      class="chip--select-multi"
      @input="data.parent.selectItem(data.item)"
    >
       {{ data.item.name }}
    </v-chip>
  </template>
  <template slot="item" slot-scope="data">
    <template v-if="typeof data.item !== 'object'">
      <v-list-tile-content v-text="data.item"></v-list-tile-content>
    </template>
    <template v-else>                       
      <v-list-tile-content>
        <v-list-tile-title v-html="data.item.name"></v-list-tile-title>
      </v-list-tile-content>
    </template>
  </template>
</v-select>
Run Code Online (Sandbox Code Playgroud)

是否有任何v-select选项可用于增加该数字?

vue.js vuetify.js v-select

2
推荐指数
1
解决办法
2561
查看次数