标签:ext odi encoding val enc struts auto .hbm.xml drive
create database crm; use crm; /* SQLyog v10.2 MySQL - 5.1.72-community : Database - crm_hibernate ********************************************************************* */ /*!40101 SET NAMES utf8 */; /*!40101 SET SQL_MODE=‘‘*/; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; /*Table structure for table `sys_user` */ CREATE TABLE `sys_user` ( `user_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT ‘用户id‘, `user_code` varchar(32) NOT NULL COMMENT ‘用户账号‘, `user_name` varchar(64) NOT NULL COMMENT ‘用户名称‘, `user_password` varchar(32) NOT NULL COMMENT ‘用户密码‘, `user_state` char(1) NOT NULL COMMENT ‘1:正常,0:暂停‘, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; /*Data for the table `sys_user` */ LOCK TABLES `sys_user` WRITE; insert into `sys_user`(`user_id`,`user_code`,`user_name`,`user_password`,`user_state`) values (5,‘m0003‘,‘小军‘,‘123‘,‘1‘),(6,‘m0001‘,‘小红‘,‘123‘,‘1‘),(7,‘m0001‘,‘小明‘,‘123‘,‘1‘),(8,‘m0001‘,‘小红‘,‘123‘,‘1‘); UNLOCK TABLES; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
package com.louis.domain; public class User { // 主键 private Long user_id; // 登录名称 private String user_code; // 用户姓名 private String user_name; // 密码(保存的时候,需要加密处理) private String user_password; // 用户的状态 1正常 0暂停 private String user_state; public Long getUser_id() { return user_id; } public void setUser_id(Long user_id) { this.user_id = user_id; } public String getUser_code() { return user_code; } public void setUser_code(String user_code) { this.user_code = user_code; } public String getUser_name() { return user_name; } public void setUser_name(String user_name) { this.user_name = user_name; } public String getUser_password() { return user_password; } public void setUser_password(String user_password) { this.user_password = user_password; } public String getUser_state() { return user_state; } public void setUser_state(String user_state) { this.user_state = user_state; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.louis.domain.User" table="sys_user"> <id name="user_id" column="user_id"> <generator class="native"/> </id> <property name="user_code" column="user_code"/> <property name="user_name" column="user_name"/> <property name="user_password" column="user_password"/> <property name="user_state" column="user_state"/> </class> </hibernate-mapping>
<!-- 引入映射的配置文件 --> <property name="mappingResources"> <list> <value>com/louis/domain/User.hbm.xml</value> </list> </property>
package com.louis.web.action; import com.louis.domain.User; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class UserAction extends ActionSupport implements ModelDriven<User> { private static final long serialVersionUID = -3413092622818913571L; private User user = new User(); public User getModel() { return user; } }
<!-- 配置用户的模块 -->
<bean id="userAction" class="com.louis.web.action.UserAction" scope="prototype">
</bean>
<!-- 配置用户的模块 -->
<action name="user_*" class="userAction" method="{1}">
<result name="loginOK" type="redirect">/index.jsp</result>
</action>
package com.louis.service.impl; import org.springframework.transaction.annotation.Transactional; import com.louis.service.UserService; @Transactional public class UserServiceImpl implements UserService { }
<bean id="userService" class="com.louis.service.UserServiceImpl">
</bean>
private UserService userService; public void setUserService(UserService userService) { this.userService = userService; }
<!-- 配置用户的模块 -->
<bean id="userAction" class="com.louis.web.action.UserAction" scope="prototype">
<property name="userService" ref="userService"/>
</bean>
package com.louis.dao.impl; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.louis.dao.UserDao; public class UserDaoImpl extends HibernateDaoSupport implements UserDao { }
<bean id="userDao" class="com.louis.dao.UserDaoImpl">
</bean>
<bean id="userService" class="com.louis.service.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
private UserDao userDao; public void setUserDao(UserDao userDao) { this.userDao = userDao; }
<bean id="userDao" class="com.louis.dao.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
scope="prototype"
配置文件
ModelDriven
HibernateDaoSupport
标签:ext odi encoding val enc struts auto .hbm.xml drive
原文地址:http://www.cnblogs.com/Michael2397/p/7697768.html