Questions tagged «java»

Java是一种流行的高级编程语言。如果您在使用或理解语言本身时遇到问题,请使用此标签。这个标签很少单独使用,最常与[spring],[spring-boot],[jakarta-ee],[android],[javafx],[gradle]和[maven]结合使用。



7
在构建Java项目时删除IntelliJ IDEA上的警告消息
我第一次使用IntelliJ IDEA社区版,并使用Maven设置TDD环境。下面提供了我要测试的代码以及我遇到的警告消息以及项目结构。 项目结构: 码: package miscellaneous; import org.junit.Test; import static org.junit.Assert.*; public class TestHello { // Methods to be tested..... private int Add1Plus1(int i, int j) { return (i + j); } @Test public void testAdd1Plus1() throws Exception { assertEquals(2, Add1Plus1(1, 1)); } } 配置详细信息: Java编译器: 1.8.0_45 Maven版本: 3.0.5 Maven用户设置文件的路径: …

5
Java 8 Collectors.toMap SortedMap
我正在使用Java 8 lambda,并且想要使用Collectors toMap返回一个SortedMap。我能想到的最好的Collectors toMap方法是使用一个虚拟对象mergeFunction并mapSupplier等于来调用以下方法TreeMap::new。 public static <T, K, U, M extends Map<K, U>> Collector<T, ?, M> toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier) { BiConsumer<M, T> accumulator = (map, element) -> map.merge(keyMapper.apply(element), valueMapper.apply(element), mergeFunction); return new CollectorImpl<>(mapSupplier, accumulator, …

4
Spring RESTTemplate的泛型
我有这样的课: public class Wrapper<T> { private String message; private T data; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public T getData() { return data; } public void setData(T data) { this.data = data; } } 我使用resttemplate如下: ... Wrapper<Model> response = restTemplate.getForObject(URL, …


12
变量可能尚未初始化错误
当我尝试编译时: public static Rand searchCount (int[] x) { int a ; int b ; ... for (int l= 0; l<x.length; l++) { if (x[l] == 0) a++ ; else if (x[l] == 1) b++ ; } ... } 我得到这些错误: Rand.java:72: variable a might not have been initialized a++ ; ^ …




5
如何使用带有Jersey的JAX-RS处理CORS
我正在开发一个Java脚本客户端应用程序,在服务器端我需要处理CORS,以及我用JERSEY用JAX-RS编写的所有服务。我的代码: @CrossOriginResourceSharing(allowAllOrigins = true) @GET @Path("/readOthersCalendar") @Produces("application/json") public Response readOthersCalendar(String dataJson) throws Exception { //my code. Edited by gimbal2 to fix formatting return Response.status(status).entity(jsonResponse).header("Access-Control-Allow-Origin", "*").build(); } 到目前为止,我收到错误消息请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问源' http:// localhost:8080 '。” 请协助我。 谢谢与问候普涅斯
72 java  rest  jersey  jax-rs  cors 

6
在Java中使用MessageFormat.format()格式化消息
我已经在资源束中存储了一些消息。我正在尝试按以下格式设置这些消息。 import java.text.MessageFormat; String text = MessageFormat.format("You're about to delete {0} rows.", 5); System.out.println(text); 假设第一个参数(即实际消息)存储在以某种方式检索到的属性文件中。 第二个参数(即5)是一个动态值,应放置在{0}不会发生的占位符中。下一行打印, 您即将删除{0}行。 占位符不会替换为实际参数。 这里是撇号- You're。我试图像往常一样逃避它,You\\'re尽管它没有用。需要进行哪些更改才能使其正常工作?

4
为什么在JUnit中不推荐使用assertEquals(double,double)?
我想知道为什么assertEquals(double, double)不推荐使用。 我曾经import static org.junit.Assert.assertEquals;使用过JUnit 4.11。 下面是我的代码: import org.junit.Test; import static org.junit.Assert.assertEquals; public class AccountTest { @Test public void test() { Account checking = new Account(Account.CHECKING); checking.deposit(1000.0); checking.withdraw(100.0); assertEquals(900.0, checking.getBalance()); } } checking.getBalance() 返回一个双精度值。 有什么事吗
72 java  junit  junit4 

3
改造2-URL查询参数
我正在使用查询参数来设置Google Maps API所需的值。 问题是我不需要&第一个查询参数的符号。 @GET("/maps/api/geocode/json?") Call<JsonObject> getLocationInfo(@Query("address") String zipCode, @Query("sensor") boolean sensor, @Query("client") String client, @Query("signature") String signature); 改造产生: &address=90210&sensor=false&client=gme-client&signature=signkey 当我需要它时会导致呼叫失败 address=90210&sensor=false&client=gme-client&signature=signkey 我该如何解决?

12
删除无法使用JpaRepository
我有一个Spring 4应用程序,试图从数据库中删除实体的实例。我有以下实体: @Entity public class Token implements Serializable { @Id @SequenceGenerator(name = "seqToken", sequenceName = "SEQ_TOKEN", initialValue = 500, allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqToken") @Column(name = "TOKEN_ID", nullable = false, precision = 19, scale = 0) private Long id; @NotNull @Column(name = "VALUE", unique = true) …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.