我最近有一个关于如何正确检查jQuery是否存在元素的问题.我从这里找到答案:
https://learn.jquery.com/using-jquery-core/faq/how-do-i-test-whether-an-element-exists/
综上所述:
if ( $( "#myDiv" ).length ) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
我工作的一个人说正确的检查方法应该是:
if ($( "#myDiv" ) && $( "#myDiv" ).length ) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
有关系吗?我的意思是从性能或延迟方面来说,它们是否表现相同?
也:
$( "#myDiv" ).show();
$( "#myDiv" ).hide();
$( "#myDiv" ).val('');
Run Code Online (Sandbox Code Playgroud)
在这些类型的jQuery函数中,似乎不需要if检查,因为如果#myDiv不存在则不会引发错误,对吗?
对于它的价值,我使用的是jQuery 1.6.4.
我已经使用Spring Data JPA设置了一个spring boot项目,但我没有看到Spring数据jpa的智能.

屏幕截图显示问题,我的餐厅实体有一个变量调用restaurantAddress,我试图让intelliJ帮助我完成编码,但没有智能显示.
我的项目设置如下:
申请类:
@SpringBootApplication
@ComponentScan(basePackages = {"com.mycompany"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>food</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<dependencies>
<!-- Dependencies for RESTful Web Services -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Dependencies for JPA Data Persistence -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--JDBC-->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
<build>
<finalName>food</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration> …Run Code Online (Sandbox Code Playgroud) 我正在研究一些kata,但我无法通过所有测试用例.
所以情况是:
给定任何数组,例如此数组:int[] a = {2, 3, 10, 2, 4, 8, 1},找到数组中的最大差异对,同时确保较大的值处于较高的索引而不是较低的值.
在这个例子中:10是最大的元素,1是最小的元素,因为10它在索引处2,1在索引处6,因此它不计数,因为较大的对在较低的索引处.因此,正确的答案是a[0],和a[2],最大的不同是10-2.
其他要求是数组大小N介于1和之间1_000_000,任何给定a[i]的介于-1_000_000和之间1_000_000
我写了这样的代码:
static int maxDifference(int[] a) {
//test array size
if (a.length < 1 || a.length > 1_000_000) return -1;
int[] oldArr = Arrays.copyOf(a, a.length);
Arrays.sort(a);
int max = a[a.length - 1];
if (max > 1_000_000 …Run Code Online (Sandbox Code Playgroud) 更新:这个问题正在寻求如何获得任何给定坐标的一组邻居的指导.
我创建了一个包含坐标的二维数组,
int[][] coordinates= { { -1, -1 }, { -1, 0 }, { -1, +1 },
{ 0, -1 }, { 0, +1 }, { +1, -1 }, { +1, 0 }, { +1, -1 } };
Run Code Online (Sandbox Code Playgroud)
如您所知,这些是坐标(0,0)的邻居.
现在我尝试实现一个接受两个参数的方法(int positionX, int positionY),并使用输入参数值coordiante(x,y)作为起始坐标并找到该坐标的所有邻居.
我在考虑这样的事情:
int getNearCoordinates(int positionX, int positionY) {
for (int[] coordinate: coordinates) {
//I am not sure what to do after this
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用一个循环从我创建的2d数组获取单个坐标,我被困在这里.我如何找到一种方法来正确找到positionX和positionY的邻居?
什么是邻居?
如果:
interface I{}
class A implements I{}
class B extends A{}
class C extends B{}
A a = new A();
B b = new B();
Why a = (B)(I)b; is correct
but b = (B)(I)a; is false?
Run Code Online (Sandbox Code Playgroud)
我发现施法很混乱,如果我可以向下施放或向上施放物体,最好的方法是什么?
下面的代码生成输出:In long.如果我将参数更改(int...x)为(int x),则会打印出来It is int.这是为什么?
public class Sub {
void probe(int...x){
System.out.println("It is int");
}
void probe(long x){
System.out.println("In long");
}
public static void main(String[] args){
int b = 4;
new Sub().probe(b);
}
}
Run Code Online (Sandbox Code Playgroud) 请不要担心循环,但我的问题是关于这些关键字:outer,middle,和inner.他们不声明为实例变量,为什么IDE让代码编译?我在google上做了一些搜索,是这个java标签吗?Java中的某种关键字?多谢你们.
public class LoopTest{
public static void main(String[] args){
int counter = 0;
outer:
for(int i = 0; i < 3; i++){
middle:
for(int j = 0; j < 3; j++){
inner:
for(int k = 0; k < 3; k++){{
}
if(k - j > 0){
break middle;
}
counter++;
}
}
}
System.out.println(counter);
}
Run Code Online (Sandbox Code Playgroud)
}
做了一些多项选择,一个问题给出了以下数组定义,并询问哪些是有效语句:
int[] array1, array2[];
int[][] array3;
int[] array4[], array5[];
A. array2 = array3;
B. array2 = array4;
C. array1 = array2;
D. array4 = array1;
E. array5 = array3;
Run Code Online (Sandbox Code Playgroud)
正确的答案是A,B,E.为什么?我看到array3和array4是二维数组而array1,2,5不是.
编辑:我不知道为什么讨厌这个问题,但也许是因为我的问题混乱.我故意用来/*+ ORDERED */控制执行的顺序并改变FROM子句中表的顺序.我想知道为什么执行时间可以改变.是因为连接顺序吗?是因为桌子大小?希望这可以消除混乱.
所以我只是在玩SQL查询并实现以下内容:如果我在FROM子句中更改表的顺序,则执行时间可能会有很大差异.以下查询在大约0.966秒内运行.但如果我转到OrderDetails d最后一个FROM条款,执行只有0.573秒!这有什么原因吗?我当时正在使用ORACLE SQL Developer
SELECT /*+ ORDERED */
su.CompanyName, CategoryName, ProductName, c.CompanyName, c.country,
FirstName, LastName, Quantity, d.UnitPrice, sh.CompanyName
FROM
OrderDetails d, Suppliers su, Shippers sh, Categories t, Products p,
Employees e, Customers c, orders o
WHERE
t.CategoryID = p.CategoryID
AND c.CustomerID = o.CustomerID
AND e.EmployeeID = o.EmployeeID
AND o.OrderID = d.OrderID
AND p.ProductID = d.ProductID
AND sh.ShipperID = o.ShipVia
AND su.SupplierID = p.SupplierID
AND LOWER(ProductName) Like '%lager%'
AND LOWER(c.city) …Run Code Online (Sandbox Code Playgroud) java ×7
arrays ×2
algorithm ×1
autoboxing ×1
casting ×1
coordinates ×1
inheritance ×1
javascript ×1
jquery ×1
oracle ×1
polymorphism ×1
spring ×1
spring-data ×1
sql ×1