1、基本概念
ssm:spring+springMVC+mybatis
2、开发环境
Eclipse mars + jdk1.7 + maven + tomcat7
3、使用maven构建web项目
3.1、首先,创建一个maven object
3.2、创建一个新的路径、next
3.3、选择 maven-archetype-webapp next
3.4 输入artifact id 这个是项目的唯一标识 实际对应项目的名称 group id一般是公司,组织的名称反写,groupid+artifactid就保证了一个项目的唯一性。
4.1、在pom.xml文件中引入jar包,各个包是干嘛的 都有说明,此处不在赘述。
1
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3 4.0.0
4 com.hbst.www
5 BaseSsm_3
6 war
7 0.0.1-SNAPSHOT
8 BaseSsm_3 Maven Webapp
9 http://maven.apache.org
10
11
12 4.0.2.RELEASE
13
14 3.2.6
15
16 1.7.7
17 1.2.17
18
19
20
21
22
23 junit
24 junit
25 3.8.1
26 test
27
28
29
30
31 org.springframework
32 spring-core
33 ${spring.version}
34
35
36
37 org.springframework
38 spring-web
39 ${spring.version}
40
41
42 org.springframework
43 spring-oxm
44 ${spring.version}
45
46
47 org.springframework
48 spring-tx
49 ${spring.version}
50
51
52
53 org.springframework
54 spring-jdbc
55 ${spring.version}
56
57
58
59 org.springframework
60 spring-webmvc
61 ${spring.version}
62
63
64 org.springframework
65 spring-aop
66 ${spring.version}
67
68
69
70 org.springframework
71 spring-context-support
72 ${spring.version}
73
74
75
76 org.springframework
77 spring-test
78 ${spring.version}
79
80
81
82 org.mybatis
83 mybatis
84 ${mybatis.version}
85
86
87
88 org.mybatis
89 mybatis-spring
90 1.2.2
91
92
93
94
95 javax
96 javaee-api
97 7.0
98
99
100
101
102 mysql
103 mysql-connector-java
104 5.1.36
105
106
107
108 commons-dbcp
109 commons-dbcp
110 1.2.2
111
112
113
114
115 jstl
116 jstl
117 1.2
118
119
120
121
122 log4j
123 log4j
124 ${log4j.version}
125
126
127
128
129
130 javax.servlet
131 javax.servlet-api
132 3.0.1
133 provided
134
135
136
137
138 com.alibaba
139 fastjson
140 1.1.41
141
142
143
144
145 org.slf4j
146 slf4j-api
147 ${slf4j.version}
148
149
150
151 org.slf4j
152 slf4j-log4j12
153 ${slf4j.version}
154
155
156
157
158 org.codehaus.jackson
159 jackson-mapper-asl
160 1.9.13
161
162
163
164 commons-fileupload
165 commons-fileupload
166 1.3.1
167
168
169 commons-io
170 commons-io
171 2.4
172
173
174 commons-codec
175 commons-codec
176 1.9
177
178
179
180 BaseSsm_3
181
182
4.2、Spring与MyBatis的整合
此次整合,并没有使用mapper接口 而是使用sqlSessionTemplate接口来实现,使用mapper接口开发,会对每张表分别生成一个model,dao和一个mapper.xml,造成文件数过多。
4.2.1、SqlSessionTemplate
SqlSessionTemplate是MyBatis-spring的核心。这个类负责管理MyBatis的SqlSession,调用MyBatis的SQL方法。SqlSessionTemplate是线程安全的,可以被多个DAO所共享使用。
当调用SQL方法时,包含从映射器getMapper()方法返回的方法,SqlSessionTemplate将会保证使用的SqlSession是和当前Spring的事务相关的。此外,它管理session的生命周期,包含必要的关闭,提交或回滚操作。
SqlSessionTemplate实现了SqlSession,这就是说要对MyBatis的SqlSession进行简易替换。
SqlSessionTemplate通常是被用来替代默认的MyBatis实现的DefaultSqlSession,因为它不能参与到Spring的事务中也不能被注入,因为它是线程不安全的。相同应用程序中两个类之间的转换可能会引起数据一致性的问题。
SqlSessionTemplate对象可以使用SqlSessionFactory作为构造方法的参数来创建。
4.2.2、介绍完基本概念,现在开始正式整合,首先创建jdbc.propreties文件 (文件编码修改为 utf-8 )
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/db3
jdbc.username=root
jdbc.password=123456
jdbc.minIdle=30
jdbc.maxIdle=80
jdbc.maxWait=60000
jdbc.maxActive=80
jdbc.initialSize=20
jdbc.testWhileIdle=true
jdbc.testOnBorrow=false
jdbc.testOnReturn=false
jdbc.validationQuery=select 1
jdbc.validationQueryTimeout=1
jdbc.timeBetweenEvictionRunsMillis=600000
jdbc.numTestsPerEvictionRun=40
4.2.3、建立spring-mybatis.xml配置文件
这个文件就是用来完成spring和mybatis的整合的。这里面也没多少行配置,主要的就是 自动扫描,自动注入,配置数据库 。
http://www.springframework.org/schema/beans/spring-beans-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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
4.2.4、我在上面配置 SqlSessionTemplate 的时候 指定了一个 typeAliasMapper.xml,这个文件用来配置实体别名,下面我们来创建它,他指定了一个分页拦截插件,代码会贴在最后,这里不再给出
4.2.5、创建spring配置文件applicationContext.xml 引入spring-mybatis.xml配置
http://www.springframework.org/schema/beans/spring-beans-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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd">
5、至此,spring和mybatis整合完成,下面整合springMVC 我这里创建spring-servlet.xml
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
application/json;charset=UTF-8
6、配置日志管理,创建log4j.xml
7、配置web.xml 在web.xm中引入spring配置文件、springMVC的配置文件和log4j.xml文件
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Archetype Created Web Application
org.springframework.web.context.request.RequestContextListener
webAppRootKey
BaseSsm_1.root
javax.servlet.jsp.jstl.fmt.localizationContext
i18n/lang_messages
SetCharacterEncoding
com.hbst.basessm_1.util.filter.SetCharacterEncodingFilter
SetCharacterEncoding
/*
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
CharacterEncodingFilter
/*
org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
classpath:log4j.xml
log4jRefreshInterval
60000
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:config/spring/applicationContext.xml
Dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:config/spring/spring-servlet.xml
1
Dispatcher
*.do
8、最后的目录结构是这样的,源代码已经提交github,有需要的可以下载源码看看,我这里提交的项目是basessm_1,跟basessm_3的结构是一样的,只需要修改下配置文件即可。
github地址是 https://github.com/1428977695/BaseSsm_3/tree/master/BaseSsm_1
9、测试,我这里使用basessm_1来测试
9.1、将项目部署到tomcat上,打开浏览器http://localhost:8080/BaseSsm_1
9.2、出现helloword,说明项目已经启动成功了,下面我们进行数据交互测试,
首先创建数据库,我这里创建user表 就两个字段 将这两个字段的值 显示在页面上
9.3、创建实体
9.4、创建mapper文件
9.5、配置实体别名映射
9.6、创建接口
9.7、创建实现类
9.8、这里将几个基础的类如baseDao.java PageInterceptor.java文件也放上来
9.8.1、接口IBaseDao
package com.hbst.basessm_1.dao;
import java.util.List;
import java.util.Map;
public interface IBaseDao {
/**
* @Author:Dean
* @Description:保存
* @param statement
* SQLID
* @param parameter
* 参数
* @return boolean true 成功,false 失败
* @Date 2015年12月31日
*/
public boolean insert(String statement, Object parameter);
/**
* @Author:Dean
* @Description:更新
* @param statement
* SQLID
* @param parameter
* 参数
* @return boolean true 成功,false 失败
* @Date 2015年12月31日
*/
public boolean update(String statement, Object parameter);
/**
* @Author:Dean
* @Description:删除
* @param statement
* SQLID
* @param parameter
* 参数
* @return boolean true 成功,false 失败
* @Date 2015年12月31日
*/
public boolean delete(String statement, Object parameter);
/**
* @Author:Dean
* @Description:查询单条数据
* @param statement
* SQLID
* @param parameter
* 参数
* @return Object
* @Date 2015年12月31日
*/
public Object findOneByCustom(String statement, Object parameter);
/**
* @param* @Author:Dean
* @Description: 查询集合列表
* @param statement
* SQLID
* @param parameter
* 参数
* @return List* @Date 2015年12月31日
*/
public ListfindListByCustom(String statement, Object parameter);
/**
* @param* @Author:Dean
* @Description: 分页查询
* @param statement
* SQLID
* @param parameter
* 参数
* @return List* @Date 2015年12月31日
*/
public MapfindPageByCustom(String statement, Object parameter);
}
9.8.2、实现类basedao
package com.hbst.basessm_1.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.ibatis.executor.ErrorContext;
import org.apache.ibatis.executor.ExecutorException;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.mapping.ParameterMode;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.property.PropertyTokenizer;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.hbst.basessm_1.dao.IBaseDao;
import com.hbst.basessm_1.util.constant.CodeConstant;
import com.hbst.basessm_1.util.exception.BusinessException;
import net.sf.json.JSONObject;
@Repository("baseDao")
public class BaseDao implements IBaseDao {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
private long ROW_NUMBER = 0;
private long ZERO = 0;
public boolean insert(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
ROW_NUMBER = sqlSessionTemplate.insert(statement, parameter);
return ROW_NUMBER > ZERO ? true : false;
}
public boolean update(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
ROW_NUMBER = sqlSessionTemplate.update(statement, parameter);
return ROW_NUMBER > ZERO ? true : false;
}
public boolean delete(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
ROW_NUMBER = sqlSessionTemplate.delete(statement, parameter);
return ROW_NUMBER > ZERO ? true : false;
}
public Object findOneByCustom(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
return sqlSessionTemplate.selectOne(statement, parameter);
}
public ListfindListByCustom(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
return sqlSessionTemplate.selectList(statement, parameter);
}
@SuppressWarnings("unchecked")
public MapfindPageByCustom(String statement, Object parameter) {
if (null == parameter || null == statement) {
throw new IllegalArgumentException(" Parameter Is Null.");
}
HashMap retMap = new HashMap();
//是否为分页查询
JSONObject jsonObject = JSONObject.fromObject(parameter);
if (!(jsonObject.containsKey("pageNO") && null != jsonObject.get("pageNO")
&& jsonObject.containsKey("records") && null != jsonObject.get("records"))) {
throw new BusinessException(CodeConstant.PARAMS_ERROR);
}
Integer pageNO = (Integer) jsonObject.get("pageNO") ;
Integer records = (Integer) jsonObject.get("records");
if(pageNO!=null && pageNO>0 && records!=null && records>0){
retMap.put("recordsTotal", this.getTotalCount(statement, parameter));
retMap.put("data",sqlSessionTemplate.selectList(statement, parameter));
return retMap;
}
retMap.put("data",sqlSessionTemplate.selectList(statement, parameter));
return retMap;
}
/**
* get total count
*
* @param sqlSession
* @param statementName
* @param values
* @return
*/
private Integer getTotalCount(String statementName, Object values) {
Map parameterMap = toParameterMap(values);
Integer count = 0;
try {
MappedStatement mst = sqlSessionTemplate.getSqlSessionFactory()
.getConfiguration().getMappedStatement(statementName);
BoundSql boundSql = mst.getBoundSql(parameterMap);
String sql = " select count(*) total_count from ("
+ boundSql.getSql() + ") as total";
Connection con = SqlSessionUtils
.getSqlSession(sqlSessionTemplate.getSqlSessionFactory(), sqlSessionTemplate.getExecutorType(),sqlSessionTemplate.getPersistenceExceptionTranslator())
.getConnection();
PreparedStatement pstmt = con.prepareStatement(sql);
// BoundSql countBS = new
// BoundSql(mst.getConfiguration(),sql,boundSql.getParameterMappings(),parameterMap);
setParameters(pstmt, mst, boundSql, parameterMap);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt("total_count");
}
rs.close();
con.close();
pstmt.close();
} catch (Exception e) {
count = 0;
e.printStackTrace();
throw new RuntimeException(e);
}
return count;
}
/**
* 对SQL参数(?)设值,参考org.apache.ibatis.executor.parameter.
* DefaultParameterHandler
*
* @param ps
* @param mappedStatement
* @param boundSql
* @param parameterObject
* @throws SQLException
*/
private void setParameters(PreparedStatement ps,
MappedStatement mappedStatement, BoundSql boundSql,
Object parameterObject) throws SQLException {
ErrorContext.instance().activity("setting parameters")
.object(mappedStatement.getParameterMap().getId());
ListparameterMappings = boundSql
.getParameterMappings();
if (parameterMappings != null) {
Configuration configuration = mappedStatement.getConfiguration();
TypeHandlerRegistry typeHandlerRegistry = configuration
.getTypeHandlerRegistry();
MetaObject metaObject = parameterObject == null ? null
: configuration.newMetaObject(parameterObject);
for (int i = 0; i
ParameterMapping parameterMapping= parameterMappings.get(i);if (parameterMapping.getMode() != ParameterMode.OUT){
Object value;
String propertyName= parameterMapping.getProperty();PropertyTokenizer prop= newPropertyTokenizer(propertyName);
if (parameterObject==null) {
value= null;} else if (typeHandlerRegistry
.hasTypeHandler(parameterObject.getClass())) {
value= parameterObject;} else if (boundSql.hasAdditionalParameter(propertyName)) {
value= boundSql.getAdditionalParameter(propertyName);} else if (propertyName
.startsWith(ForEachSqlNode.ITEM_PREFIX)
&& boundSql.hasAdditionalParameter(prop.getName())) {
value= boundSql.getAdditionalParameter(prop.getName());if (value != null){
value= configuration.newMetaObject(value).getValue(
propertyName.substring(prop
.getName().length()));
}
} else {
value= metaObject ==null ? null : metaObject
.getValue(propertyName);
}
TypeHandler typeHandler= parameterMapping.getTypeHandler();if (typeHandler==null) {
throw new ExecutorException(
"There was no TypeHandler found for parameter "
+ propertyName + " of statement "
+ mappedStatement.getId());
}
typeHandler.setParameter(ps, i + 1, value,
parameterMapping.getJdbcType());
}
}
}
}
protected Map toParameterMap(Object parameter) {
if (parameter==null) {
return new HashMap();
}
if (parameter instanceof Map) {
return (Map, ?>) parameter;
} else {
try {
return PropertyUtils.describe(parameter);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
}
9.8.3、分页拦截器
package com.hbst.basessm_1.dao.plugin;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import net.sf.json.JSONObject;
/**
* @author tangguilin
* 分页拦截器
*/
@Intercepts({
@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class}),
@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})
})
public class PageInterceptor implements Interceptor {
public Object intercept(Invocation invocation) throws Throwable {
if (invocation.getTarget() instanceof StatementHandler) {
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
//获取参数对象
DefaultParameterHandler parameterHander=(DefaultParameterHandler) metaStatementHandler.getValue("delegate.parameterHandler");
Object parameterObject = parameterHander.getParameterObject();
JSONObject jsonParameter = JSONObject.fromObject(parameterObject);
//是否分页
if(jsonParameter!=null && jsonParameter.has("pageNO")){
Integer pageNO = jsonParameter.getInt("pageNO");
Integer records = jsonParameter.getInt("records");
BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
String sql = boundSql.getSql();
StringBuffer sb=new StringBuffer();
sb.append(sql);
sb.append(" limit ").append((pageNO-1)*records).append(" , ").append(records);
metaStatementHandler.setValue("delegate.boundSql.sql", sb.toString());
}
}
return invocation.proceed();
}
/**
* 拦截类型StatementHandler
*/
public Object plugin(Object target) {
if (target instanceof StatementHandler) {
return Plugin.wrap(target, this);
} else {
return target;
}
}
public void setProperties(Properties properties) {
}
}
9.8.4、返回码文件
package com.hbst.basessm_1.util.constant;
/**
* 返回码
*
* @author lanshiyan description: code码为6位 每两位为一个级别分别代表不同的意思 前两位:级别 00 系统级别 01
*/
public interface CodeConstant {
/****************************************************************************/
/************************ BEGIN 00系统级别公共错误码 *************************/
/****************************************************************************/
/**
* 成功
*/
public static final String SUCCESS = "000000";
/**
* 参数验证错误码
*/
public static final String PARAMS_ERROR = "000001";
public static final String PARAMS_ERROR_DESCRIPTION = "Invalid method required parameter";
/**
* 系统异常错误码
*/
public static final String SYSTEM_ERROR = "000002";
public static final String SYSTEM_ERROR_DESCRIPTION = "Unknow system exception";
/****************************************************************************/
/************************ BEGIN 01业务级别登录错误码 **************************/
/****************************************************************************/
// ===========================================================================
// BEGIN 00公共错误码
// ===========================================================================
/**
* 用户名密码错误
*/
public static final String USERNAME_PWD_ERROR = "010001";
/**
* 参数为空
*/
public static final String PARARM_IS_EMPTY = "010002";
/**
* 不存在此用户
*/
public static final String SYSTEM_USER_NOT_EXISTS = "010003";
public static final String SYSTEM_USER_NOT_EXISTS_DESCRIPTION = "User not exists or bad user ID";
/**
* 密码复杂度不符合要求
*/
public static final String SYSTEM_BAD_PASSWORD_COMPLEXITY = "010004";
public static final String SYSTEM_BAD_PASSWORD_COMPLEXITY_DESCRIPTION = "Invalid password of complexity";
/**
* 旧密码错误
*/
public static final String SYSTEM_BAD_OLD_PASSWORD = "010005";
public static final String SYSTEM_BAD_OLD_PASSWORD_DESCRIPTION = "Invalid old password";
}
9.8.5、返回实体文件
package com.hbst.basessm_1.util.entity;
import java.io.Serializable;
/**
* 返回消息实体对象定义
*
* @author Dean 20160912
*/
public class ResultMessage implements Serializable {
private static final long serialVersionUID = 1L;
// 成功或失败的错误码,成功时返回000000
private String code;
// 失败时返回的错误消息
private String codeDesc;
// 当需要返回值时返回值对象,如果是查询列表,则返回queryList对象
private Object data;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getCodeDesc() {
return codeDesc;
}
public void setCodeDesc(String codeDesc) {
this.codeDesc = codeDesc;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
return "ResultMessage [code=" + code + ", codeDes=" + codeDesc + ", data=" + data + "]";
}
}
9.8.6、系统自定义异常类
package com.hbst.basessm_1.util.exception;
import com.hbst.basessm_1.util.baseUtil.ResourceUtils;
import com.hbst.basessm_1.util.constant.CodeConstant;
/**
* 系统自定义异常类。
*
*
*
*/
public class BusinessException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 错误码。
*/
private String errorCode;
/**
* 问题
*/
private String errorDes;
/**
* 指定错误码与错误描述的异常。
*
* @param errorCode
* 错误码
* @param msg
* 异常信息
*/
public BusinessException(String errorCode, String msg) {
super(msg);
this.errorCode = errorCode;
this.errorDes = msg;
}
/**
* 指定错误码与错误描述的异常。
*
* @param errorCode
* 错误码
* @param msg
* 异常信息
*/
public BusinessException(String errorCode) {
super(ResourceUtils.getResultCodeDesc(errorCode));
this.errorCode = errorCode;
this.errorDes = (ResourceUtils.getResultCodeDesc(errorCode));
}
/**
* 未定义异常。
*/
public BusinessException() {
super(ResourceUtils.getResultCodeDesc(CodeConstant.SYSTEM_ERROR));
this.errorCode = CodeConstant.SYSTEM_ERROR;
}
public String getErrorDes() {
return errorDes;
}
public void setErrorDes(String errorDes) {
this.errorDes = errorDes;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}
9.9、现在创建controller
9.10、在index.jsp中加入jquery.js,用jq的ajax方法去请求后台
9.11、刷新页面,点击按钮,会出现数据库里面插入的值。
10、到这里 ssm基础框架的整合,已经前后台交互就算完成。