我正在尝试运行简单的 hello word java 程序并想要记录 hello world。但我收到错误
eclipse 中的声明为“无法访问包 java.util.logging”
import java.util.logging.*;。
我使用的是Java 11版本
完整代码如下
package myproject;
import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Logger;
import java.util.logging.*;
public class FileOperations {
public static void main(String[] args) {
// Create a Logger
Logger logger = Logger.getLogger(FileOperations.class.getName());
// Call info method
logger.info("This is message 1");
// TODO Auto-generated method stub
File file=new File("myFile.txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(file);
fos.write(2);
System.out.println("File operation completed");
Logger.log(Level.INFO, "My …Run Code Online (Sandbox Code Playgroud) 我正在将使用Spring实现的Maven项目迁移到Spring Boot 1.5.20.RELEASE。
\n我有一个适配器类,它将由所有带有注释的类扩展@RestControllers,以保证与前端的向后兼容性
public class RestControllerAdapter {\n\n private MessageTemplate messageTemplate;\n\n private MessageTemplate getMessageTemplate() {\n\n if (messageTemplate == null) {\n messageTemplate = ApplicationContextUtils.getBean(MessageTemplate.class);\n }\n\n return messageTemplate;\n }\n\n protected final String message(@NonNull String code) {\n return getMessageTemplate().getMessage(code);\n }\n\n protected final String message(@NonNull String code, Object... args) {\n return getMessageTemplate().getMessage(code, args);\n }\n\n protected final ModelMap success() {\n val map = new ModelMap();\n map.put("success", true);\n map.put("message", getMessageTemplate().getMessage("message.success.default"));\n return map;\n }\n\n protected final ModelMap error(@NonNull …Run Code Online (Sandbox Code Playgroud) 我创建了 spring-boot gradle 多模块项目,其中包含 3 个模块:控制器、服务、存储库。主文件位于控制器模块中,名为 MySpringBootApplication。
我可以构建这个项目(使用 gradle build)并可以获得 jar 文件。但是在命令行中启动这个 jar 后,我遇到了下一个错误:
Error: Could not find or load main class com.epam.esm.config.MySpringBootApplication Caused by: java.lang.ClassNotFoundException: com.epam.esm.config.MySpringBootApplication.
Run Code Online (Sandbox Code Playgroud)
为了修复此错误,我在 main 中的MANIFEST.MF文件Main-Class中添加了属性,但此操作没有帮助。那么有人可以帮忙吗?build.gradle
主要构建.Gradle 文件
plugins {
id 'java'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.4.3'
id 'application'
}
group = 'com.myproject'
version = 'snapshot-1.0.0'
repositories {
mavenCentral()
}
bootJar {
enabled = false
}
jar {
enabled = true
manifest {
attributes(
"Main-Class": "com.myproject.config.MySpringBootApplication")
}
} …Run Code Online (Sandbox Code Playgroud) 我想验证文本字段是否为空或不使用javafx。
我对事件处理程序感到困惑。我想确认一下:-是否有很多方法可以使用setOnAction:
submit.setOnAction((new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
System.out.println("Hello World");
}
}));
Run Code Online (Sandbox Code Playgroud)
要么
submit.setOnAction(e -> handle(e));
Run Code Online (Sandbox Code Playgroud)
这两个选择有什么区别?
我想验证我的应用程序中的文本字段。
public class AppGUI extends Application{
public static void main(String[] args)
{
launch();
}
public void start(Stage topView)
{
createUI(topView);
}
private void createUI(Stage topView)
{
TextField name = TextField();
Button submit = new Button("Submit");
submit.setOnAction(e -> validate());
}
private boolean validate()
{
// if textfield is empty, return false. else, return true.
}
Run Code Online (Sandbox Code Playgroud)
我在这里迷路了。如果setOnAction中的e未在validate中使用,可以吗?如何将textfield的值传递给validate()?使文本字段私有变量是唯一的方法吗?(因为我有这么多文本字段,所以我想知道它是否是一个不错的选择)。在createUI方法中,我怎么说是否validate()返回false,显示错误消息,如果是,则执行其他操作?谢谢你,很抱歉打扰
我是Java新手。我看到有些人使用这个函数在 Spring 中返回唯一的 id。此函数是否返回唯一值?
public class Utils {
private final Random RANDOM = new SecureRandom();
private final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private String generateRandomString(int length) {
StringBuilder returnValue = new StringBuilder(length);
for (int i = 0; i < length; i++) {
returnValue.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length())));
}
return new String(returnValue);
}
}
Run Code Online (Sandbox Code Playgroud) java ×4
spring-boot ×2
eclipse ×1
eventhandler ×1
gradle ×1
javafx ×1
multi-module ×1
spring ×1