嗯,是过滤,在这个里面实现了些什么?
这个问题太大
了,而且这是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;