草庐IT

print-method

全部标签

java - 错误 : Attempted to call method "format" on null context object

Spring-bootv1.4.1Javav1.8Thymeleafv2.1.5。下面这行代码在我看来:它具有我基于S.O.的语法。问题SpringBootThymeleafOrdinalNumbers,产生错误:org.springframework.expression.spel.SpelEvaluationException:EL1011E:(pos11):Methodcall:Attemptedtocallmethodformat(java.time.LocalDate,java.lang.String)onnullcontextobject但是,如果我在没有Thymeleaf

java - Joda - 从 PeriodFormat.getDefault().print() 中删除秒、毫秒?

我有一个这样的方法:publicstaticStringgetFormattedDateDifference(DateTimestartDate,DateTimeendDate){Periodp=newPeriod(startDate,endDate);returnPeriodFormat.getDefault().print(p);}我想减少打印的秒数和毫秒数。我该怎么做? 最佳答案 如果您只想将时间缩短到分钟,为什么不直接指定正确的周期类型作为开始呢?privatestaticfinalPeriodTypePERIOD_TO_M

java - Play Framework : Redirect to controller method with arguments

我正在使用PLAY框架2.2.1构建一个Web应用程序,并试图在地址栏中显示所请求站点的所有可用httpget查询参数,即使是那些未在请求中设置的参数。在这种情况下并非所有httpget参数都已设置,我想添加具有默认值的未设置参数并进行重定向。我有一个可以使用GET请求的站点:GET/testcontrollers.Application.test(q:String,w:String?=null,f:String?=null,o:String?=null)这是我希望在controllers.Application中使用的方法:publicstaticResulttest(Stringq

Java8 : Is there a way to get an instance method reference from a class method reference?

例如,如果我有这样的界面:publicinterfaceFooBar{Bfoo(Aa);Bbar(Aa);}有没有办法像FooBar::bar那样获取类级别的方法引用?并获取实例方法引用?即。如果我有FooBarmyFooBarInstance;BiFunction,A,B>barFunction=FooBar::bar;有什么简单的方法可以得到Function与我定义的实例相匹配的实例FunctionmyBarFunction=myFooBarInstance::bar; 最佳答案 您想要做的在函数编程世界中被称为“部分函数应用程

java - 在 java 中打印将标题设置为 "Java Printing"

以下代码有效,但是当我打印到PDFCreator打印机驱动程序时,它的默认标题是“JavaPrinting”。(我怀疑Adob​​eDistiller也是如此,因为如果你使用searchgoogleforPDFswithJavaPrinting,你会得到很多结果。)有没有办法将它从“JavaPrinting”更改为另一个字符串?packagecom.example.test.gui;importjava.awt.Graphics;importjava.awt.print.PageFormat;importjava.awt.print.Printable;importjava.awt.p

java - Java 的 System.out.print() 会一直缓冲到 println() 吗?

我今天无意中听到关于System.out.print()的争论。一个人声称,由于print()不包括终止\n,它写入的缓冲区最终将填满并开始丢失数据。另一个人声称他们一直在为他们所有的Java程序使用System.out.print()并且从未遇到过这个问题。第一人称对吗?如果stdout已满,System.out.print()是否可以开始阻止或丢弃数据?是否有导致此问题的代码示例? 最佳答案 当System.out.print使用的缓冲区填满时,输出将写入文件(或连接到程序标准输出流的终端或其他数据目标),导致一个空缓冲区。在不

java - 使用 System.out.print 与 println 的多线程问题

我有以下线程,它每200毫秒打印一个点:publicclassProgress{privatestaticbooleanthreadCanRun=true;privatestaticThreadprogressThread=newThread(newRunnable(){publicvoidrun(){while(threadCanRun){System.out.print('.');System.out.flush();try{progressThread.sleep(200);}catch(InterruptedExceptionex){}}}});publicstaticvoid

java - 为什么 System.out.print() 不工作?

所以我正忙着编写一个我认为是相对简单的“读取文件”程序。我遇到了很多编译错误,所以我开始尝试一次编译一行,看看我在哪里被清理了。这是我到目前为止的位置:importjava.nio.file.*;importjava.io.*;importjava.nio.file.attribute.*;importjava.nio.channels.FileChannel;importjava.nio.ByteBuffer;importstaticjava.nio.file.StandardOpenOption.*;importjava.util.Scanner;importjava.text.*

java - 有人可以解释 "Note: This method should be called under AWT tree lock."吗?

我正在尝试让我的程序读取以类似问卷的形式输入的答案。为此,我计划使用getComponents()获取所需的答案字段(例如,文本字段,单选按钮等),然后使用诸如getText()之类的方法读取答案。我从未使用过getComponents(),而只是在学习Java/Swing/AWT。getComponents()文档中的上述警告使我感到恐惧,因为我不知道什么是“树锁”,或者在哪里可以找到它。谷歌一无所获。即使事实证明getComponents()对于我的问题来说是不合适的解决方案,为了学习,我仍然希望我的问题得到解答。谢谢!:) 最佳答案

java - Spring 启动 1.4 : Executing Method after Liquibase finished

我有一个使用Liquibase的基于SpringBoot1.4.0的项目。是否可以在liquibase完成后执行方法?类似Bean后处理器的东西?我想做的是在应用程序以开发模式启动时向我的数据库添加一些数据。在开发模式下,应用程序使用内存中的h2数据库,因此liquibase必须在我写入数据之前创建表。 最佳答案 SpringBoot自动配置一个名为liquibase的SpringLiquibasebean。任何依赖于这个bean的bean都将在Liquibase完成后创建。例如,您可以使用@PostConstruct来填充数据库: