为了提高我的clique-partitioning程序(使用有序数组)的性能,我在for
循环的stop条件中包含了对我循环的数组元素的访问.
int myValue = 13;
for (int i=0; array[i] < myValue; i++)
{
//performing operations on the array
}
Run Code Online (Sandbox Code Playgroud)
这显然是不安全的,因为可能是我的数组只包含小于的值myValue
,所以我尝试了这个
int myValue = 13;
for (int i=0; i < array.size() && array[i] < myValue; i++)
{
//performing operations on the array
}
Run Code Online (Sandbox Code Playgroud)
在这个实现中,一切似乎都顺利,但如果我切换条件,我会遇到第一个例子的同样问题.
int myValue = 13;
for (int i=0; array[i] < myValue && i < array.size(); i++)
{
//performing operations on the array
}
Run Code Online (Sandbox Code Playgroud)
因此,我推断这显然是由于编译器设置两个条件的顺序的方式,因为在最后一种情况下,即使我要求仅在i
不大于数组大小的情况下进入循环,我' m之前读取的值可能超出了数组的范围.
我的问题是:它是否像我在第二个实现中一样安全,或者编译器有时会切换我的控制条件导致不安全的代码?
谢谢.
我正在使用Spring工具套件处理弹簧MVC项目和弹簧数据,我想将日期参数传递给本机查询,到目前为止我已经这样做了.
我的查询方法在扩展JpaRepository的接口中
@Query(value =
"SELECT "
+ "a.name, a.lastname
+ "FROM "
+ "person a, "
+ "myTable b "
+ "WHERE "
+ "a.name= ?1' "
+ "AND a.birthday = ?2 ",
nativeQuery = true)
public ArrayList<Object> personInfo(String name, String dateBirthDay);
Run Code Online (Sandbox Code Playgroud)
实现此接口定义的方法:
public ArrayList<Object> getPersonsList(String name, String dateBirthDay) {
ArrayList<Object> results= null;
results= serviceAutowiredVariable.personInfo(name, dateBirthDay);
return results;
}
Run Code Online (Sandbox Code Playgroud)
这就是我从控制器类中调用它的方式.
personsList= _serviceAutowiredVariable.getPersonsList("Jack", "TO_DATE('01-08-2013', 'DD-MM-YYYY')" );
Run Code Online (Sandbox Code Playgroud)
我想在这一行中"AND a.birthday = ?2 "
,?2
is等于这个字符串TO_DATE('01-08-2013', 'DD-MM-YYYY')
但是当我运行我的代码时,我收到此错误
[Request processing failed; …
Run Code Online (Sandbox Code Playgroud) 我有一个使用 hibernate 的带有 JPA 的 Maven 项目。
我必须指定一个 jar 文件来加载外部类,persistence.xml
位于src/main/resources/META-INF
<persistence unit name="PersistenceUnit" transaction-type="JTA"
...
<jar-file>lib/${project.persistencejar}.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)
使用 Maven 过滤(文件名可以根据各种 Maven 设置进行更改)。然后我指示 Maven 通过包含在pom.xml
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>META-INF/persistence.xml</include>
</includes>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
跑步mvn clean install
会产生可展开且工作的耳朵。
问题是:如果我在 Eclipse 项目配置中启用 JPA Facet,Eclipse 会抱怨
Multiple annotations found at this line:
- JAR file "lib/${project.persistencejar}.jar" cannot be resolved
- The path to the JAR file will vary on your runtime environment. Please make sure the
specified path fits …
Run Code Online (Sandbox Code Playgroud) arrays ×1
c++ ×1
filtering ×1
jar ×1
java ×1
jpa ×1
loops ×1
maven ×1
persistence ×1
spring ×1
spring-data ×1
spring-mvc ×1
standards ×1