SSI的实例(登录增删改查)
源码下载:http://download.csdn.net/detail/u011518709/8195143
主要jar包:

配置文件:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="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">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 整合spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
spring配置文件: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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="1000"/>
<property name="defaultAutoCommit" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
</bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>/WEB-INF/sql-map-config.xml</value>
</property>
</bean>
<bean id="userdao" class="com.dao.UserDaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient"/>
</property>
</bean>
<bean id="userservice" class="com.service.UserServiceImpl">
<property name="userdao">
<ref bean="userdao" />
</property>
</bean> </beans>
数据库配置文件:jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/exe_test
jdbc.username=root
jdbc.password=root
sql-map-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="com/pojo/User.xml"/>
</sqlMapConfig>
主要介绍下:hibernate和sqlMapClient 查询的底层方法的区别:
UserdaoImpl.java
package com.dao;
import java.sql.SQLException;
import java.util.List; import com.ibatis.sqlmap.client.SqlMapClient;
import com.pojo.User;
public class UserDaoImpl implements UserDao{
private SqlMapClient sqlMapClient;
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
} public User Login(User u) {
User user = null;
try {
user = (User)sqlMapClient.queryForObject("login", u);
} catch (SQLException e) {
e.printStackTrace();
}
return user;
} public boolean isInsert(User user) {
boolean b;
try {
sqlMapClient.insert("insert", user);
b = true;
} catch (SQLException e) {
e.printStackTrace();
b = false;
}
return b ;
} public boolean isDelete(int id){
User user = null;
boolean b;
try{
sqlMapClient.delete("delete",id);
b = true;
}catch(SQLException e){
e.printStackTrace();
b = false;
}
return b;
} public boolean update(User user) {
boolean b ;
try {
sqlMapClient.update("update", user);
b = true;
} catch (Exception e) {
b = false;
}
return b;
} public User queryById(int id ) {
User user = null;
try {
user = (User) sqlMapClient.queryForObject("querybyid",id);
} catch (SQLException e) {
e.printStackTrace();
}
return user;
} public List<User> queryAll() {
List list = null;
User user = new User();
try {
list = sqlMapClient.queryForList("queryAll",user);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
User.xml (增删改查的语句)
<?xml version="1.0" encoding="gb2312" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias alias="User" type="com.pojo.User" />
<resultMap id="UserResult" class="User">
<result property="id" column="ID" />
<result property="username" column="USERNAME" />
<result property="password" column="PASSWORD" />
</resultMap> <select id="login" resultMap="UserResult" parameterClass="User">
select * from USER where USERNAME=#username# and PASSWORD=#password#
</select> <insert id="insert" parameterClass="User">
insert into USER(ID,USERNAME,PASSWORD)values(#id#,#username#,#password#)
</insert> <delete id="delete" parameterClass="int">
delete from USER where ID = #id#
</delete> <update id="update" parameterClass="User">
update USER set USERNAME=#username#,PASSWORD=#password# where ID = #id#
</update> <select id="querybyid" parameterClass="int" resultClass="User">
select * from USER where ID = #id#
</select> <select id="queryAll" parameterClass="User" resultClass="User">
select * from USER
</select>
</sqlMap>
ibatis后台查询的学习总结参考:http://blog.csdn.net/estelle_belle/article/details/41448589
SSI的实例(登录增删改查)的更多相关文章
- elasticsearch实例讲解增删改查
1.首先弄明白四个概念 elasticsearch 关系型数据库 index 数据库 type 表 document 行 field 字段 如果刚一开始理解比较困难,那你就在心中默念100遍,10遍也 ...
- Spring MVC实例(增删改查)
数据库配置文件application-context-jdbc.xml <?xml version="1.0" encoding="UTF-8"?> ...
- MVC实现登录,增删改查之数据展示:JSP的EL表达式(二)
这里的数据展示利用jsp的EL表达式,后台放入session,前台EL获取 数据库设计是这样的,一个老师对应有多个学生,在学生表student中建立外键tid与老师表teacher的tid对应,现在老 ...
- lucene4.10.2实例(增删改查)
最新jar和src免费下载:http://download.csdn.net/detail/u011518709/8248403 lucene 包的组成结构:对于外部应用来说索引模块(index)和检 ...
- node-express项目的搭建并通过mongoose操作MongoDB实现增删改查分页排序(四)
最近写了一个用node来操作MongoDB完成增.删.改.查.排序.分页功能的示例,并且已经放在了服务器上地址:http://39.105.32.180:3333. Mongoose是在node.js ...
- java连接mysql以及增删改查操作
java连接数据库的代码基本是固定的,步骤过程觉得繁琐些,代码记起来对我来说是闹挺.直接上代码: (温馨提醒:你的项目提前导入连接数据库的jar包才有的以下操作 ) class DBConnectio ...
- Day 18 :面向对象[基础,继承,组合]类的增删改查
有的人说,编程有3种范式: 1.面向过程:就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了. 2.面向函数:面向函数是面向过程的升级版,也就是把每个 ...
- 完成在本机远程连接HBase进行数据增删改查
1.进行hbase与本机远程连接测试连接 1.1 修改虚拟机文件hbase-site.xml(cd/usr/local/hbase/conf)文件,把localhost换成你的虚拟机主机名字 1.2修 ...
- IDEA搭建SSM实现登录、注册,数据增删改查功能
本博文的源代码:百度云盘/java/java实例/SSM实例/SSM实现登录注册,增删改查/IDEA搭建SSM实现登录,注册,增删改查功能.zip 搭建空的Maven项目 使用Intellij id ...
随机推荐
- 让TinyXML保存文件为UTF-8格式
TinyXML是个好东西,这个不用我多说了,我用它做过好几个项目,但这几个项目都只是从xml文件中获取信息,没有涉及到写文件,最近需要生成xml的配置文件,才注意到这个问题,那就是TinyXML似乎不 ...
- Unity中HideInInspector和SerializeField
http://blog.sina.com.cn/s/blog_697b1b8c0102uxvn.html Unity会自动为Public变量做序列化,序列化的意思是说再次读取Unity时序列化的变量是 ...
- Ruby编程实践
命令 常量大写 类名和模块名首字母大写,驼峰法,MyClass,Person 方法名小写,ruby中末尾添加符号特殊含义:destroyMethod!表示这个方法具有破坏性:isPrime?表示返回b ...
- [Xcode 实际操作]八、网络与多线程-(5)使用UIApplication对象发送邮件
目录:[Swift]Xcode实际操作 本文将演示如何使用应用程序单例对象,发送邮件的功能. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 注:需要使用真机进行测 ...
- NPOI用WorkbookFactory读写 2007以上格式文件(xlsx)
//我用的最新的2.2.1版本 //第一步:引用DLL,5个全导入,包括ICSHARP.ZIP,是个开源压缩工具包.XLSX是压缩格式,需要它来解压 //第二部: using NPOI.SS.User ...
- react native设置容器阴影
shadowColor:'#eee',shadowOffset:{h:10,w:10},shadowRadius:3,shadowOpacity:0.8,
- android okhttp和webview session共享
public static OkHttpClient get(Context context){ OkHttpClient.Builder builder = new OkHttpClient.Bui ...
- dubbo-springboot
一.服务提供者boot-user-service-provider 服务提供者boot-user-service-provider代码结构如下: 1.服务提供者boot-user-service-pr ...
- F. Bakkar In The Army 二分
http://codeforces.com/gym/100283/problem/F 思路是二分第几行,二分出来的行是总和 >= n的,那么第k - 1行一定要选,那么再在第k行中二分那一列. ...
- Unity Shader入门精要学习笔记 - 第9章 更复杂的光照
转载自 冯乐乐的<Unity Shader入门精要> Unity 的渲染路径 在Unity里,渲染路径决定了光照是如何应该到Unity Shader 中的.因此,如果要和光源打交道,我们需 ...