小编Sha*_*jun的帖子

为什么Java 8为方法引用引入了新的"::"运算符?

在Java 8中,方法引用是使用::运算符完成的.

例如

// Class that provides the functionality via it's static method
public class AddableUtil {
  public static int addThemUp(int i1, int i2){
    return i1+i2;
  }
}

// Test class
public class AddableTest {
  // Lambda expression using static method on a separate class
  IAddable addableViaMethodReference = AddableUtil::addThemUp;
  ...
}
Run Code Online (Sandbox Code Playgroud)

你可以看到addableViaMethodReference现在的行为就像是一个别名AddableUtil::addThemUp.因此addableViaMethodReference()将执行相同的操作 AddableUtil.addThemUp()并返回相同的值.

他们为什么选择引入新的运营商而不是现有运营商?我的意思是,当函数名称结束时执行函数,()并在没有尾随时返回函数引用().

方法执行

AddableUtil.addThemUp();
Run Code Online (Sandbox Code Playgroud)

方法参考

AddableUtil.addThemUp;
Run Code Online (Sandbox Code Playgroud)

这不是更简单直观吗?AFAIK,AddableUtil.addThemUp当前不(Java 7)用于任何其他目的并抛出编译错误.为什么不利用这个机会而不是创建一个全新的运营商呢?

java java-8 method-reference

23
推荐指数
2
解决办法
2598
查看次数

rails访问部分内部的视图名称

我有一个部分,我在不同的页面使用.我想根据呈现它的视图有条件地隐藏部分内部的某个div.

我正在考虑创建一个页面特定的javascript文件,它将查找div并隐藏它.

但是,如果有一种方法来检索部分内部的视图名称/页面名称,它将是部分的中心,并且不需要在多个页面中加载相同的javascript文件.

有没有人知道在局部内部做这件事的方法

ruby-on-rails partial-views

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

Spring Data JPA中@Modifying方法的返回值是什么意思

@Repository
public interface LoginDao extends JpaRepository<LoginEntity, Integer> { //}, LoginDaoCustom {
    LoginEntity findByLogin(String login);

    @Modifying
    int changePassword(String password, String login);
}
Run Code Online (Sandbox Code Playgroud)

如果我将changePassword的返回值更改为int以外的任何值,我会得到以下错误.

Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
    at org.springframework.util.Assert.isTrue(Assert.java:65)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.<init>(JpaQueryExecution.java:166)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.getExecution(AbstractJpaQuery.java:106)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:86)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
    ... 46 more
Run Code Online (Sandbox Code Playgroud)

这个整数返回值是什么意思?我确信春天有记录在某处,但我找不到它.它未列在jpa.modifying-queries中

我应该补充一点,如果将返回类型声明为int,则更新将以静默方式失败,并且不会更新值.

spring spring-data spring-data-jpa

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

薄控制器

我正在用javafx弄湿我的脚.这就是我在做的事情.

FXML Views
DI Controllers
Weld-SE Managed Services and Models
Trying to confine UI to FXML
Trying keep the Controllers thin
Run Code Online (Sandbox Code Playgroud)

问题:

在尝试编写UI时,大多数静态UI都被限制在fxml中.但有些情况下,我发现自我添加,删除,显示,隐藏元素等.

我发现自己在控制器内执行此操作,因为fx允许我在视图中配置控制器方法,它将调用特定的操作/事件.所有这些代码都涉及动态UI构建/操作,属于视图层.但是,它最终会在控制器中使控制器变胖.

javafx提供了javascript集成.这是一种可能的方法来抽象出那个视图的manupulation代码.但这会增加不太完美的javascript.

我如何在java或fxml中抽象出代码,这样我就不会破坏Thin Controller Paradigm?

编辑

@assylias

同意,我已经考虑过这种方式,这样java类和fxml一起成为一个可重用的小部件.但是,我如何将其连接到FXML.FXML除了控制器之外什么都不懂.假设我使用fx:controller将此视图类连接到fxml中,而不是将其命名为控制器.所以我有这样的事情.

在此输入图像描述

此视图类只有视图操作代码.然后我会创建另一个控制器类.但后来我希望以某种方式将表单数据填充到此控制器中.这应该仅在用户提交表单时发生.所以在某种程度上,我需要以某种方式告诉javafx UI操作请求/事件与实际数据操作请求/事件不同.

你的想法,对不起,如果它是冗长的.试图用尽可能少的语言表达出来.

java javafx-2

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

如何检查用户是否已登录javascript

我有一个登录灯箱,需要在用户未登录时显示.灯箱完全在javascript,fancybox中实现,并使用rails部分为html.

我可以看到cookie在登录时设置为chrome,但document.cookie似乎返回空.原因可能在这里解释

我如何在javascript/erb中实现这一点.

javascript jquery ruby-on-rails

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

在java swing中自定义详细的html链接颜色

Swing允许在组件中使用html JLabel.文件详细讨论了这一点.它还显示了如何更改特定文本的颜色.

我正在使用包含数千个此类组件的现有swing应用程序.我想改变使用它的链接的颜色.一次做一个将是非常乏味的.默认情况下,如果未指定颜色,则swing似乎将其呈现为蓝色.

如何将此默认值更改为其他内容?

java swing

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

在hg diff patch中包含新文件

如何在mercurial diff补丁中添加新文件?我似乎无法在手册页中找到任何信息.

mercurial

4
推荐指数
1
解决办法
1880
查看次数

@ControllerAdvice是否覆盖SimpleMappingExceptionResolver?

我这样SimpleMappingExceptionResolver配置了.

@Bean(name = "simpleMappingExceptionResolver")
public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() {
    SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();

    Properties mappings = new Properties();
    mappings.setProperty("InvalidRequestException", "error");
    mappings.setProperty("GenericServerException", "error");
    mappings.setProperty("IllegalArgumentException", "error");

    r.setExceptionMappings(mappings);
    r.setDefaultErrorView("error");
    r.setExceptionAttribute(DEFAULT_EXCEPTION_ATTRIBUTE);
    r.setWarnLogCategory("org.springframework.web.servlet.handler.SimpleMappingExceptionResolver");
    return r;
}
Run Code Online (Sandbox Code Playgroud)

但是我有一个@ControllerAdvice定义MethodArgumentNotValidException.class并放在@ComponentScan触手可及的范围内.但由于某些原因,我没有调用类中的带@ExceptionHandler注释的方法@ControllerAdvice.但我确实看到了堆栈跟踪.它促使我思考,spring正在使用一些defaultHandler MethodArgumentNotValidException.class.

WARN : org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Handler execution resulted in exception
org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument at index 0 in method: public com.mrll.global.profile.model.PasswordInfo com.mrll.global.controller.PasswordController.passwordInfo(com.mrll.global.core.password.PasswordChange) throws com.mrll.global.profile.PasswordChangeException, with 1 error(s): [Field error in object 'passwordChange' on field …
Run Code Online (Sandbox Code Playgroud)

spring exception-handling spring-mvc

4
推荐指数
1
解决办法
1969
查看次数

此媒体所需的编码器正忙

尝试通过AVAssetWriter和AVAssetWriterInput方法将多个视频连接成一个时.在第3个视频之后,我从AVAssetWriter.error收到"无法编码"错误.

另外,我能够通过控制台看到成功读取到缓冲区,但只有最后成功读取的视频才会在连接的mov中结束.任何对任何一个或两个问题的了解,来源和日志如下.谢谢

+(void)doWriteWithVideoWriter:(AVAssetWriter *)videoWriter withIndex:(int)index withWriterInputArray:(NSMutableArray *)writersArray withInstance:(VideoCombinerManager *)theInstance{
if ([writersArray count] > 0)
{
    int newIndex = index+1;

    NSError *readerError;
    NSDictionary *videoOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey];

    AVAsset *sourceAsset = [theInstance.loadedAssetsForCompilationDictionary objectForKey:[theInstance.sortedKeysArray objectAtIndex:index]];
    AVAssetTrack *videoTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    AVAssetReaderTrackOutput *currentReaderTrackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:videoOptions];
    AVAssetReader *currentReader = [[AVAssetReader alloc] initWithAsset:sourceAsset error:&readerError];
    [currentReader addOutput:currentReaderTrackOutput];
    [currentReader startReading];

    AVAssetWriterInput *writerInput = [[writersArray objectAtIndex:0] retain];

    dispatch_queue_t _processingQueue = dispatch_queue_create("asdf", NULL);
    [writerInput requestMediaDataWhenReadyOnQueue:_processingQueue usingBlock:^{
    if ([writerInput isReadyForMoreMediaData])
    {
        CMSampleBufferRef nextSampleBuffer;

        if ([currentReader …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios

3
推荐指数
1
解决办法
1623
查看次数

使用netbeans时Ubuntu上的Javafx错误

当试图在ubuntu linux上运行一个基本的javafx应用程序时,我看到以下错误.使用命令行或netbeans运行应用程序时出现错误.

Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: /home/venkat/.m2/repository/com/oracle/javafx/javafx/2.1.0-beta/i386/libglass.so
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:277)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:90)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:163)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: /home/venkat/.m2/repository/com/oracle/javafx/javafx/2.1.0-beta/i386/libglass.so
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1828)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:143)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:56)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:31)
at com.sun.glass.ui.Application$1.run(Application.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:73)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:85)
at com.sun.glass.ui.gtk.GtkPlatformFactory.<clinit>(GtkPlatformFactory.java:23)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.sun.glass.ui.PlatformFactory.getPlatformFactory(PlatformFactory.java:20)
at com.sun.glass.ui.Application.Run(Application.java:108)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:267)
... 5 more
Run Code Online (Sandbox Code Playgroud)

linux netbeans javafx

3
推荐指数
1
解决办法
2721
查看次数