spring_mvc_+hibernate_实现对学生信息的增删改查功能.docx
文本预览下载声明
换了一份新工作,刚到公司第一个礼拜,让学习spring mvc +hibernate,学完之后实现一个小功能,对学生信息的增删改查。对于工作近两年的我,真的没有那份恒心把两本电子书认认真真的从头至尾看完。以前接触过spring mvc,稍微了解一些配置文件,但是要和hibernate结合起来,还真不知道怎么搭建。所以就哪里不懂从哪里入手,现学现用,现在把学习过程总结一下,和大家做个分享。
第一步:准备好开发工具,本次学习使用myeclipse +mysql
第二步:准备好需要的jar包,如下所示:第三步:创建数据库 以及表机构
create database student default character set utf8;
create table student_info (id varchar(32) comment 主键,name varchar(5) comment 学生姓名,sex varchar(1) comment 性别,age int(2) comment 年龄,num varchar(5) comment 学号,PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8;
第四步:创建web project 并且添加配置文件,路径如下:
其中spring-beans.xml配置如下:
?xml version=1.0 encoding=UTF-8? beans xmlns=HYPERLINK /schema/beans /schema/beans xmlns:xsi=HYPERLINK /2001/XMLSchema-instance /2001/XMLSchema-instance xmlns:context=HYPERLINK /schema/context /schema/context xmlns:mvc=HYPERLINK /schema/mvc /schema/mvc xsi:schemaLocation=HYPERLINK /schema/beans /schema/beans HYPERLINK /schema/beans/spring-beans.xsd /schema/beans/spring-beans.xsd
bean id=studentDAO class=com.app.dao.impl.StudentDAOimpl property name=sessionFactory ref=sessionFactory/property /bean bean id=studentManagerBase class=com.app.service.impl.StudentManagerImpl property name=studentDAO ref=studentDAO/property /bean
bean name=studentManager parent=transactionProxy property name=target ref=studentManagerBase/property /bean/beansspring-common.xml内容如下:
?xml version=1.0 encoding=UTF-8?beans xmlns=HYPERLINK /schema/beans /schema/beansxmlns:xsi=HYPERLINK /2001/XMLSchema-instance /2001/XMLSchema-instancexmlns:tx=HYPERLINK /schema/tx /schema/txxmlns:context=HYPERLINK /schema/context /schema/contextxmlns:mvc=HYPERLINK /schema/mvc /schema/mvcxsi:schemaLocation=HYPERLINK /schema/beans /schema/beans HYPERLINK /schema/beans/spring-beans.xsd /schema/beans/spring-beans.xsdHYPERLINK /schema/tx /schema/tx HYPERLINK /schema/tx/spring-tx-3.0.xsd /schema/tx/spring-tx-3.0.xsd!-- 配置数据源 --bean id=dataSourceclass=org.spring
显示全部