如何计算流过滤器的匹配?我正在尝试将以下代码重构为java8 stream:
//java7
int i = 0;
for (Node node : response.getNodes()) {
Integer id = node.getId();
if (id != null) {
node.setContent("This is the id: " + id);
i++;
}
}
//java8
response.getNodes().stream()
.filter(node -> node.getId() != null)
.forEach(node -> node.setValue("This is the id: " + node.getId()));
Run Code Online (Sandbox Code Playgroud)
我现在如何获得已应用的已过滤元素的数量?Sidequestion:在旧代码中我可以Integer id多次重复使用.如何使用流实现相同的功能?
SpringApplication将从以下位置的application.properties文件加载属性,并将它们添加到Spring环境中:
Run Code Online (Sandbox Code Playgroud)- A /config subdirectory of the current directory. - The current directory - A classpath /config package - The classpath root列表按优先级排序(在列表中较高位置定义的属性将覆盖在较低位置中定义的属性).
问题:在服务器war上运行文件时tomcat:如何为类路径或tomcat容器application.properties 外部添加其他位置d:\application.properties?
自定义位置应优先于上述位置.
问题是:我当然可以/config在tomcat webapps文件夹中的爆炸战争中添加一个文件夹,但是如果清理了webapps文件夹并重新部署了war,我将失去任何自定义配置.
因此,我想在外面添加一个额外的位置.
如何@see正确使用javadoc?
我的目的是使用抽象方法创建一个抽象类.这些方法有javadoc注释.现在,如果我扩展抽象类,我会覆盖方法并想要使用@see.
但对于所有的参数,可以如用于return该@see链接似乎并没有工作.Eclipse仍抱怨expected @return tag.
那我该怎么用?
public abstract class MyBase {
protected abstract void myFunc();
}
class MyImpl extends MyBase {
/**
* @see MyBase#myFunc()
*/
@Override
protected void myFunc() { .. }
}
Run Code Online (Sandbox Code Playgroud) 我的数据库中有一些日期条目.什么是最好的?:
order by.collection.sort左右对它们进行排序?谢谢
我在Enterprise Architect中有一些我要导入到MS Word的图表.
将图表输出到图片时,如何摆脱图表周围的边框和图表名称?怎么能被禁用?
我在tomcat webserver环境中运行war文件.
我有一个基于注释的配置@Beans,以及一个用于webservices的xml配置:
@Configuration
//@ComponentScan(basePackageClasses = ...)
public class AppConfig {
//beans @Bean
}
Run Code Online (Sandbox Code Playgroud)
applicationContext.xml中:
<beans>
<context:component-scan base-package="..."/>
<jaxws:endpoint ... />
</bean>
Run Code Online (Sandbox Code Playgroud)
问题:我想@ComponentScan通过注释定义只有类型安全.但如果我这样做,则不会执行扫描.相比之下,当我使用<context:component-scan..一切正常.
SpringWeb服务器中的组件扫描是否与用于包扫描的xml配置相关联?
我想在spring-data中使用方法名称的sql select.
选择应按价格排序.
@Entity
public class Product {
int name;
BigDecimal price;
}
interface ProductRepository extends CrudRepository<Product, Long> {
Product findFirstByNameOrderByPriceAsc(String name);
}
Run Code Online (Sandbox Code Playgroud)
结果:
org.springframework.dao.IncorrectResultSizeDataAccessException: result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements
Run Code Online (Sandbox Code Playgroud)
为什么?我正是findFirst()因为这个原因才使用该方法才能获得最佳结果,如果找到多个...
我使用的是spring带有CrudRepositoryS代表数据库连接.
现在我需要一个很长(几行)的SQL查询,我更喜欢在类路径中的文件中维护,而不是直接在代码中.
但我怎么能做到这一点?我的回购看起来如下:
@Query(value = "<my very long sql query>", nativeQuery = true) //how to inject file content?
@Modifying
@Transactional
public void executeSpecificSql();
Run Code Online (Sandbox Code Playgroud) 我正在使用tomcat连接池org.apache.tomcat.jdbc.pool.DataSource.连接在我的数据库中显示pg_stat_activity为空application_name.
我如何在我的java应用程序中设置该应用程序名称,因此我知道每个连接的来源(因为将有多个应用程序访问同一个数据库)?
我正在使用默认的日志记录配置logging.file=myfile.log.
如何在保持日志文件配置的日志文件的同时阻止控制台输出logback.xml?
我的目标是没有控制台窗口输出,但只记录到该文件.
无需创建特定的spring-bootspring-boot`,无需自己配置日志记录.
java ×9
spring ×5
spring-boot ×2
collections ×1
java-8 ×1
java-ee ×1
java-stream ×1
javadoc ×1
logging ×1
postgresql ×1
spring-data ×1
sql ×1
tomcat ×1
tomcat-jdbc ×1
uml ×1