一、/WEB-INF/web.xml    (配置WebWork + Spring)

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

二、/WEB-INF/applicationContext.xml (配置Spring + iBatis)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans default-autowire="autodetect">

<!-- 读取Mysql驱动信息参数文件    -->
<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
     <list>
      <value>WEB-INF/jdbc.properties</value>
     </list>
    </property>
</bean>

<!-- C3P0 数据源    -->
<bean id="dataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

<bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation"
     value="WEB-INF/sql-map-config.xml" />
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="userservices" class="userServices"/>   
<bean id="mymysqldriver" class="MyMysqlDriver"/>

<!-- 在personservices 对象中注入 sqlMapClient -->
<bean id="personservices" class="PersonServices">
  <property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

</beans>

三、/WEB-INF/jdbc.properties (配置 iBatis 的数据库驱动(MySql驱动))

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mysql1
jdbc.username=root
jdbc.password=1234

四、/classes/xwork.xml (配置 WebWork )

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">

<!-- START SNIPPET: xworkSample -->

<xwork>
<include file="webwork-default.xml"/>

<include file="xwork-Global.xml"/>
<include file="xwork-PersonAction.xml"/>
</xwork>

五、/classes/xwork-Global.xml (配置 WebWork )

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
<package name="global" extends="webwork-default">
    <global-results>
     <result name="error" type="redirect">/isnull.jsp</result>
    </global-results>
</package>
</xwork>

六、/classes/xwork-PersonAction.xml (配置 WebWork )

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
    <package name="ppp" extends="global">
     <action name="personaction" class="PersonAction">
      <result name="success" type="dispatcher">/Person.jsp</result>
      <interceptor-ref name="params"/>
     </action>
    </package>
</xwork>

七、/WEB-INF/sql-map-config.xml (配置 iBatis)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>

<settings
          cacheModelsEnabled="true"
          enhancementEnabled="true"
          lazyLoadingEnabled="true"
          maxRequests="32"
          maxSessions="10"
          maxTransactions="5"
          useStatementNamespaces="false"
      />
      <sqlMap resource="/PersonDataEntity.xml" />
</sqlMapConfig>

八、/classes/PersonDataEntity.xml (配置    iBatis    说白了就是写Sql)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Person">
<select id="selectPerson" resultClass="fizi.PersonDataEntity">
    SELECT PER_ID as id,
    PER_FIRST_NAME as firstName,
    PER_LAST_NAME as lastName,
    PER_BIRTH_DATE as birthDate,
    PER_WEIGHT_KG as weightInKilograms,
    PER_HEIGHT_M as heightInMeters
    FROM PERSON
    WHERE PER_ID = #value#
</select>
<insert id="insertPerson" parameterClass="fizi.PersonDataEntity">
    <![CDATA[
     INSERT INTO
     PERSON (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
     PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M)
     VALUES (#id#, #firstName#, #lastName#,
               #birthDate#, #weightInKilograms#, #heightInMeters#)
    ]]>
</insert>
<update id="updatePerson" parameterClass="fizi.PersonDataEntity">
    <![CDATA[
     UPDATE PERSON
     SET PER_FIRST_NAME = #firstName#,
     PER_LAST_NAME = #lastName#, PER_BIRTH_DATE = #birthDate#,
     PER_WEIGHT_KG = #weightInKilograms#,
     PER_HEIGHT_M = #heightInMeters#
     WHERE PER_ID = #id#
    ]]>
</update>
<delete id="deletePerson" parameterClass="fizi.PersonDataEntity">
    <![CDATA[
     DELETE PERSON
     WHERE PER_ID = #id#
    ]]>
</delete>     
</sqlMap>

九、/classes/webwork.properties (配置    WebWork )

### extension for actions  这里有点意思啊!
webwork.action.extension=action,java,aspx,jhtml

### Configuration reloading
### This will cause the configuration to reload xwork.xml when it is changed
webwork.i18n.reload=true
webwork.configuration.xml.reload=true

### Load custom default resource bundles
webwork.custom.i18n.resources=default

### character encoding
### webwork.locale=zh_CN
webwork.i18n.encoding=UTF-8

### upload jakarta, temp dir, maxSize = 10M
webwork.multipart.parser=jakarta

### webwork.ui.theme=xhtml
webwork.ui.theme=simple

### WebWork-Spring Integration
webwork.objectFactory = spring
webwork.objectFactory.spring.autoWire = name

十、部分学习代码 PersonDataEntity.java

import java.util.Date;

public class PersonDataEntity {
private int id;
private String firstName;
private String lastName;
private Date birthDate;
private double weightInKilograms;
private double heightInMeters;
public int getId () {
return id;
}
public void setId (int id) {
this.id = id;
}
public Date getBirthDate() {
    return birthDate;
}
public void setBirthDate(Date birthDate) {
    this.birthDate = birthDate;
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public double getHeightInMeters() {
    return heightInMeters;
}
public void setHeightInMeters(double heightInMeters) {
    this.heightInMeters = heightInMeters;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
public double getWeightInKilograms() {
    return weightInKilograms;
}
public void setWeightInKilograms(double weightInKilograms) {
    this.weightInKilograms = weightInKilograms;
}
}

十一、PersonServices.java (要使用iBatis 则需要 继承 类 SqlMapClientDaoSupport )

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapClient;

public class PersonServices extends SqlMapClientDaoSupport {

public PersonDataEntity GetPerson(Integer pID) {

return (PersonDataEntity) getSqlMapClientTemplate()
      .queryForObject("selectPerson", pID);
}
}

十二、PersonAction.java 在WebWork中方便调用的Action所以需要实现 接口Action

import Socket.sclient;

import com.opensymphony.xwork.Action;

public class PersonAction implements Action{
private PersonDataEntity persondataentity = new PersonDataEntity();
private PersonServices personservices;
public String execute() throws Exception {
    // TODO Auto-generated method stub
    Integer pid = new Integer(100001);
    sclient client = new sclient();     //调用Socket,这里你可以不需要(我写的:)
    client.ReadServer();
    persondataentity = personservices.GetPerson(pid);
    if (persondataentity!=null)
    {
     return SUCCESS;
    }
    else
    {
     return ERROR;
    }
}
public void setPersondataentity(PersonDataEntity persondataentity) {
    this.persondataentity = persondataentity;
}
public void setPersonservices(PersonServices personservices) {
    this.personservices = personservices;
}
public PersonDataEntity getPersondataentity() {
    return persondataentity;
}

}

十三、实际调用 PersonAction的 jsp文件 QueryPerson.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Person查询</title>
</head>
<body>
<table border=0 width=97%>
    <tr><td align="left">
     <form name="personaction" action="personaction.action" method="post">
     //想开个玩笑的话也可以写成,嘿嘿,原因参见文件:webwork.properties
     <form name="personaction" action="personaction.aspx" method="post">
      PersonID:&nbsp;<input type="text" name="persondataentity.id"><br>
      <input type="submit" name="查询"><br>
     </form>
    </td></tr>
</table>
</body>
</html>

十四、做个简单的查询结果返回页面 person.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@taglib uri="/webwork" prefix="ww" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
人员:<label style="color: red;" ><ww:property value='persondataentity.firstName'/></label>查询成功!
</body>
</html>

WebWork + Spring + iBatis + MySql 实例(Jonson)相关推荐

  1. Spring + Ibatis + MySql实例详解

    1. 环境: 将以下jar包加入到工程,commons-logging-1.0.4.jar.ibatis-2.3.0.677.jar.mysql-connector-java-5.0.3-bin.ja ...

  2. spring mvc mysql 实例_Spring+Mybatis+SpringMVC+Maven+MySql搭建实例

    一.准备工作 1. 首先创建一个表: CREATE TABLE `t_user` ( `USER_ID` int(11) NOT NULL AUTO_INCREMENT, `USER_NAME` ch ...

  3. c ibatis mysql实例_[Java教程]java程序中的ibatis连接mySql的基本实例

    [Java教程]java程序中的ibatis连接mySql的基本实例 0 2015-03-16 00:01:32 属性文件:SqlMap.properties1 driver=com.mysql.jd ...

  4. c ibatis mysql实例_Ibatis+MySql实例

    1. 介绍 Ibatis是开源的持久层框架.它的核心是SqlMap,将实体Bean跟关系数据库进行映射,将业务代码和SQL语句的书写进行分开,方便管理.Ibatis是"半自动"的O ...

  5. ibatis mysql 函数_Ibatis+MySql范例(转)

    Ibatis+mysql实例(转) 1. 介绍 Ibatis是开源的持久层框架.它的核心是SqlMap,将实体Bean跟关系数据库进行映射,将业务代码和SQL语句的书写进行分开,方便管理.Ibatis ...

  6. Spring MVC + Spring + Hibernate + mysql 注册登陆入门实例

    Spring MVC + Spring + Hibernate + mysql 注册登陆入门实例 (1) 结构 (说明目的是要做在线聊天室的,也包含登陆注册部分,先用这部分做个例子)开发环境用的是ST ...

  7. Spring 的持久化实例(JDBC, JdbcTemplate、HibernateDaoSupport、JdbcDaoSupport、SqlSessionDaoSupport等)...

    2019独角兽企业重金招聘Python工程师标准>>> 一.表(这里用mysql,数据库名为yiibai) CREATE TABLE `customer` (`CUST_ID` in ...

  8. springmvc与mysql实例_Spring+Mybatis+SpringMVC+Maven+MySql搭建实例

    摘要:本文主要讲了如何使用Maven来搭建Spring+Mybatis+SpringMVC+MySql的搭建实例,文章写得很详细,有代码有图片,最后也带有运行的效果. 一.准备工作 1. 首先创建一个 ...

  9. Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建

    目录 Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建 0.项目准备 1.数据持久层Mybatis+MySQL 1.1 MySQL数据准备 1.2 Mybatis ...

  10. activiti7关联mysql_学习笔记:一个MySQL实例有多个Activiti数据库问题

    学习笔记:一个MySQL实例有多个Activiti数据库问题 使用SpringBoot + activiti6 搭建审批流项目,数据库使用的是MySQL.且我的数据库下存在多个activiti相关的数 ...

最新文章

  1. C++ 中this指针的用途
  2. DataGridView 密码列(显示为*号)的设置
  3. windows2003 DHCP中批处理绑定IP与MAC
  4. BZOJ 2959: 长跑 [lct 双连通分量 并查集]
  5. androidstudio在mainactivity实现监听器借口无法抽象_趣操作,Tomcat如何实现一键式启停?
  6. MONO,原来你是水中月
  7. Git使用中关于rebase 、stash 、reflog、reset的一些注意点
  8. CXF生成本地ws调用代码测试webservice
  9. 通过谓词查找第一个元素
  10. ALSA驱动、设备函数调用关系
  11. mysql 循环_MySQL存储过程中的3种循环【转载】
  12. word 2007为不同页插入不同页眉页脚
  13. xp共享文件夹服务器,xp共享文件夹服务器
  14. 电商运营学习成长目录
  15. png格式的图片怎么变成jpg格式?png图片怎么转格式?
  16. 51单片机入门教程(2)——实现流水灯
  17. 腾讯云搭建 CentOS 可视化界面startx无效解决方法
  18. 永磁体磁偏角测试原理和测量设备介绍
  19. C语言之逻辑移位与算术移位
  20. Windows 筛选平台 (WFP)

热门文章

  1. 怎么打开优酷的kux格式?教你把kux转换成mp4的方法
  2. 某酷kux文件转mp4方法
  3. 电磁场有限元基本原理(5)
  4. php7isapi,WINDOWS 2000下使用ISAPI方式安装PHP
  5. typecho图片插件_Typecho图片表情插件Smilies1.1.3更新
  6. Android集成讯飞语音、百度语音、阿里语音识别
  7. VS2015静态库的使用(上)
  8. Python如何实现图片显示
  9. 网页上的时间显示设置
  10. 【云和恩墨大讲堂】视频课程震撼来袭-SQL优化精选案例