我创建了一个简单的表,如下所示.
CREATE TABLE CUSTOMERS
(
CUST_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
CUSTOMER_NAME VARCHAR(24) NOT NULL,
REGION VARCHAR(26),
PRIMARY KEY (CUST_ID)
);
Run Code Online (Sandbox Code Playgroud)
然后我用这个映射文件为这个表创建了一个映射
<class name="Customer" table="CUSTOMERS">
<id type="int" column="CUST_ID" >
<generator class="native"></generator>
</id>
<property name="customerName" type="string" column="CUSTOMER_NAME" />
<property name="region" type="string" column="REGION"/>
</class>
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个像下面这样的简单类来访问db.
public class CustomerDao {
public void addCustomer(Customer customer) {
Session session = SessionManager.getSessionFactory()
.getCurrentSession();
session.beginTransaction();
session.saveOrUpdate(customer);
session.getTransaction().commit();
}
public List<Customer> getAllCustomer() {
Session session = SessionManager.getSessionFactory()
.getCurrentSession();
session.beginTransaction();
List<Customer> …Run Code Online (Sandbox Code Playgroud) 我不确定为什么我的实体类不会创建我需要的表模式
@Entity
@Table(name = "User")
public class User implements Serializable {
private Long id;
private String loginName;
@Id
@GeneratedValue
public Long getId() {
return id;
}
@Column(name = "login_name", unique = true)
public String getLoginName() {
return loginName;
}
//other setters
}
Run Code Online (Sandbox Code Playgroud)
当我使用Schema导出时.
new SchemaExport(config).create(true, true);
Run Code Online (Sandbox Code Playgroud)
它创建此SQL,但它不会向我的login_name字段添加任何唯一约束.
drop table User
create table User (id bigint generated by default as identity, login_name varchar(255)primary key (id))
Run Code Online (Sandbox Code Playgroud)
我正在使用Apache Derby,我检查了Derby的参考手册,它确实支持列上的Unique约束.我尝试在类上添加uniqueconstraint注释,但结果是一样的.
任何的想法?
我正在尝试使用 Jersey 1.X 版本连接到安全的外部休息服务。
我使用了以下代码
public class MyRestClient
{
private static final String API_USER_NAME = "some value";
private static final String API_PASSWORD = "some value";
private static final String REST_URL = "https://<somevalue>";
public static void main(String[] args)
{
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new HTTPBasicAuthFilter(API_USER_NAME, API_PASSWORD));
WebResource webResource =
client.resource(UriBuilder.fromUri(REST_URL).build());
ClientResponse response = webResource.post(ClientResponse.class);
System.out.println(response);
}
}
Run Code Online (Sandbox Code Playgroud)
但我一直打这个例外..
com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching 'somevalue' found
Run Code Online (Sandbox Code Playgroud)
我检查了这个外部休息服务的 API,它说它支持基本 HTTP 身份验证,但我不知道为什么我一直遇到这个错误。
有什么想法吗?
刚开始学习Linux Bash Shell编程,我只是不知道我是否理解正确.看下面的示例程序:
#!/bin/bash
n=1
sumRSS=1000
sumSZ=2000
echo Before sumRSS=$sumRSS sumSZ=$sumSZ
ps -ly | while
read c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
do
if (( n>1 ))
then
echo n=$n rss=$sumRSS sz=$sumSZ
((sumRSS = sumRSS + c8))
((sumSZ = sumSZ + c9))
fi
((n++))
done
echo Sum of RSS = $sumRSS
echo Sum of SZ = $sumSZ
Run Code Online (Sandbox Code Playgroud)
输出:
Before sumRSS=1000 sumSZ=2000
n=2 rss=1000 sz=2000
n=3 rss=2368 sz=29118
n=4 rss=3792 sz=55644
n=5 rss=4780 sz=82679
Sum of RSS …Run Code Online (Sandbox Code Playgroud) 我使用以下代码过滤具有以下扩展名的文件
FileFilter fileFilter= new WildcardFileFilter("*.docx");
File[] sampleFiles= filesDirectory.listFiles(fileFilter);
Run Code Online (Sandbox Code Playgroud)
但是,如果我想要相反的情况,我想排除具有此扩展名的文件。目前我有以下代码
public class FileFilter {
public static void main(String[] args) {
File dir = new File("C:\\temp\\filter-exclude");
File[] files = dir.listFiles(new ExcludeFilter());
for (File f : files) {
System.out.println("file: " + f.getName());
}
}
public static class ExcludeFilter implements java.io.FileFilter {
@Override
public boolean accept(File file) {
if (file.getName().toLowerCase().endsWith("docx")) {
return false;
}
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但不确定是否已经有这方面的课程。有这样的课吗?
我正在将我的控制器转换为spring mvc中带注释的样式控制器.
基本上我在旧式控制器simpleformcontroller中这样做.
protected Map referenceData(HttpServletRequest request) throws Exception
{
Map referenceData = new HashMap();
List<ItemVo> lstItem1 = eqrManager
.searchAllEqptCondQualItems("A1", "BOXES");
List<ItemVo> lstItem2 = eqrManager
.searchAllEqptFullQualItems("A2", "CANNED_GOODS");
referenceData.put("BOX_ITEMS", lstItem1);
referenceData.put("CANNED_ITEMS", lstItem2);
return referenceData;
}
Run Code Online (Sandbox Code Playgroud)
在注释中,我做了这样的事情:
@ModelAttribute("BOX_ITEMS")
public List<ItemVo> populateCondEQRItems() {
List<ItemVo> lstCondQual = eqrManager
.searchAllEqptCondQualItems("A1", "BOXES");
return lstCondQual;
}
@ModelAttribute("CANNED_ITEMS")
public List<ItemVo> populateFullEQRItems() {
List<ItemVo> lstFullQual = eqrManager
.searchAllEqptFullQualItems("A2", "CANNED_GOODS");
return lstFullQual;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法只在一个方法中返回所有属性而不必创建多个@ModelAttribute?在我的情况下,我需要注释2方法?如果我需要3,我应该创建3个带注释的方法吗?
我一直在阅读Hibernate核心,我仍在探索它的一些功能.
在文档中提到SessionFactory是Hibernate的重量级组件,因此它应该只在Web应用程序和单例中设置一次.每个Session工厂都应该属于一个JDBC连接.
有谁知道如何在tomcat Web应用程序中正确设置会话工厂?任何链接或教程都会更好.
我应该将它设置为contextlistener类吗?
谢谢.
如何卸载Glassfish Application Server?
我在安装时犯了一个错误,我想更改Glassfish安装目录.
我只是在安装过程中遵循以下顺序.
它从文件中说我从网上看到有一个uninstall.exe选项,但我似乎找到了一个.
我正在尝试使用glassfish和eclipse进行Primefaces 3.
我想在创建或输入用户详细信息时使用Primefaces Dialog.例如,假设在一个页面中,我有一个Create按钮,单击该按钮会显示该对话框.
<p:dialog id="dialog" widgetVar="dlg1">
<h:form id="addMemberForm">
<!-- More code here -->
<f:facet name="footer">
<p:commandButton value="Save"
actionListener="#{myBean.save}"
oncomplete="dlg1.hide()" />
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
..单击我的保存按钮时,执行此代码.
public class MyBean{
public void save(ActionEvent event) {
try{
myEJB.addMember(newMember);
//how to show message
}catch(Exception e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
添加成功后,如何向用户显示对话框弹出消息.
我尝试使用此代码,但这不显示,对话框被解除.
FacesMessage facesMessage = new FacesMessage("Successful add!");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
Run Code Online (Sandbox Code Playgroud)
我以为这是一个ajax提交所以一切都被清除了.
我想我必须在oncomplete期间执行一些代码,但我不知道该怎么做?
我不确定有什么区别,但这样做是有效的:
<div class="clearfix"></div>
Run Code Online (Sandbox Code Playgroud)
但不是这个。
<div class="clearfix"/>
Run Code Online (Sandbox Code Playgroud)
不确定bootstrap中是否有关于完整HTML标记和快捷HTML标记的规则。在 Bootstrap 中我需要完整输入 HTML 吗?
我创建了一个WSDL,我想利用AXIS 2作为我的Web服务器.
我将它下载到我的C:\ axis2-1.6.1并设置了所有必需的安装参数.
我的问题是,我将*.aar文件部署到repository/services文件夹中,并且axis2server能够对其进行解压缩,当我导航到我时,我看到了我的Web服务
当我使用SOAPUI测试我的服务时,我只收到此错误.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>unknown</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
不确定,但我没有在Axis控制台上看到任何错误?
我在哪里可以找到任何相关信息来解决这个问题?
我在我的JSF应用程序中使用了以下注销算法,因为用户能够注销并终止会话.
但是,我的问题是,即使用户被重定向到登录页面,但当他/她按下浏览器后退按钮时,他仍然能够看到以前的数据.
@ManagedBean
@RequestScoped
public class LogoutBean {
public String logout() {
String result="/faces/pages/public/login.xhtml?faces-redirect=true";
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
try {
request.logout();
} catch (ServletException e) {
log.info("Error during logout!");
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法以浏览器使用上面的逻辑显示页面已过期的方式配置它.
我不是Java正则表达式的专家,但我似乎找不到任何链接可以告诉我这个正则表达式模式的含义.
([^.@]+)
Run Code Online (Sandbox Code Playgroud)
这个正则表达式模式描述了什么?
谢谢