SSI整合 示例
sql语句
create table user_c (id varchar(10) primary key,name varchar(20),age int ,address varchar(30);)
1.引入jar包
antlr-2.7.6.jar
aspectjweaver.jar
backport-util-concurrent.jar
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.quartz-1.6.2.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-httpclient-3.1.jar
commons-io-1.3.2.jar
dom4j-1.6.1.jar
ehcache-1.5.0.jar
freemarker-2.3.16.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
javassist-3.12.0.GA.jar
javassist-3.7.ga.jar
jcommon-1.0.17.jar
jfreechart-1.0.14.jar
json-lib-2.3-jdk15.jar
jta-1.1.jar
log4j-1.2.13.jar
mybatis-3.2.2.jar
mybatis-spring-1.2.0.jar
mysql-connector-java-5.1.13-bin.jar
ognl-3.0.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.aspects-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
org.springframework.instrument-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.jms-3.0.5.RELEASE.jar
org.springframework.orm-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.test-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web.portlet-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
org.springframework.web.struts-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
slf4j-api-1.6.1.jar
slf4j-nop-1.6.1.jar
struts2-core-2.2.1.jar
struts2-spring-plugin-2.2.1.jar
xwork-core-2.2.1.jar
2.写domain
User.java
package cn.itcast.mybatis.domain; public class User {
private String id;
private String name;
private Integer age;
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", age=" + age + "]";
} }
MyUser.xml (mybatis对数据处理)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="cn.itcast.mybatis.domain.User">
<sql id="cols">
id,name,age,address
</sql>
<sql id="ucols">
name=#{name},age=#{age},address=#{address}
</sql> <!-- 查询所有记录 -->
<select id="listAll" resultType="aliasesUser">
select <include refid="cols"/> from user_c
</select> <!-- 按条件查询 -->
<select id="find" parameterType="aliasesUser" resultType="aliasesUser">
select * from user_c
<where>
<if test="name!=null">
and name like "%"#{name}"%"
</if>
<if test="age!=null">
and age=#{age}
</if>
</where>
</select> <!-- 查询一个用户 -->
<select id="get" parameterType="string" resultType="aliasesUser">
select <include refid="cols"/> from user_c where id=#{id}
</select> <!-- 新增 -->
<insert id="create" parameterType="aliasesUser">
insert into user_c (id,name,age,address) values(#{id},#{name},#{age},#{address})
</insert> <!-- 修改 -->
<update id="update" parameterType="aliasesUser">
update user_c
<set>
<if test="name!=null">
name=#{name},
</if>
<if test="age!=null">
age=#{age},
</if>
<if test="address!=null">
address=#{address},
</if>
</set> where id=#{id}
</update> <!-- 删除 -->
<delete id="delete" parameterType="string">
delete from user_c where id=#{id}
</delete>
</mapper>
3.dao层处理
package cn.itcast.mybatis.dao; import java.util.List; import cn.itcast.mybatis.domain.User; public interface IUserDao {
public List<User> list();
public User get(String id);
public int insert(User u);
public int update(User u);
public int deleteById(String id);
}
daoImpl处理
package cn.itcast.mybatis.dao; import java.util.List; import org.mybatis.spring.support.SqlSessionDaoSupport; import cn.itcast.mybatis.domain.User; public class UserDaoImpl extends SqlSessionDaoSupport implements IUserDao { //删除
public int deleteById(String id) {
return this.getSqlSession().delete("cn.itcast.mybatis.domain.User.delete",id);
} //新增
public int insert(User u) {
return this.getSqlSession().insert("cn.itcast.mybatis.domain.User.create", u);
} //列表
public List<User> list() {
return this.getSqlSession().selectList("cn.itcast.mybatis.domain.User.listAll");
} //修改
public int update(User u) {
return this.getSqlSession().update("cn.itcast.mybatis.domain.User.update",u);
} //获取对象
public User get(String id) {
return (User) this.getSqlSession().selectOne("cn.itcast.mybatis.domain.User.get", id);
} }
4.service层
package cn.itcast.mybatis.service; import java.util.List; import cn.itcast.mybatis.domain.User; public interface IUserService {
public List<User> list();
public User get(String id);
public int insert(User u);
public int update(User u);
public int deleteById(String id);
}
serviceImpl
package cn.itcast.mybatis.service; import java.util.List; import cn.itcast.mybatis.dao.IUserDao;
import cn.itcast.mybatis.domain.User; public class UserServiceImpl implements IUserService { private IUserDao userDao;
public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
} public int deleteById(String id) {
int i = userDao.deleteById(id);
//测试事务
int j = 1/0;
return i;
} public User get(String id) {
return userDao.get(id);
} public int insert(User u) {
return userDao.insert(u);
} public List<User> list() {
return userDao.list();
} public int update(User u) {
return userDao.update(u);
} }
5.action层
package cn.itcast.mybatis.action; import java.util.List; import cn.itcast.mybatis.domain.User;
import cn.itcast.mybatis.service.IUserService; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; public class UserAction extends ActionSupport implements ModelDriven<User> {
private User model = new User();
public User getModel() {
return model;
} private IUserService userService;
public IUserService getUserService() {
return userService;
} public void setUserService(IUserService userService) {
this.userService = userService;
} public String list(){
List<User> dataList = userService.list();
ActionContext.getContext().put("dataList", dataList); return "plist";
} public String tocreate(){ return "pcreate";
} public String toupdate(){
User u = userService.get(model.getId());
ActionContext.getContext().getValueStack().push(u); return "pupdate";
} public String toview(){
User u = userService.get(model.getId());
ActionContext.getContext().getValueStack().push(u); return "pview";
} public String createSave(){
userService.insert(model); return "actlist";
} public String updateSave(){
userService.update(model); return "actlist";
} public String delete(){
userService.deleteById(model.getId()); return "actlist";
}
}
6.核心 配置文件
sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <typeAliases>
<typeAlias type="cn.itcast.mybatis.domain.User" alias="aliasesUser"></typeAlias>
</typeAliases>
<environments default="development"> <environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisdb?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="friends"/>
</dataSource>
</environment>
<!-- 产品 可用于多个配置的 -->
<environment id="product">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisdb?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="friends"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="cn/itcast/mybatis/domain/MyUser.xml"/>
</mappers>
</configuration>
spring-beans.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"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- 数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost/mybatisdb?characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" value="friends"></property>
</bean> <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
<property name="dataSource" ref="dataSource"></property> </bean> <!-- 事务相关控制 -->
<bean name="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 通知 -->
<tx:advice id="tx"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="pc" expression="execution(* cn.itcast.mybatis.service.*.*(..))" />
<!--把事务控制在Service层-->
<aop:advisor pointcut-ref="pc" advice-ref="tx" />
</aop:config> <bean id="userDao" class="cn.itcast.mybatis.dao.UserDaoImpl">
<property name="sqlSessionFactory" ref="sessionFactory"></property>
</bean> <bean id="userService" class="cn.itcast.mybatis.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean> <bean id="userAction" class="cn.itcast.mybatis.action.UserAction" scope="prototype">
<property name="userService" ref="userService">
<!-- 一样 <ref bean="userService"/> -->
</property>
</bean>
</beans>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.objectFactory" value="spring"></constant> <package name="user" namespace="/user" extends="struts-default">
<action name="userAction_*" class="userAction" method="{1}">
<result name="pview">/WEB-INF/jsps/user/jUserView.jsp</result>
<result name="plist">/WEB-INF/jsps/user/jUserList.jsp</result>
<result name="pcreate">/WEB-INF/jsps/user/jUserCreate.jsp</result>
<result name="pupdate">/WEB-INF/jsps/user/jUserUpdate.jsp</result>
<result name="actlist" type="redirectAction">/user/userAction_list</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MySSI</display-name> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
显示层
jUserCreate.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<form action="${pageContext.request.contextPath}/user/userAction_createSave" method="post">
<s:hidden name="id"/> <h2>新增用户</h2> <table border="1">
<tr>
<td>姓名:</td><td><s:textfield name="name"/></td>
</tr>
<tr>
<td>年龄:</td><td><s:textfield name="age"/></td>
</tr>
<tr>
<td>地址:</td><td><s:textarea name="address"/></td>
</tr>
<td><input type="submit" name="btnOK"/></td>
</tr>
</table>
</form>
</body>
</html>
jUserList.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<h2>用户列表</h2> <div style="padding:10px;">
<a href="${pageContext.request.contextPath}/user/userAction_tocreate">新增</a>
</div> <table border="1">
<tr align="center">
<td>序号</td>
<td>姓名</td>
<td>年龄</td>
<td>地址</td>
<td>操作</td>
</tr>
<s:iterator value="#dataList" var="u" status="line">
<tr>
<td align="center"><s:property value="#line.index+1"/></td>
<td><s:property value="name"/></td>
<td align="center"><s:property value="age"/></td>
<td><s:property value="address"/></td>
<td>
<a href="${pageContext.request.contextPath}/user/userAction_toview?id=${u.id}">查看</a>
<a href="${pageContext.request.contextPath}/user/userAction_toupdate?id=${u.id}">修改</a>
<a href="${pageContext.request.contextPath}/user/userAction_delete?id=${u.id}">删除</a>
</td>
</tr>
</s:iterator> </table>
jUserUpdate.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<form action="${pageContext.request.contextPath}/user/userAction_updateSave" method="post">
<s:hidden name="id"/> <h2>修改用户</h2> <table border="1">
<tr>
<td>姓名:</td><td><s:textfield name="name"/></td>
</tr>
<tr>
<td>年龄:</td><td><s:textfield name="age"/></td>
</tr>
<tr>
<td>地址:</td><td><s:textarea name="address"/></td>
</tr>
<td><input type="submit" name="btnOK"/></td>
</tr>
</table>
</form>
</body>
</html>
jUserView.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<form action="${pageContext.request.contextPath}/user/userAction_createSave" method="post">
<s:hidden name="id"/> <h2>浏览用户</h2> <div style="padding:10px;">
<a href="#" onclick="history.go(-1);">返回</a>
</div> <table border="1">
<tr>
<td>姓名:</td><td><s:property value="name"/></td>
</tr>
<tr>
<td>年龄:</td><td><s:property value="age"/></td>
</tr>
<tr>
<td>地址:</td><td><s:property value="address"/></td>
</table>
</form>
</body>
</html>
SSI整合 示例的更多相关文章
- Maven+SpringMVC+SpringFox+Swagger整合示例
查考链接:https://my.oschina.net/wangmengjun/blog/907679 coding地址:https://git.coding.net/conding_hjy/Spri ...
- 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例
本文给出一个整合Maven+SpringMVC+SpringFOX+Swagger的示例,并且一步步给出完成步骤. 本人在做实例时发现 http://blog.csdn.net/zth1002/art ...
- Struts2+Hibernate+Spring 整合示例
转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...
- SpringBoot与PageHelper的整合示例详解
SpringBoot与PageHelper的整合示例详解 1.PageHelper简介 PageHelper官网地址: https://pagehelper.github.io/ 摘要: com.gi ...
- WebService之Spring+CXF整合示例
一.Spring+CXF整合示例 WebService是一种跨编程语言.跨操作系统平台的远程调用技术,它是指一个应用程序向外界暴露一个能通过Web调用的API接口,我们把调用这个WebService的 ...
- [Java] SSH框架笔记_框架整合示例(一)
本文描述的是框架SSH集成的示例,由于在这个过程中有一些小的细节容易被遗忘,特别撰写了一篇小的博文来记录这个过程,希望对自己以及后来者能够起到积极意义. 本文中使用的框架和版本号为: struts-2 ...
- spring springmvc mybatis maven 项目整合示例-导航页面
spring原理 实践解析-简单的helloworld spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包 spring原理案例-基本项目 ...
- Joomla3x-CKEditor4x-WordPaster整合示例
1.1. 集成到Joomla_3.4.7-ckeditor4x 资源下载:Joomla 3x, 1.1.1. 添加wordpaster文件夹 路径:/media/wordpaster/ 1.1 ...
- SpringBoot与MybatisPlus3.X整合示例(十六)
包含 分页.逻辑删除.自定义全局操作 等绝大部分常用功能的使用示例,相当于大整合的完整示例 pom.xml <dependencies> <dependency> <gr ...
随机推荐
- [xsy2289]B
题意:给一棵树,一次操作定义为删掉一条树边再加一条边,并且满足加完边后这还是一棵树,问在进行不超过$k$次操作后能构造出多少种不同的树 首先...矩阵树定理在边有边权的时候同样适用,这时可以把它看成重 ...
- 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon
普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...
- Mac电脑,Andorid studio 配置 Flutter
1,下载flutter cd ~/Library/ git clone -b dev https://github.com/flutter/flutter.git 2,环境配置: 这里配置用户级别环境 ...
- Spring MVC常用注解@PathVariable、@RequestHeader、@CookieValue、@RequestParam、@RequestBody、@SessionAttributes、@ModelAttribute
简介: handler method参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri部分(这里指uri template中 ...
- WebAPI 操作返回
定义了一个返回枚举: public enum ResultExceptionEnum { 积分不足 = , 支付失败 = , 用户不存在 = , 验证码发送失败 = , 验证码不正确 = , 账号已存 ...
- http请求及缓存框架 GalHttprequest
GalHttprequest 是一个android平台上一个轻量级的http网络请求及缓存框架.当前GalHttpRequest支持以下功能: 同步请求Stirng.InputStream.Bitma ...
- 新公司官网项目优化实践(Vue)
入职后接手website-html和website-mobile项目,发现项目加载速度不太理想,于是结合自己之前的经验对项目做了优化.此篇文章主要记录这次优化详情. 原始项目:开发环境:website ...
- Binary Tree Preorder Traversal -- leetcode
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...
- 模糊搜索:concat各种函数详解、like操作符、通配符
if(StringUtils.isNotBlank(queryBean.getConditions())){ hqlBuilder.addWhereClause(" concat(this. ...
- mr程序无法输出日志进行调试的解决方法
mr程序无法输出日志进行调试的解决方法 @(Hadoop) yarn开启日志输出设置 在yarn-site.xml文件中添加如下配置: <property> <name>yar ...