Hibernate
hibernate.cfg.xml
文件头信息前缀的版本不同,4.0会导致jboss不能自动生成xx.hbm.xml
文件
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect 方言-->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>-->
<!-- Enable Hibernate's automatic session context management 自动上下文管理-->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache 缓存 -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout 打印sql信息到控制台-->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/hibernate?useUnicod=true&characterEncoding=utf8</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!-- <mapping resource="Student.hbm.xml"/> -->
</session-factory>
</hibernate-configuration>
Student.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2016-10-27 11:16:13 by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="Student" table="STUDENT">
<!-- 主键 -->
<id name="sid" type="int">
<column name="SID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="gender" type="java.lang.String">
<column name="GENDER" />
</property>
<property name="birthday" type="java.util.Date">
<column name="BIRTHDAY" />
</property>
<!-- <property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property> -->
<property name="picture" type="java.sql.Blob">
<column name="PICTURE" />
</property>
<!-- 组件类型 Address是一个类
private int sid;// 学号
private String name;// 姓名
private String gender;// 性别
private Date birthday;// 出生日期
private Blob picture;//照片
private Address address;-->
<component name="address" class="Address">
<property name="postcode" column="POSTCODE"></property>
<property name="phone" column="PHONE"></property>
<property name="address" column="ADDRESS"></property>
</component>
</class>
</hibernate-mapping>
Structs
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>structs2Validator</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
structs.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="user_*" method="{1}" class="action.UserAction">
<result>/index.jsp</result>
<result name="update">/index.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>
action中的方法
public String login(){
System.out.println(user.toString());
System.out.println("执行了login");
return SUCCESS;
}
public String update(){
System.out.println("执行了update");
return "update";
}