嗯,是過濾,在這個裡面實現了些什麼?
這個問題太大
了,而且這是struts2,更加復雜。在裡面做了很多事情,最起碼的
至少有載入你的struts.xml配置文件,解析你的配置文件,然後通過你的請求路徑,找到相應的action,封裝你的表單數據等等,還有很多過濾器。。。struts2不是一兩句能說完的,看看源代碼吧,如果看得懂,就知道做了什麼了
『貳』 java當中映射文件什麼意思
比如hibernate的映射文件就是資料庫中表的欄位和你的bean裡面欄位的對應關系而已
『叄』 java內存映射文件有什麼用,不理解啊
內存映射文件(memory-mapped
file)能讓你創建和修改那些大到無法讀入內存的文件。有了內存映射文件,你就可以認為文件已經全部讀進了內存,然後把它當成一個非常大的數組來訪問了。將文件的一段區域映射到內存中,比傳統的文件處理速度要快很多
『肆』 如何基於Hibernate在Java類中實現,根據資料庫表生成持久化類代碼和映射文件hbm.xml
這個就要藉助hibernate tools跟xdoclet來完成了;
首先你要在你的java代碼里應用xdoclet標簽,例如
Java code
private String name;
/**
* @hibernate.property column = "name" length = "50"
*/
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
其中,寫到javadoc上的@hibernate.property column = "name" length = "50"
就是xdoclet標簽,它需要xdoclet程序來處理,這里就需要用到hibernate tools。
具體做的話一般情況是建一個ant腳本來完成,例如:
XML code
<target name="hibernate-xdoclet" depends="init, init-xdoclet_hibernate"
description="Generate mapping documents">
<echo>+---------------------------------------------------+</echo>
<echo>| |</echo>
<echo>| R U N N I N G H I B E R N A T E D O C L E T |</echo>
<echo>| |</echo>
<echo>+---------------------------------------------------+</echo>
<delete>
<fileset dir="${hibernate.cfg.xml.dir}" includes="hibernate.cfg.xml" />
</delete>
<echo message="hibernate.cfg.xml at ${hibernate.cfg.xml.dir}"></echo>
<sleep seconds="1"/>
<hibernatedoclet
destdir="${hibernate.cfg.xml.dir}"
excludedtags="@version,@author,@todo,@see"
addedtags="@xdoclet-generated at ${TODAY},@right The XDoclet Team,@author XDoclet,@version ${version}"
force="false"
verbose="true">
<fileset dir="${src.dir}">
<include name="com/**/model/**/*.java"/>
</fileset>
<hibernatecfg
version="3.0"
destDir="${hibernate.cfg.xml.dir}"
dialect="org.hibernate.dialect.Oracle9Dialect"
driver="oracle.jdbc.driver.OracleDriver"
jdbcUrl="jdbc:oracle:thin:@localhost:1521:RESDL"
userName="test"
password="123"
showSql="true"
schema="true"
validateXML="true"
/>
<hibernate version="3.0"/>
</hibernatedoclet>
</target>
上面的代碼是生成hbm跟cfg文件的,下面再介紹如何從java類到資料庫:
XML code
<target name="hibernate-schema" depends="init, init-hibernate-schema"
description="Generate DB schema from the O/R mapping files">
<echo>+---------------------------------------------------+</echo>
<echo>| |</echo>
<echo>| R U N N I N G D B S C H E M A |</echo>
<echo>| |</echo>
<echo>+---------------------------------------------------+</echo>
<echo message="mysql.sql at etc/hbm2doc"></echo>
<sleep seconds="1"/>
<hibernatetool destdir="etc/hbm2doc">
<configuration propertyFile="${src.dir}/hibernate.properties">
<fileset dir="${hibernate.cfg.xml.dir}">
<include name="com/**/model/**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2ddl drop="true"
outputfilename="mysql.sql"/>
<hbm2doc/>
</hibernatetool>
</target>
當然ant工程里的一些初始化需要自己定義,我這里只摘錄關鍵部分,具體的東西請查閱相關文檔,hibernate tutorail里就有個例子
『伍』 Java讀取配置文件的幾種方法
在現實工作中,我們常常需要保存一些系統配置信息,大家一般都會選擇配置文件來完成,本文根據筆者工作中用到的讀取配置文件的方法小小總結一下,主要敘述的是spring讀取配置文件的方法。
一、讀取xml配置文件
(一)新建一個java bean
package chb.demo.vo;
public class HelloBean {
private String helloWorld;
public String getHelloWorld() {
return helloWorld;
}
public void setHelloWorld(String helloWorld) {
this.helloWorld = helloWorld;
}
}
(二)構造一個配置文件
?xml version="1.0" encoding="UTF-8"?
!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" ""
beans
bean id="helloBean" class="chb.demo.vo.HelloBean"
property name="helloWorld"
valueHello!chb!/value
/property
/bean
/beans
(三)讀取xml文件
1.利用
ApplicationContext context = new ("beanConfig.xml");
HelloBean helloBean = (HelloBean)context.getBean("helloBean");
System.out.println(helloBean.getHelloWorld());
2.利用FileSystemResource讀取
Resource rs = new FileSystemResource("D:/software/tomcat/webapps/springWebDemo/WEB-INF/classes/beanConfig.xml");
BeanFactory factory = new XmlBeanFactory(rs);
HelloBean helloBean = (HelloBean)factory.getBean("helloBean");
System.out.println(helloBean.getHelloWorld());
值得注意的是:利用FileSystemResource,則配置文件必須放在project直接目錄下,或者寫明絕對路徑,否則就會拋出找不到文件的異常。
二、讀取properties配置文拿鎮件
這里介紹兩種啟敬技術:利用spring讀取properties 文件和利用java.util.Properties讀取
(一)利用spring讀取properties 文件
我們還利用上面的HelloBean.java文件,構造如下beanConfig.properties文件:
helloBean.class=chb.demo.vo.HelloBean
helloBean.helloWorld=Hello!chb!
屬性文件中的"helloBean"名稱即是Bean的別名設定,.class用於指定類來消旁粗源。
然後利用org.springframework.beans.factory.support.來讀取屬性文件
BeanDefinitionRegistry reg = new DefaultListableBeanFactory();
reader = new (reg);
reader.loadBeanDefinitions(new ClassPathResource("beanConfig.properties"));
BeanFactory factory = (BeanFactory)reg;
HelloBean helloBean = (HelloBean)factory.getBean("helloBean");
System.out.println(helloBean.getHelloWorld());
(二)利用java.util.Properties讀取屬性文件
比如,我們構造一個ipConfig.properties來保存伺服器ip地址和埠,如:
ip=192.168.0.1
port=8080
則,我們可以用如下程序來獲得伺服器配置信息:
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ipConfig.properties");
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("ip:"+p.getProperty("ip")+",port:"+p.getProperty("port"));
『陸』 java相關。關於hibernate的映射文件的位置,謝謝!
hibernate.cfg.xml一般放在src目錄下,實體映射文件放在實體所在的包目錄下
『柒』 java eclipse怎樣自動生成hibernate配置映射文件
步驟如下:
1、創建資料庫,創建相應的表;
2、點擊圖標,選擇MyEclipse Datebase Explorer;