1. 项目结构

2 web.xml的配置内容如下:

<?xmlversion="1.0"encoding="UTF-8"?>

<web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>

<servlet-name>springmvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:springmvc.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<!-- struts用/*,springmvc不能/*,语法
*.xxx -->

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:beans.xml</param-value>

</context-param>

</web-app>

  1. springmvc.xml的配置内容如下:

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

       http://www.springframework.org/schema/mvc

       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

       http://www.springframework.org/schema/context

       http://www.springframework.org/schema/context/spring-context-3.0.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">

<context:component-scanbase-package="com.rl.controller"/>

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<propertyname="prefix"value="/WEB-INF/jsp/"></property>

<propertyname="suffix"value=".jsp"></property>

</bean>

</beans>

  1. log4j.properties的内容如下:

log4j.rootLogger=DEBUG,Console

#Console

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=%d[%t]%-5p[%c]-%m%n

log4j.logger.java.sql.ResultSet=INFO

log4j.logger.org.apache=INFO

log4j.logger.java.sql.Connection=DEBUG

log4j.logger.java.sql.Statement=DEBUG

log4j.logger.java.sql.PreparedStatement=DEBUG

  1. beans.xml的配置内容如下:

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

       http://www.springframework.org/schema/mvc

       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

       http://www.springframework.org/schema/context

       http://www.springframework.org/schema/context/spring-context-3.0.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:component-scanbase-package="com.rl"/>

<beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<propertyname="driverClassName"value="com.mysql.jdbc.Driver"></property>

<propertyname="url"value="jdbc:mysql://localhost:3306/springmvc"></property>

<propertyname="username"value="root"></property>

<propertyname="password"value="123456"></property>

</bean>

<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<propertyname="dataSource"ref="dataSource"></property>

<propertyname="hibernateProperties">

<props>

<propkey="hibernate.Dialect">org.hibernate.dialect.MySQL5Dialect</prop>

<propkey="hibernate.show_sql">true</prop>

<propkey="hibernate.hbm2ddl">update</prop>

</props>

</property>

<propertyname="mappingDirectoryLocations"value="classpath:com/rl/mapping/"></property>

</bean>

<beanid="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<propertyname="sessionFactory"ref="sessionFactory"></property>

</bean>

<tx:adviceid="txAdvice"transaction-manager="txManager">

<tx:attributes>

<tx:methodname="save*"propagation="REQUIRED"/>

<tx:methodname="get*"read-only="true"/>

</tx:attributes>

</tx:advice>

<aop:config>

<aop:advisoradvice-ref="txAdvice"pointcut="execution(*
com.rl.service..*.*(..))"
/>

</aop:config>

</beans>

  1. Person0420的代码如下:

package com.rl.model;

import java.util.Date;

@SuppressWarnings("serial")

publicclass
Person0420implements java.io.Serializable {

private
IntegerpersonId;

private
Stringname;

private
Stringgender;

private
Stringaddress;

private
Datebirthday;

/**

*

*/

public
Person0420() {

}

/**

*@param
personId

*@param
name

*@param
gender

*@param
address

*@param
birthday

*/

public
Person0420(Integer personId, String name, String gender,

String address, Date birthday) {

this.personId
= personId;

this.name
= name;

this.gender
= gender;

this.address
= address;

this.birthday
= birthday;

}

/**

*@return
the personId

*/

public
Integer getPersonId() {

returnpersonId;

}

/**

*@param
personId the personId to set

*/

publicvoid
setPersonId(Integer personId) {

this.personId
= personId;

}

/**

*@return
the name

*/

public
String getName() {

returnname;

}

/**

*@param
name the name to set

*/

publicvoid
setName(String name) {

this.name
= name;

}

/**

*@return
the gender

*/

public
String getGender() {

returngender;

}

/**

*@param
gender the gender to set

*/

publicvoid
setGender(String gender) {

this.gender
= gender;

}

/**

*@return
the address

*/

public
String getAddress() {

returnaddress;

}

/**

*@param
address the address to set

*/

publicvoid
setAddress(String address) {

this.address
= address;

}

/**

*@return
the birthday

*/

public
Date getBirthday() {

returnbirthday;

}

/**

*@param
birthday the birthday to set

*/

publicvoid
setBirthday(Date birthday) {

this.birthday
= birthday;

}

}

  1. Person0420.hbm.xml的内容如下:

<?xmlversion="1.0"encoding="utf-8"?>

<!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/Hibernate
Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!--

Mapping fileautogenerated by MyEclipse Persistence Tools

-->

<hibernate-mapping>

<classname="com.rl.model.Person0420"table="person_0420"catalog="springmvc">

<idname="personId"type="java.lang.Integer">

<columnname="PERSON_ID"/>

<generatorclass="identity"/>

</id>

<propertyname="name"type="java.lang.String">

<columnname="NAME"length="10"/>

</property>

<propertyname="gender"type="java.lang.String">

<columnname="GENDER"length="1"/>

</property>

<propertyname="address"type="java.lang.String">

<columnname="ADDRESS"length="50"/>

</property>

<propertyname="birthday"type="java.util.Date">

<columnname="BIRTHDAY"length="0"/>

</property>

</class>

</hibernate-mapping>

  1. 创建数据库和表所需的SQL语句:

DROP DATABASE springmvc;

CREATE DATABASE springmvc DEFAULT CHARSET utf8;

USE springmvc;

CREATE TABLE person_0420(

PERSON_ID INT AUTO_INCREMENT PRIMARY KEY,

NAME VARCHAR(10) NOT NULL,

GENDER VARCHAR(1) NOT NULL,

ADDRESS VARCHAR(50) NOT NULL,

birthday DATE

);

  1. PersonDao的代码如下:

package com.rl.dao;

import com.rl.model.Person0420;

publicinterfacePersonDao
{

publicvoid
save(Person0420 person);

}

  1. PersonDaoImpl 的内容如下:

package com.rl.dao.impl;

import org.hibernate.SessionFactory;

import org.springframework.beans.factory.annotation.Autowired;

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

import org.springframework.stereotype.Repository;

import com.rl.dao.PersonDao;

import com.rl.model.Person0420;

@Repository

public class PersonDaoImpl extends HibernateDaoSupport implements PersonDao {

@Autowired

public void setMySessionFactory(SessionFactory sessionFactory){

super.setSessionFactory(sessionFactory);

}

public void save(Person0420 person) {

this.getHibernateTemplate().save(person);

}

}

  1. PersonService的内容如下:

package com.rl.service;

import com.rl.model.Person0420;

publicinterface
PersonService {

publicvoid
save(Person0420 person);

}

  1. PersonServiceImpl的内容如下:

package com.rl.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.rl.dao.PersonDao;

import com.rl.model.Person0420;

import com.rl.service.PersonService;

@Service

public class PersonServiceImpl implements PersonService {

@Autowired

PersonDao personDao;

public void save(Person0420 person) {

personDao.save(person);

}

}

  1. PersonController的内容如下:

package com.rl.controller;

import java.text.SimpleDateFormat;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.propertyeditors.CustomDateEditor;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.ServletRequestDataBinder;

import org.springframework.web.bind.annotation.InitBinder;

import org.springframework.web.bind.annotation.RequestMapping;

import com.rl.model.Person0420;

import com.rl.service.PersonService;

@Controller

@RequestMapping("/person")

public class PersonController {

@Autowired

PersonService personService;

@RequestMapping("/toForm.do")

public String toForm() {

return "form";

}

@RequestMapping("/save.do")

public String save(Person0420 person) {

personService.save(person);

return "success";

}

@InitBinder

public void initBinder(ServletRequestDataBinder binder) {

binder.registerCustomEditor(Date.class, new CustomDateEditor(

new SimpleDateFormat("yyyy-MM-dd"), true));

}

}

14 form.jsp的内容如下:

<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPEHTMLPUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<basehref="<%=basePath%>">

<title>My
JSP 'index.jsp' starting page</title>

<metahttp-equiv="pragma"content="no-cache">

<metahttp-equiv="cache-control"content="no-cache">

<metahttp-equiv="expires"content="0">

<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">

<metahttp-equiv="description"content="This
is my page"
>

<!--

<linkrel="stylesheet" type="text/css"
href="styles.css">

-->

</head>

<body>

<formaction="person/save.do"method="post">

name:<inputname="name"type="text"><br>

gender:<inputname="gender"type="text"><br>

address:<inputname="address"type="text"><br>

birthday:<inputname="birthday"type="text"><br>

<inputvalue="submit"type="submit">

</form>

</body>

</html>

  1. success.jsp的内容如下:

<%@pagelanguage="java"import="java.util.*"pageEncoding="ISO-8859-1"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPEHTMLPUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<basehref="<%=basePath%>">

<title>My
JSP 'index.jsp' starting page</title>

<metahttp-equiv="pragma"content="no-cache">

<metahttp-equiv="cache-control"content="no-cache">

<metahttp-equiv="expires"content="0">

<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">

<metahttp-equiv="description"content="This
is my page"
>

<!--

<linkrel="stylesheet" type="text/css"
href="styles.css">

-->

</head>

<body>

success<br>

</body>

</html>

浏览器中的访问地址是:http://localhost:8080/ssh/person/toForm.do

03SpringMVC,Spring,Hibernate整合(Date时间转换)的更多相关文章

  1. SpringMVC+Spring+Hibernate整合开发

    最近突然想认真研究下java web常用框架,虽然现在一直在用,但实现的整体流程不是很了解,就在网上搜索资料,尝试自己搭建,以下是自己的搭建及测试过程. 一.准备工作: 1/安装并配置java运行环境 ...

  2. Spring+Hibernate整合配置 --- 比较完整的spring、hibernate 配置

    Spring+Hibernate整合配置 分类: J2EE2010-11-25 17:21 16667人阅读 评论(1) 收藏 举报 springhibernateclassactionservlet ...

  3. spring+hibernate整合:报错org.hibernate.HibernateException: No Session found for current thread

    spring+hibernate整合:报错信息如下 org.hibernate.HibernateException: No Session found for current thread at o ...

  4. Struts2+Spring+Hibernate整合开发(Maven多模块搭建)

    Struts2+Spring+Hibernate整合开发(Maven多模块搭建) 0.项目结构 Struts2:web层 Spring:对象的容器 Hibernate:数据库持久化操作 1.父模块导入 ...

  5. 笔记58 Spring+Hibernate整合(一)

    Spring+Hibernate整合 一.整合思路 使DAO继承HibernateTemplate这个类 HibernateTemplate这个类提供了setSessionFactory()方法用于注 ...

  6. MyEclipse下Spring+Hibernate整合

    目前,SSH(Struts+Spring+Hibernate)是Web开发的一种常用框架组合,Struts实现了MVC,Hibernate实现了关系对象映射,Spring实现了基于Bean的配置管理. ...

  7. Struts+Spring+Hibernate整合入门详解

    Java 5.0 Struts 2.0.9 Spring 2.0.6 Hibernate 3.2.4 作者:  Liu Liu 转载请注明出处 基本概念和典型实用例子. 一.基本概念       St ...

  8. Spring、Struts2+Spring+Hibernate整合步骤

    所使用的Jar包: Hibernate: Spring(使用MyEclipse自动导入框架功能) Struts2: 注解包和MySql驱动包: 1.配置Hibernate和Spring: <be ...

  9. Struts+Spring+Hibernate整合

    这段笔记三两年前写的,一直因为一些琐事,或者搞忘记了,没有发.今天偶然翻出了它,就和大家一起分享下吧. 1.导入jar包 Struts的jar包: Spring的jar包: Hibernate的jar ...

随机推荐

  1. Go实现海量日志收集系统(三)

    再次整理了一下这个日志收集系统的框,如下图 这次要实现的代码的整体逻辑为: 完整代码地址为: https://github.com/pythonsite/logagent etcd介绍 高可用的分布式 ...

  2. .net如何引用System.Drawing.Drawing2D 命名空间和System.Drawing.Image及其相关概念

    其实这个很简单,直接在引用那里单击右键选择添加框架,然后找到System.Drawing就OK了, 其实并没有网上所说的那样需要下载什么Drawing.BLL. 首先Syetem.Drawing.Dr ...

  3. mvn package 和 mvn install

    刚刚准备将maven项目中一个子项目打个包,使用了mvn package.心想这个很简单嘛,没料就报错了.报错咱不怕,看看错在哪就好了. 编译出错,找不到我定义的异常类中的配置.那应该是引用父模块出来 ...

  4. TeamViewer 服务队列网页怎么打开?有什么用?

    熟悉一款软件,除了要熟悉它的界面,还应该熟悉它的网站.可能会有很多人说,网站我当然知道了.但是TeamViewer的服务队列页面你真的熟悉吗?所以,今天小编就带大家深入的了解一下TeamViewer服 ...

  5. Express 配置 https / 443 安全链接

    按照教程已配置成功 前一部分内容参照     https://blog.csdn.net/chenyufeng1991/article/details/60340006 前半部分是生成证书文件,关键部 ...

  6. [Luogu 1516] 青蛙的约会

    Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...

  7. 离线合成联想到的--canvas合成水印

    前段时间做了功能模块:用户设置自定义勋章: 实现方式:前端把用户设置的昵称传到后台,后台根据不同用户等级,使用离线合成技术合成不同的勋章返回到前端: 方案算是实现了,但是有点坑就是,后台的离线合成没有 ...

  8. Python能做些什么?

    前言 网上搜集到的一些python能做什么的资料,利用python能做很多事情,我们可以在多门课程中都使用Python作为我们的教学语言.比如,计算机网络.数据结构.人工智能.图像处理.软件分析与测试 ...

  9. 开源一个自己造的轮子:基于图的任务流引擎GraphScheduleEngine

    GraphScheduleEngine是什么: GraphScheduleEngine是一个基于DAG图的任务流引擎,不同语言编写.运行于不同机器上的模块.程序,均可以通过订阅GraphSchedul ...

  10. Redis和nosql简介,api调用;Redis数据功能(String类型的数据处理);List数据结构(及Java调用处理);Hash数据结构;Set数据结构功能;sortedSet(有序集合)数

    1.Redis和nosql简介,api调用 14.1/ nosql介绍 NoSQL:一类新出现的数据库(not only sql),它的特点: 1.  不支持SQL语法 2.  存储结构跟传统关系型数 ...