小编Vis*_*uth的帖子

在Java中继承静态变量

我想要进行以下设置:

abstract class Parent {
    public static String ACONSTANT; // I'd use abstract here if it was allowed

    // Other stuff follows
}

class Child extends Parent {
    public static String ACONSTANT = "some value";

    // etc
}
Run Code Online (Sandbox Code Playgroud)

这在Java中可行吗?怎么样?如果我可以避免它,我宁愿不使用实例变量/方法.

谢谢!

编辑:

常量是数据库表的名称.每个子对象都是一个迷你ORM.

java polymorphism inheritance static static-variables

4
推荐指数
1
解决办法
8126
查看次数

有没有办法检测电子邮件地址是否属于现有帐户?

有一种方法可以检测电子邮件 ID 的格式是否正确。示例abcqs@def.com是格式正确的电子邮件地址,但这可能是也可能不是有效的电子邮件帐户。

  • 情况 1可能是该域不存在(例如def.com此处)。
  • 情况 2如果域有效,则该域的 id 可能不存在(例如 def 域不存在 abcqs 用户名)。

如果无效,那么如果我们发送邮件,我们可能会在发送电子邮件后的几个小时内收到一些投递失败的邮件。

我想实现一个类似的概念。我想验证一个电子邮件ID是否属于一个有效的帐户,这将查明该帐户是否存在。

如何实现?

java email email-verification

3
推荐指数
1
解决办法
2031
查看次数

Statement中的executeUpdate(String,int)方法始终返回1

任何人都可以告诉我为什么executeUpdate即使我已经指定返回生成的密钥,下面的方法()总是返回1?我想在generatedKey变量中获取生成的键.它适用于PreparedStatement使用getGeneratedKeys,但我想这样做Statement.

    public int testQuery(Connection con) {

        int generatedKey = 0;

        try {

            Statement statement = con.createStatement();
            generatedKey = statement.executeUpdate("INSERT INTO profile (fullname) VALUES ('Visruth CV')", Statement.RETURN_GENERATED_KEYS);

        } catch (SQLException e) {          
            e.printStackTrace();
        } finally {
           try { 
               con.close();
           } catch(Exception ex) {
               ex.printStackTrace();
           }
        }
        System.out.println("generated key : "+generatedKey);

        return generatedKey;
    }
Run Code Online (Sandbox Code Playgroud)

根据文档executeUpdate(String sql, int autoGeneratedKeys),它说:

Executes the given SQL statement and signals the driver with the given …
Run Code Online (Sandbox Code Playgroud)

java mysql jdbc

3
推荐指数
1
解决办法
4857
查看次数

简单的Spring EL表达式不起作用; 错误TypeMismatchException

我在application-context.xml中有以下简单表达式:

<bean id="instrument" class="com.ustunozgur.Instrument" init-method="initialize" scope="prototype">
<property name="age" value="#{4}"/>
<property name="name" value="Violin"/>
Run Code Online (Sandbox Code Playgroud)

Instrument类是一个简单的POJO.但是,它抛出以下错误:

[ERROR] ...nested exception is org.springframework.beans.TypeMismatchException: 
Failed     to convert property value of type 'java.lang.String' to required type
'int'   for      property 'age'; nested exception is java.lang.NumberFormatException: For input string:
"{4}" -> 
Run Code Online (Sandbox Code Playgroud)

这是我的xml中的初始bean声明:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?我在我的pom.xml中包含了spring-core,spring-expression,spring-context.我没有通过代码进行任何配置; 所有配置都是通过xml完成​​的.

PS:这是一个命令行应用程序,它可能是罪魁祸首吗?

PPS:以下代码有效,因此似乎只忽略XML中的spel:

  ExpressionParser parser = new SpelExpressionParser();
  Expression exp = parser.parseExpression("'Hello World'");
  String message = (String) exp.getValue();
Run Code Online (Sandbox Code Playgroud)

这是我的完整application-context.xml和pom.xml:http://paste.pocoo.org/show/494260/http://paste.pocoo.org/show/494262/

java spring exception spring-el

2
推荐指数
1
解决办法
2722
查看次数

"我们在java中改变运行时任何对象的行为"是什么意思

我正在阅读Orielly Design模式,并且有一行" We can change the Behavior of any object at runtime"以及如何使用getter和setter在运行时更改对象的行为.

java runtime

2
推荐指数
1
解决办法
1943
查看次数

Java Set.contains(o)与List.get(索引)时间复杂度

我正在创建一个股票应用程序,我可以在购买特定股票时保存指数的历史记录.目前我正在使用a HashSet<Integer>来保存这些值(范围0-270).

在程序中,有很多查找使用的历史记录Set.contains(o),即O(1).

我正在考虑将此历史更改为a ArrayList<Boolean>,其中trueat指数0表示指数0处有买入,false指数1表示指数1处没有买入,等等...

这样,我可以做一个List.get(index),这也是O(1),但我猜测会稍快一点,因为HashSet查找的基本性质.

但由于指数的范围很小,我不确定我的假设是否成立.

所以如果我不关心空间复杂性,哪种方法会更快?

java performance list set time-complexity

2
推荐指数
1
解决办法
970
查看次数

如何在单击"清除"按钮时删除Jquery验证错误消息

编辑用户和清除用户是单独的按钮.

那么如何使用以下语句validator.resetForm()清除单击Clear Button时的错误消息; ?

function clearUser(){ 
       // Need to clear previous errors here 
} 


function editUser(){     
    var validator = $("#editUserForm").validate({ 
            rules: {                             
                userName: "required" 
        },  
        errorElement: "span" ,                
        messages: { 
          userName: errorMessages.E2 
        } 
      }); 

     if(validator.form()){  
        // form submition code 

    } 
} 
Run Code Online (Sandbox Code Playgroud)

jquery jquery-validate jqueryform

1
推荐指数
1
解决办法
1万
查看次数

使用Java Spring 3.0 @NumberFormat注释

我目前正在开发一个小型项目,试图让Java spring验证在Web表单上运行.它确实有效,但是我有一个用于输入年龄的输入,然后我使用这个注释转换为数字格式,如果我输入字母,它会在提交表单时将其显示在输入框旁边:

"无法将类型为java.lang.String的属性值转换为属性所需的类型java.lang.Integer;嵌套异常为org.springframework.core.convert.ConversionFailedException:无法从类型java.lang转换值"dasdf" .string类型为java.lang.Integer;嵌套异常是java.lang.IllegalArgumentException:无法解析dasdf"

有没有办法改变这个消息,我确信它很简单,但已经搜索过,找不到它.

这是目前的验证码:

@NotNull
@NumberFormat(style = Style.NUMBER)
@Min(1)        
@Max(110)        
private Integer age;
Run Code Online (Sandbox Code Playgroud)

干杯,大卫

java spring spring-annotations number-formatting spring-3

1
推荐指数
1
解决办法
6723
查看次数

在Java中嵌套while循环

我在java程序中遇到了一些嵌套的while循环问题.从我调试的代码开始,我的代码会检查第二个while循环语句,然后永远退出循环.我不知道为什么会发生这种情况所以我会在这里发布代码:

while (current != null) {
        if(id == current.getMovie().getId()) {
           movieExists = true;
           movie = current;
           while (checkCurrent == movie) {
              showingPointer = checkCurrent.getMovie().getLinkHead();
              while (showingPointer != null) {
                 if (cal.compareTo(showingPointer.getShowing().getShowingCalendar()) == 0) {
                    return false;
                 }
                 showingPointer = showingPointer.getNext();
              }
              checkCurrent = checkCurrent.getNext();       
           }        
        }
        current = current.getNext();
     }
Run Code Online (Sandbox Code Playgroud)

java loops while-loop nested-loops

1
推荐指数
1
解决办法
807
查看次数

GWTTestCase - 未找到测试

我正在eclipse juno中运行1.7.5尝试设置junit测试.我从juno插件文件夹中添加了junit jar.我为junit 4设置了选项.

我创建了一个新的get项目'MyJunitProject',并在客户端'MyFirstGWTTestCase'下创建了一个类.这是代码.

package com.client;

import org.junit.Test;

import com.google.gwt.junit.client.GWTTestCase;

 public class MyFirstGWTTestCase extends GWTTestCase {

@Override
public String getModuleName() {
    return "com.MyJunitProject";
}

@Test
public void myFirstTest() {
    assertTrue(true);
}

}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

junit.framework.AssertionFailedError: No tests found in com.client.MyFirstGWTTestCase
at junit.framework.Assert.fail(Assert.java:50)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Run Code Online (Sandbox Code Playgroud)

java gwt junit

1
推荐指数
1
解决办法
1483
查看次数

如果if参数在java中已经设置为true,那么为什么if的情况不会产生任何错误

当if参数为true时,为什么java程序在if else情况下不会出错.为什么不做任何例外.例如,这里method1和method2即使有无法访问的语句也不会产生任何(编译)错误,但是method3会产生编译错误.首先仔细阅读代码并提供答案.

    public int method1() {
        if(true) {
            return 1;
        } else {
            return 2;//unreachable statement but doesn't make exception
        }
    }

    public int method2() {
        if(true) {
            return 1;//unreachable statement but doesn't make exception
        } else if (true) {
           return 2;//unreachable statement but doesn't make exception
        } else {
            return 3;//unreachable statement but doesn't make exception
        }
    }

    public int method3() {

        if(true) {
            return 1;//unreachable statement but doesn't make exception
        } else if (true) {
           return 2;//unreachable statement …
Run Code Online (Sandbox Code Playgroud)

java compiler-errors compilation

0
推荐指数
1
解决办法
153
查看次数

Java版本控制

我使用docx4j来加载,操作和保存Word文件.一切都很完美,但有一件事我不知道如何实现它.我想要的是版本控制 - 这意味着如果您保存文档,则可以恢复该文档的早期版本(例如,仅保存delta).也许你可以描述它应该像SVN或Git,你可以回到你的文件的早期版本.问题是我不知道有任何可能实现这一点.所以我希望你们中的任何人都可以帮助我.如果任何人至少知道一个包或其他东西可以通常使用文件而不是特别是docx文件,那就没关系了.谢谢你的帮助!

编辑:对不起,我的问题不精确.这是我在这里的第一篇文章,将来我会改进;)

java api version-control version docx

0
推荐指数
1
解决办法
1559
查看次数

在展开可选值NSDefautlts时发现了nil的swift问题

致命错误的问题:在展开Optional值时意外发现nil.

let lastupdate = defaults.stringForKey("localdate")
self.lastUpdate.text = "Updated at " + last update! //issues when I use this line
self.lastUpdate.text = lastupdate // If use this line I have no issues.
Run Code Online (Sandbox Code Playgroud)

如果我预先填充数据,则有效.但我想允许零值.

null xcode swift xcode-6.2

0
推荐指数
1
解决办法
320
查看次数