小编Don*_*oby的帖子

将null插入char(1)

我正在创建一个INSERT脚本,我遇到了一个问题.有一个中间的初始字段是char(1)

有时记录在该字段中没有任何内容,所以我放了一个NULL.这会导致数据太长而不会出现列错误.我不想只是把''留下空白.

还有另一种方法吗?

mysql null insert

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

wicket ModalWindow错误

我是wicket的新手,当我尝试运行我的应用程序时,他遇到错误:

WicketMessage:模态窗口内容id错误.组件ID:myPanel; 内容ID:内容:

在我的AddStudent html中:

<span wicket:id="InformationDialog"/>
<span wicket:id="myPanel"/>
Run Code Online (Sandbox Code Playgroud)

这是我打开标签后的第一件事

在AddStudent.java中(在构造函数中):

panel=new InformationPanel("myPanel");
message=new ModalWindow("InformationDialog");
message.setContent(panel);
message.setCssClassName(ModalWindow.CSS_CLASS_BLUE);
message.setTitle("Important Information");
Run Code Online (Sandbox Code Playgroud)

InformationPanel扩展Panel的位置:

<html>
<wicket:panel>
<table>
<tr>
<td><span wicket:id="message"/></td>
</tr>
<tr>
<td><input type ="button" value ="OK" wicket:id="ok"/></td>
</tr>
</table>
</wicket:panel>
<html>
Run Code Online (Sandbox Code Playgroud)

显然,我有一个相应的java类 - 它可能没有关系,但在这里它是:

package myapp.project;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.panel.Panel;

public class InformationPanel extends Panel {
    private Button ok;
    private Label messageLabel;
    public InformationPanel(String id){
        super(id);
        messageLabel=new Label("message","");
        ok=new Button("ok"){
            public void onSubmit(){
                AddStudent student = new AddStudent();
                setResponsePage(student);
            }
        }; …
Run Code Online (Sandbox Code Playgroud)

java wicket

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

按行平均而不考虑负值

我需要计算我的数据集的单个单位的变量之间的平均值.但是,在这样做的时候,我需要不考虑一些价值观.为了更好地解释,想想有两个单元和三个变量:

      V1    V2     V3
[1]   3     -2      4
[2]  -1      4      1
Run Code Online (Sandbox Code Playgroud)

并且您想要按行计算平均值,而不考虑这些负值:

=> mean(1row)=(3 + 4)/ 2

=> mean(2row)=(4 + 1)/ 2

有谁能请给我命令在R?

非常感谢

average r selection

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

我如何使用thenReturn for Class?

这是一个非常新手的问题,但我不知道如何存根.

我必须模拟一个像这样返回Class的方法.

public Class<? extends SomeClass> getAClass();
Run Code Online (Sandbox Code Playgroud)

如果我做这样的事情

when(this.someInstance.getAClass())
    .thenReturn(SomeClassThatExtendsSomeClass.class);
Run Code Online (Sandbox Code Playgroud)

我收到编译错误.

The method thenReturn(Class<capture#1-of ? extends SomeClass>) in the type OngoingStubbing<Class<capture#1-of ? extends SomeClass>> is not applicable for the arguments (Class<SomeClassThatExtendsSomeClass>)
Run Code Online (Sandbox Code Playgroud)

java stub mockito

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

stackoverflow错误:检查数字是偶数还是奇数没有%或/运算符

//检查数字是偶数还是奇数没有/或%运算符.

public class EvenOrOdd {

    public static int CheckEvenOrOdd(int num) {
        if (num > 2) {
            int number = num - 2;
            num = CheckEvenOrOdd(number);
        }
        return num;
    }

    public static void main(String[] args) {
        int num = CheckEvenOrOdd(5322221);
        if (num == 1) {
            System.out.println("Odd number");
        } else {
            System.out.println("Even number");
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

我将堆栈大小定义为200m为-xss200m,但如果number大于5322221,则此程序会出现OutOfMemory错误和StackOverflow错误.

建议如何解决这个问题,找到数字是偶数还是奇数.

java

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

对HashSet进行排序

我编写了一个程序来在HashSet中插入数据......这里是代码

public class Person implements Comparable<Person>
{
    private int person_id;
    private String person_name;
    public Person(int person_id,String person_name)
    {
        this.person_id=person_id;
        this.person_name=person_name;
    }
    /* getter and setter method */
    public boolean equals(Object obj)
    {
        Person p=(Person)obj;
        if(!(p instanceof Person))
        {
            return false;
        }
        else if(this.person_id==p.person_id)
            return true;
        else
            return false;
    }
    @Override
    public int hashCode()
    {
        return person_id*6;
    }
    @Override
    public int compareTo(Person o)
    {
        if(this.person_id>o.person_id)
            return 1 ;
        else if(this.person_id<o.person_id)
            return -1;
        else return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我还没有粘贴其他两个类.我在这些类中所做的就是填充数据而其他类是主类.

现在我明白了,通过Java Doc Api我知道在Collections类中有一个名为sort()的方法.现在我的问题就是那个排序mathod的列表. …

java sorting

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

Junit 和 Jmock 来测试 Springs TransactionSynchronizationManager

我有一些使用事务同步管理器的代码..但我似乎无法让它在模拟中工作..我在模拟实体管理器和事务管理器..这样我的上下文保存实体并调用提交...... TransactionSynchronizationManager 确实如此似乎没有被击中……在测试中?

   this.transactionTemplate.execute(new TransactionCallback<E>() {
                @Override
                public E doInTransaction(TransactionStatus status) {    
                    // update entities


                    TransactionSynchronizationManager.registerSynchronization(new NotificationTransactionSynchronization(){
                       @Override
                       public void afterCommit() {
                    // do some post commit work
                                   int i = notifier.notifyAllListeners();
                       }
                    });

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

我的测试课:

@Test
public void testHappyPath() {


    context.checking(new Expectations() {
        {
            allowing(platformTransactionManager).getTransaction(definition);
            will((returnValue(status)));

            oneOf(platformTransactionManager).commit(status);

                         //next line never gets hit... so the test fails...
                         //if i remove it will pass but i need to check that it works...

            oneOf(mockNotifier).notifyAllListeners();

        }
    });
    this.TestClass.process();
    context.assertIsSatisfied();            
}   
Run Code Online (Sandbox Code Playgroud)

java spring jmock

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

如何将ComboBox.SelectedItem()转换为int?

我尝试将ComboBox.SelectedItem()转换为int,但无法正常工作。我知道ComboBox.SelectedItem()的类型为String,我像这样强制转换:

 int idprovider = ((Integer)IdProviderComboBox.getSelectedItem()).intValue();
Run Code Online (Sandbox Code Playgroud)

但我收到错误:java.lang.ClassCastException:java.lang.String无法转换为java.lang.Integer

也许有人有一个主意。谢谢!

java casting

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

当ResultSet关闭时,Statement会发生什么?

结果集关闭时语句会发生什么?

    Statement stmt = null;
    ResultSet rs = null;

    try {
        stmt = con.createStatement();
        rs = stmt.executeQuery(query.toString());
        ...
    }

    // lots of code

    rs.close()
Run Code Online (Sandbox Code Playgroud)

注意:当Statement对象关闭,重新执行或用于从多个结果序列中检索下一个结果时,Statement对象会自动关闭该对象.

但是当ResultSet首先关闭时会发生什么?

对于什么问题,首先应该发生什么?

java jdbc

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

这两种方法有什么区别?JAVA

我的教授为我提供了一系列方法来填写罗马数字程序(加法格式,所以4 = IIII,9 = VIIII等)

我无法理解这两种方法之间的区别:

   **
   * This method prints, to the standard output and in purely additive
   * notation, the Roman numeral corresponding to a natural number.
   * If the input value is 0, nothing is printed. This
   * method must call the method romanDigitChar(). 
   * @param val   ?
   */

    public void printRomanNumeral(int val)
    {

    }

   **
   * This method returns the Roman numeral digit corresponding
   * to an integer value. You must use a nested-if statement.
   * …
Run Code Online (Sandbox Code Playgroud)

java methods roman-numerals

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

标签 统计

java ×8

average ×1

casting ×1

insert ×1

jdbc ×1

jmock ×1

methods ×1

mockito ×1

mysql ×1

null ×1

r ×1

roman-numerals ×1

selection ×1

sorting ×1

spring ×1

stub ×1

wicket ×1