草庐IT

int_data

全部标签

java - Spring Data JPA 存储库 : IN-clause in derived query not working

我有一个看起来像这样的存储库:publicinterfaceUserRepositoryextendsJpaRepository{UserfindByEmailIgnoreCase(Stringemail);@Query("selectufromUseruwhereu.idin(:ids)")SetgetByIdInSet(@Param("ids")Setids);}当我调用getByIdInSet时,出现以下错误:Causedby:java.lang.IllegalArgumentException:Youhaveattemptedtosetavalueoftypeclassorg.

java - 将 Object[] 数组转换为 java 中的 int [] 数组?

似乎没有简单的方法可以做到这一点,但这是我到目前为止所做的,如果有人可以更正它以使其正常工作,那就太好了。在“newarray[e]=array[i].intValue();”我收到错误消息“在类型“java.lang.Object”中找不到名为“intValue”的方法。”帮助!/*Description:Agamethatdisplaysdigits0-9andaskstheuserforanumberN.ItthenreversesthefirstNnumbersofthesequence.Itcontinuesthisuntilallofthenumbersareinorder

Java-使用 BufferedReader 时将 String 转换为 int

在使用BufferedReader时如何将String转换为int?据我所知,它类似于以下内容:System.out.println("inputanumber");intn=Integer.parseInt(br.readLine(System.in));但由于某种原因,它不起作用。错误信息说:没有找到适合readLine(java.io.InputStream)的方法它还说br.readLine不适用 最佳答案 需要在BufferedReader的构造函数中指定一个InputStreamReader。InputStreamRea

java - PreparedStatement : How to insert data into multiple tables using JDBC

有人能告诉我以下JDBC代码中是否需要第一个stmt.close();来针对两个不同的表执行两个不同的SQL查询吗?publicclassMyService{privateConnectionconnection=null;publicvoidsave(Bookbook){try{Class.forName("com.mysql.jdbc.Driver");connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","password");PreparedStatementstmt=c

java - 如何在int中添加空格?

假设我要打印数字100000000。乍一看很难说出这个数字代表多少百万。是1000万还是1亿?如何使Java中的大数字看起来更具可读性?例如这样的东西会很棒:100000000。你一眼就能看出这个数字是1亿。 最佳答案 你也可以试试DecimalFormat;DecimalFormatformatter=newDecimalFormat("#,###");System.out.println(formatter.format(100000));结果:1000>>1,00010000>>10,000100000>>100,000100

Java:charAt 转换为 int?

我想输入我的nirc号码,例如S1234567I然后将1234567单独作为一个整数作为indiv1作为charAt(1),indiv2为charAt(2),indiv为charAt(3)等。但是,当我使用下面的代码时,我可以似乎连第一个数字都没有?有什么想法吗?Scannerconsole=newScanner(System.in);System.out.println("EnteryourNRICnumber:");Stringnric=console.nextLine();intindiv1=nric.charAt(1);System.out.println(indiv1);

java - 为什么 (int)(14/13 - 0.001) 产生 0 而不是 1?

如果将像1.0012这样的float转换为整数,它不是会变成1吗?那为什么我写的时候是:(int)(14/13-0.001)不是1.07592~变成1它变成了0?(用Eclipse编译的Java)。 最佳答案 它会截断。对于1.0012,它只是删除了小数点右边的部分。例子(int)(14/13-0.001)14/13会变成1然后转成double,1.0-0.001=0.999,截断后变成0。 关于java-为什么(int)(14/13-0.001)产生0而不是1?,我们在StackOve

java - Spring Data - 从表中获取最后一条记录

这个问题在这里已经有了答案:GetlastrecordsorderedbydateonSpringData(2个答案)关闭4年前。我正在使用SpringDataJPA,我想从Settings表中检索最后一条记录。我有SettingsRepository以及由SpringData实现的标准方法。如何编写方法(或查询)从给定表中检索最后一行?interfaceSettingsRepositoryextendsJpaRepository{//?}

java - 在 int 属性上按降序对自定义对象数组进行排序

我想按出生年份降序排列我的数组。我的数组还有两个其他类型的String元素。因此,例如,出生在最早年份(例如1939年)的人将排在首位,然后依此类推。这是我的代码:importjava.util.*;publicclassStudentInformationTest{publicstaticvoidmain(String[]args){StudentInformation[]studentInfo=newStudentInformation[10];studentInfo[0]=newStudentInformation("StudentA",1971,"BScFDIT");stude

java - 如何在 Java 中返回一个临时的 int 数组

这个问题在这里已经有了答案:Arrayinitializationsyntaxwhennotinadeclaration(4个答案)关闭6年前。我如何设法在Java中返回一个临时数组(为了节省代码行,而不创建变量)。做印心的时候,我可以用int[]ret={0,1};返回时无法使用return{0,1};我是否遗漏了什么或者是否有强制打字来做到这一点?我想到了使用newint[]作为下面的答案。然而,我们在启动时不需要newint[]的原因是什么?