以下是 netbeans 在将 jtable 与 netbeans gui 编辑器绑定时生成的代码。
serverDetailsQuery = java.beans.Beans.isDesignTime() ? null : F1SoftSMSCPUEntityManager.createQuery("SELECT s FROM ServerDetails s ");
我通过编辑更改了查询
SELECT s FROM ServerDetails s order by id desc
这工作正常。现在我想在查询中传递参数以通过 ShortCode 过滤记录,例如:
SELECT s FROM ServerDetails s where s.shortCode : filterShortCode order by id desc
短代码是文本字段,如果用户键入短代码并单击该按钮,则有一个按钮将过滤记录。
相关代码
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
F1SoftSMSCPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("F1SoftSMSCPU").createEntityManager();
serverDetailsQuery = java.beans.Beans.isDesignTime() ? null : F1SoftSMSCPUEntityManager.createQuery("SELECT s FROM ServerDetails s order by id desc");
serverDetailsList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : serverDetailsQuery.getResultList();
jPanel1 = new javax.swing.JPanel();
serverDetailsPanel = new javax.swing.JPanel();
bindButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
bindingDetailsTable = new javax.swing.JTable();
blockButtonToBindingDetails = new javax.swing.JButton();
smscBindingDetailsFilterPanel = new javax.swing.JPanel();
filterByShortCodeTextField = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
smscBindingFilterButton = new javax.swing.JButton();
}// Variables declaration - do not modify
private javax.persistence.EntityManager F1SoftSMSCPUEntityManager;
private javax.swing.JButton bindButton;
private javax.swing.JTable bindingDetailsTable;
private javax.swing.JButton blockButtonToBindingDetails;
private javax.swing.JTextField filterByShortCodeTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private java.util.List<com.f1soft.SMSC.entities.ServerDetails> serverDetailsList;
private javax.swing.JPanel serverDetailsPanel;
private javax.persistence.Query serverDetailsQuery;
private javax.swing.JPanel smscBindingDetailsFilterPanel;
private javax.swing.JButton smscBindingFilterButton;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
感谢并愿意尽快得到专家的回复。