在bean包下建立User类和User.hbm.xml文件,实现User类和数据库表User的映射关系,具体User类不多说,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>
   //实现User类和表的映射
<class name="com.whl.bean.User">
<id name="id" type="java.lang.Integer" column="id">
<generator class="increment"/>
</id>
<property name="username" />
<property name="userpass" column="userpass"/>
</class>
</hibernate-mapping>

7.applicationContext.xml文件中实现前面所有需要注入的对象

 <?xml version="1.0" encoding="UTF-8"?>

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="123456" />
</bean> <bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/whl/bean/User.hbm.xml</value>
</list>
</property>
</bean> <bean id="userDao" class="com.whl.daoimpl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <bean id="userService" class="com.whl.serviceimpl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean> <bean id="LoginAction" class="com.whl.action.UserLoginAction">
<property name="userService" ref="userService"></property>
</bean> </beans>

8 在action类中实现真实的操作,并根据其结果做出相应的应答

package com.whl.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.whl.bean.User;
import com.whl.service.IUserService; public class UserLoginAction extends ActionSupport implements ModelDriven<User> { /**
*
*/
private static final long serialVersionUID = 1L;
private User user=new User();
private IUserService userService; public String userLongin(){
User u = userService.getUserByNamePass(user.getUsername(), user.getUserpass());
if (u!=null) {
ActionContext ac = ActionContext.getContext();
ac.put("user", u.getUsername());
return SUCCESS;
} return INPUT; } public void setUserService(IUserService userService) {
this.userService = userService;
} @Override
public User getModel() { return user;
} }

手动整合实现SSH项目开发02的更多相关文章

  1. 手动整合实现SSH项目开发01

    内容简介:本文主要介绍SSH项目开发的配置以及简单登录功能的实现. 1. 新建一个Dynamic Web Project. 2.导入需要 的Jar包,此项目是Struts.Hibernate.Spri ...

  2. JAVAEE——SSH项目实战02:客户列表和BaseDao封装

    作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7129152.html 该项目在SSH三大框架整合基础上进行开发:http://www.c ...

  3. SSH实战 · SSH项目开发环境搭建

    一:SSH整合 创建一个新的WEB项目 引入struts2.3.15.3: jar包:                 struts-2.3.15.3\apps\struts2-blank.war\W ...

  4. ActiveMQ整合spring结合项目开发流程(生产者和消费者)总结

    一:生产者代码编写: 1.配置pom.xml引入相关坐标 <dependencies> <!-- spring开发测试 --> <dependency> <g ...

  5. spring(四) 手动整合web项目(SSH)

    清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...

  6. SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)

    这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...

  7. 使用eclipse整合ssh项目的例子--lljf(1)

    最近向自己单独做一个基于ssh的项目,来预习和巩固自己的Java基础.找了一个实际生活中的定做衣服的例子来做一做,放到博客上给大家一起分享学习,后边会持续更新项目编写时候遇到的困难和使用的技术等. 1 ...

  8. FreeMarker与SSH项目整合流程

    FreeMarker与SSH项目整合流程 学习了SSH之后,一般为了减少数据库的压力,会使用FreeMarker来生成静态HTML页面.下面简单说一下FreeMarker与SSH项目的整合全过程~ 前 ...

  9. 第一章 企业项目开发--maven+springmvc+spring+mybatis+velocity整合

    说明:本系列文章主要是对自己在一家大型互联网公司实习的过程中对所学知识的总结!参与的是实际中使用的上线项目. 代码的github地址:https://github.com/zhaojigang/ssm ...

随机推荐

  1. PAT 1079 Total Sales of Supply Chain[比较]

    1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...

  2. PAT 1061 Dating[简单]

    1061 Dating(20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4 ...

  3. Debian更新软件源提示There is no public key available for the following key IDs的解决方法

    今天装了的debian7.0 但是更新软件源的时候出错 提示 W: There is no public key available for the following key IDs: 9D6D8F ...

  4. uva11020 set

    有n个人,每个人有两个属性x,y.如果对于一个人P(x,y) 不存在另外一个人(x',y') 使得x'<x,y'<=y 或者 x'<=x,y'<y 我们说p是有优势的,每次给出 ...

  5. Python通用网络爬虫脚本

    from sys import argv from os import makedirs,unlink,sep,mkdir from os.path import dirname,exists,isd ...

  6. Entity Framework在WCF中序列化的问题(转)

    问题描述 如果你在WCF中用Entity Framework来获取数据并返回实体对象,那么对下面的错误一定不陌生. 接收对 http://localhost:5115/ReService.svc 的 ...

  7. 什么是Java泛型?

    ①为什么要使用泛型? 引入例子 public class GenericTest { public static void main(String[] args) { List list = new ...

  8. git仓库迁移的两种解决方案

    Git仓库迁移而不丢失log的方法 要求能保留原先的commit记录,应该如何迁移呢? 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢? 注意:如果使用了代码审核工具Gerrit ...

  9. Kali2018.1

    目录 制作U盘启动盘 安装 Kali Linux 之后的事 更新源 配置 Zsh 配置 Vim 修改 Firefox 语言为中文 安装 Gnome 扩展 美化 安装 Google 拼音输入法 安装常用 ...

  10. CentOS6安装Pyhon3

    一,从官方下载Python3.6 [root@linux-node1 src]# pwd /usr/local/src [root@linux-node1 src]# wget https://www ...