码迷,mamicode.com
首页 > 其他好文 > 详细

2、创建用户模板

时间:2017-10-20 10:23:37      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:ext   odi   encoding   val   enc   struts   auto   .hbm.xml   drive   

1、创建数据库

 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 */;

技术分享

2、创建用户实体/crm/src/com/louis/domain/User.java

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;
    }
}

3、编写hibernate映射文件/crm/src/com/louis/domain/User.hbm.xml

<?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>    

4、引入映射文件/crm/src/applicationContext.xml

    <!-- 引入映射的配置文件 -->
        <property name="mappingResources">
            <list>
                <value>com/louis/domain/User.hbm.xml</value>
            </list>
        </property> 

5、创建用户Action/crm/src/com/louis/web/action/UserAction.java

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;
    }

}

6、配置用户模块/crm/src/applicationContext.xml

    <!-- 配置用户的模块 -->
    <bean id="userAction" class="com.louis.web.action.UserAction" scope="prototype">
        
    </bean>

7、配置用户请求/crm/src/struts.xml

<!-- 配置用户的模块 -->
        <action name="user_*" class="userAction" method="{1}">
            <result name="loginOK" type="redirect">/index.jsp</result>
        </action>

8、创建服务类/crm/src/com/louis/service/impl/UserServiceImpl.java

package com.louis.service.impl;

import org.springframework.transaction.annotation.Transactional;

import com.louis.service.UserService;
@Transactional
public class UserServiceImpl implements UserService {

}

9、配置服务类/crm/src/applicationContext.xml

    <bean id="userService" class="com.louis.service.UserServiceImpl">
        
    </bean>

10、action类添加依赖注入/crm/src/com/louis/service/impl/UserServiceImpl.java

    private UserService userService;
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

11、配置依赖注入/crm/src/applicationContext.xml

<!-- 配置用户的模块 -->
    <bean id="userAction" class="com.louis.web.action.UserAction" scope="prototype">
        <property name="userService" ref="userService"/>
    </bean>

12、创建dao/crm/src/com/louis/dao/impl/UserDaoImpl.java

package com.louis.dao.impl;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.louis.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

}

13配置dao/crm/src/applicationContext.xml

    <bean id="userDao" class="com.louis.dao.UserDaoImpl">
        
    </bean>

14、service注入dao

    <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;
    }

15、配置dao的属性

    <bean id="userDao" class="com.louis.dao.UserDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

技术分享

16、创建注册页面regist.jsp

17、/crm/src/com/louis/web/action/UserAction.java

 

问题

scope="prototype"
配置文件
ModelDriven
HibernateDaoSupport
 

2、创建用户模板

标签:ext   odi   encoding   val   enc   struts   auto   .hbm.xml   drive   

原文地址:http://www.cnblogs.com/Michael2397/p/7697768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!