本人从一开始看到网上的别人写的博客也好,资料也好,实际上已经很全,但是,在参考写的同时也发现有很多地方都不解不能直接用的问题,导致实际使用的过程中经常会出错,参考原来做的项目,以及网上的资料,整理了一个比较简单的自己理解的spring+spring mvc+mybatis+mysql实现的分页的资料。前台用easyui实现。有源码。
运行效果图:
一、配置文件
1、在mybatis的
configuration配置文件(本人的配置文件:
configuration.xml,同时本人还有config.properties是数据连接的配置文件)中直接运添加如下:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
configuration
PUBLIC
"-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd"
>
<
configuration
>
<!-- 配置数据库方言 目前只有 mysql和oracle两种-->
<!-- 配置property的另一种方式,不同的配置方式关系到分页拦截器取property时候使用的不同方法 -->
<!-- <properties>
<property name="dialect" value=" mysql"/>
<property name="pageSqlId" value=".*Page$" />
</properties> -->
<
settings
>
<
setting
name
=
"cacheEnabled"
value
=
"true"
/>
</
settings
>
<
plugins
>
<
plugin
interceptor
=
"my.comm.interceptor.PageInterceptor"
>
<
property
name
=
"dialect"
value
=
"mysql"
/>
<!-- 此处可以根据实际情况配置 此配置表明只要是查询带有Page结尾的语句才真正地进行分页处理,但是实际是所有连接都先进入拦截器,然后再判断是否带有Page结尾 -->
<
property
name
=
"pageSqlId"
value
=
".*Page$"
/>
</
plugin
>
</
plugins
>
<!-- 此处不要,但是如果没有配置config.properties的话就不能去掉,建议不写在此处
<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/test?useUnicode=true&characterEncoding=UTF-8" />
<property name=" username" value="root" />
<property name="password" value="" />
</dataSource>
</environment>
</environments>
</
configuration
>
另附:config.properties配置:
hibernate.dialect=
org.hibernate.dialect.MySQLDialect
driverClassName=
com.mysql.jdbc.Driver
validationQuery=
SELECT
1
jdbc_url=
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc_username=
root
jdbc_password=
dbType=
mysql
2、spring-mybatis.xml添加如下配置:
<!-- myBatis文件 -->
<
bean
id
=
"sqlSessionFactory"
class
=
"org.mybatis.spring.SqlSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"configLocation"
value
=
"classpath:configuration.xml"
/>
<
property
name
=
"mapperLocations"
value
=
"classpath:rich/mapping/*.xml"
/>
</
bean
>
以上基本的配置完成
二、拦截器的编写
package
my.comm.interceptor;
import
java.sql.Connection;
import
java.sql.PreparedStatement;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
java.util.List;
import
java.util.Properties;
import
org.apache.ibatis.annotations.Param;
import
org.apache.ibatis.executor.parameter.ParameterHandler;
import
org.apache.ibatis.executor.statement.StatementHandler;
import
org.apache.ibatis.logging.Log;
import
org.apache.ibatis.logging.LogFactory;
import
org.apache.ibatis.mapping.BoundSql;
import
org.apache.ibatis.mapping.MappedStatement;
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.factory.DefaultObjectFactory;
import
org.apache.ibatis.reflection.factory.ObjectFactory;
import
org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import
org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
import
org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import
org.apache.ibatis.session.Configuration;
import
org.apache.ibatis.session.RowBounds;
import
my.comm.page.PageParameter;
import
my.model.Store;
/**
*
*
@ClassName
PageInterceptor
*
@Description
分页拦截器
*
@author
fengshj
*
@date
2014年10月9日
*/
// args = {Connection.class}表明只要是数据连接都先进入拦截器
@Intercepts
({
@Signature
(type = StatementHandler. class, method = "prepare" , args = {Connection. class})})
public
class
PageInterceptor implements Interceptor {
private
static
final
Log logger = LogFactory.getLog(PageInterceptor. class);
private
static
final
ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory();
private
static
final
ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
private
static
String
defaultDialect
= "mysql" ; // 数据库类型(默认为 mysql)
private
static
String
defaultPageSqlId
= ".*Page$" ; // 需要拦截的ID(正则匹配)
private
static
String
dialect
= "" ; // 数据库类型(默认为 mysql)
private
static
String
pageSqlId
= "" ; // 需要拦截的ID(正则匹配)
private
Properties
properties
;
public
PageInterceptor() {
this .properties = null;
}
@Override
public
void
setProperties(Properties
properties
) {
this .properties = properties ;
}
@Override
public
Object intercept(Invocation
invocation
)
throws
Throwable {
StatementHandler
statementHandler
= (StatementHandler)
invocation
.getTarget();
MetaObject
metaStatementHandler
= MetaObject.forObject(
statementHandler
,
DEFAULT_OBJECT_FACTORY
,
DEFAULT_OBJECT_WRAPPER_FACTORY
);
// 分离代理对象链(由于目标类可能被多个拦截器拦截,从而形成多次代理,通过下面的两次循环可以分离出最原始的的目标类)
while
(
metaStatementHandler
.hasGetter( "h")) {
Object
object
=
metaStatementHandler
.getValue(
"h"
);
metaStatementHandler
= MetaObject.forObject(
object
,
DEFAULT_OBJECT_FACTORY
,
DEFAULT_OBJECT_WRAPPER_FACTORY
);
}
// 分离最后一个代理对象的目标类
while
(
metaStatementHandler
.hasGetter( "target")) {
Object
object
=
metaStatementHandler
.getValue(
"target"
);
metaStatementHandler
= MetaObject.forObject(
object
,
DEFAULT_OBJECT_FACTORY
,
DEFAULT_OBJECT_WRAPPER_FACTORY
);
}
Configuration
configuration
= (Configuration)
metaStatementHandler
.getValue(
"delegate.configuration"
);
/*此处取dialect取的就是configuration.xml里的property,dialect = configuration.getVariables().getProperty("dialect");
* 的取法是configuration.xml里的这种定义才使用,这种方法可以直接取不用实例化this.properties
* <properties>
<property name="dialect" value="mysql"/>
<property name="pageSqlId" value=".*Page$" />
</properties>
* */
//dialect = configuration.getVariables().getProperty("dialect");
/*
* 这种取法是下面的写法才使用,但是这种取法就一定要先将this.properties实例化
* <plugin interceptor="my.comm.interceptor.PageInterceptor">
<property name="dialect" value="mysql"/>
<property name="pageSqlId" value=".*Page$" />
</plugin>
*/
dialect
=
this
.properties .getProperty( "dialect");
if
(
null
== dialect || "".equals( dialect )) {
logger
.warn(
"Property dialect is not setted,use default 'mysql' "
);
dialect
=
defaultDialect
;
}
pageSqlId
=
this
.
properties
.getProperty( "pageSqlId");
// pageSqlId = configuration.getVariables().getProperty("pageSqlId");
if
(
null
== pageSqlId || "".equals( pageSqlId )) {
logger
.warn(
"Property pageSqlId is not setted,use default '.*Page$' "
);
pageSqlId
=
defaultPageSqlId
;
}
MappedStatement
mappedStatement
= (MappedStatement)
metaStatementHandler
.getValue(
"delegate.mappedStatement"
);
// 只重写需要分页的 sql语句。通过MappedStatement的ID匹配,默认重写以Page结尾的MappedStatement的 sql
if
(
mappedStatement
.getId().matches( pageSqlId)) {
BoundSql
boundSql
= (BoundSql)
metaStatementHandler
.getValue(
"delegate.boundSql"
);
Object
parameterObject
=
boundSql
.getParameterObject();
if
(
parameterObject
== null) {
throw
new
NullPointerException("parameterObject is null!" );
}
else
{
// 分页参数作为参数对象parameterObject的一个属性
/**
* 此处特别要注意对应的mpper.java里要包含page这个parameter,
* 如:public List
<Store> getStoreListByPage(@Param("store")Store store,@Param("page")Pagination page);
* 如果没有@Param("page")Pagination page会报错
*/
PageParameter
page
= (PageParameter)
metaStatementHandler
.getValue(
"delegate.boundSql.parameterObject.page"
);
String
sql
=
boundSql
.getSql();
// 重写 sql
String
pageSql
= buildPageSql(
sql, page);
metaStatementHandler
.setValue(
"delegate.boundSql.sql"
, pageSql );
// 采用物理分页后,就不需要 mybatis的内存分页了,所以重置下面的两个参数
metaStatementHandler
.setValue(
"delegate.rowBounds.offset"
,
RowBounds.
NO_ROW_OFFSET );
metaStatementHandler
.setValue(
"delegate.rowBounds.limit"
, RowBounds.NO_ROW_LIMIT );
Connection
connection
= (Connection)
invocation
.getArgs()[0];
// 重设分页参数里的总页数等
setPageParameter(
sql, connection , mappedStatement , boundSql , page );
}
}
// 将执行权交给下一个拦截器
return
invocation
.proceed();
}
/**
* 从数据库里查询总的记录数并计算总页数,回写进分页参数
<code> PageParameter</code> ,这样调用者就可用通过 分页参数
*
<code>
PageParameter
</code>
获得相关信息。
*
*
@param
sql
*
@param
connection
*
@param
mappedStatement
*
@param
boundSql
*
@param
page
*/
private
void
setPageParameter(String
sql
, Connection connection , MappedStatement mappedStatement ,
BoundSql
boundSql
, PageParameter
page
) {
// 记录总记录数
String
countSql
=
"select count(0) from ("
+
sql
+ ") as total" ;
PreparedStatement
countStmt
=
null
;
ResultSet
rs
=
null
;
try
{
countStmt
=
connection
.prepareStatement(
countSql
);
BoundSql
countBS
=
new
BoundSql(
mappedStatement
.getConfiguration(),
countSql
,
boundSql
.getParameterMappings(),
boundSql
.getParameterObject());
setParameters(
countStmt , mappedStatement , countBS , boundSql .getParameterObject());
rs
=
countStmt
.executeQuery();
int
totalCount
= 0;
if
(
rs
.next()) {
totalCount
=
rs
.getInt(1);
}
page
.setTotalCount(
totalCount );
int
totalPage
= totalCount / page .getPageSize() + ((totalCount % page .getPageSize() == 0) ? 0 : 1);
page
.setTotalPage(
totalPage );
}
catch
(SQLException
e
) {
logger
.error(
"Ignore this exception"
, e );
}
finally
{
try
{
rs
.close();
}
catch
(SQLException
e
) {
logger
.error(
"Ignore this exception"
, e );
}
try
{
countStmt
.close();
}
catch
(SQLException
e
) {
logger
.error(
"Ignore this exception"
, e );
}
}
}
/**
* 对SQL参数(?)设值
*
*
@param
ps
*
@param
mappedStatement
*
@param
boundSql
*
@param
parameterObject
*
@throws
SQLException
*/
private
void
setParameters(PreparedStatement
ps
, MappedStatement mappedStatement , BoundSql boundSql,
Object
parameterObject
)
throws
SQLException {
ParameterHandler
parameterHandler
=
new
DefaultParameterHandler(mappedStatement , parameterObject , boundSql );
parameterHandler
.setParameters(
ps
);
}
/**
* 根据数据库类型,生成特定的分页 sql
*
*
@param
sql
*
@param
page
*
@return
*/
private
String buildPageSql(String
sql
, PageParameter
page
) {
if
(
page
!= null) {
StringBuilder
pageSql
=
new
StringBuilder();
if
(
"mysql"
.equals( dialect)) {
pageSql
= buildPageSqlForMysql(
sql, page );
}
else
if
("oracle" .equals( dialect)) {
pageSql
= buildPageSqlForOracle(
sql, page );
}
else
{
return
sql
;
}
return
pageSql
.toString();
}
else
{
return
sql
;
}
}
/**
* mysql的分页语句
*
*
@param
sql
*
@param
page
*
@return
String
*/
public
StringBuilder buildPageSqlForMysql(String
sql
, PageParameter
page
) {
StringBuilder
pageSql
=
new
StringBuilder(100);
String
beginrow
= String.valueOf((
page
.getCurrentPage() - 1) *
page
.getPageSize());
pageSql
.append(
sql);
pageSql
.append(
" limit " + beginrow + "," + page .getPageSize());
return
pageSql
;
}
/**
* 参考 hibernate的实现完成oracle的分页
*
*
@param
sql
*
@param
page
*
@return
String
*/
public
StringBuilder buildPageSqlForOracle(String
sql
, PageParameter
page
) {
StringBuilder
pageSql
=
new
StringBuilder(100);
String
beginrow
= String.valueOf((
page
.getCurrentPage() - 1) *
page
.getPageSize());
String
endrow
= String.valueOf(
page
.getCurrentPage() *
page
.getPageSize());
pageSql
.append(
"select * from ( select temp.*, rownum row_id from ( ");
pageSql
.append(
sql);
pageSql
.append(
" ) temp where rownum <= ").append( endrow);
pageSql
.append(
") where row_id > ").append( beginrow);
return
pageSql
;
}
@Override
public
Object plugin(Object
target
) {
// 当目标类是StatementHandler类型时,才包装目标类,否者直接返回目标本身,减少目标被代理的次数
if
(
target
instanceof StatementHandler) {
return
Plugin.wrap(
target, this );
}
else
{
return
target
;
}
}
}
三、分页参数类
package
my.comm.page;
import
java.util.List;
/**
* 分页参数类
*
*/
public
class
PageParameter {
public
static
final
int DEFAULT_PAGE_SIZE = 10;
private
int
pageSize
;
private
int
currentPage
;
private
int
prePage
;
private
int
nextPage
;
private
int
totalPage
;
private
int
totalCount
;
/**
* 当前页的数据
*/
private
List<?>
list
;
/**
* 获得分页内容
*
*
@return
*/
public
List<?> getList() {
return list ;
}
/**
* 设置分页内容
*
*
@param
list
*/
@SuppressWarnings
(
"unchecked" )
public
void
setList(List
list
) {
this .list = list ;
}
public
PageParameter() {
this
.
currentPage
= 1;
this
.
pageSize
= DEFAULT_PAGE_SIZE;
}
/**
*
*
@param
currentPage
*
@param
pageSize
*/
public
PageParameter(
int currentPage , int pageSize) {
this
.
currentPage
= currentPage ;
this
.
pageSize
= pageSize ;
}
public
int
getCurrentPage() {
return
currentPage
;
}
public
void
setCurrentPage(
int
currentPage
) {
this
.
currentPage
= currentPage ;
}
public
int
getPageSize() {
return
pageSize
;
}
public
void
setPageSize(
int
pageSize
) {
this
.
pageSize
= pageSize ;
}
public
int
getPrePage() {
return
prePage
;
}
public
void
setPrePage(
int
prePage
) {
this
.
prePage
= prePage ;
}
public
int
getNextPage() {
return
nextPage
;
}
public
void
setNextPage(
int
nextPage
) {
this
.
nextPage
= nextPage ;
}
public
int
getTotalPage() {
return
totalPage
;
}
public
void
setTotalPage(
int
totalPage
) {
this
.
totalPage
= totalPage ;
}
public
int
getTotalCount() {
return
totalCount
;
}
public
void
setTotalCount(
int
totalCount
) {
this
.
totalCount
= totalCount ;
}
}
四、调用
1、controller类
package
my.controller;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;
import
java.util.Date;
import
java.util.HashMap;
import
java.util.Map;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody;
import
my.comm.page.PageParameter;
import
my.model.Store;
import
my.service.StoreService;
@Controller
@RequestMapping
(
"StoreController"
)
public
class
StoreController {
@Autowired
private
StoreService
storeService
;
@RequestMapping
(
"getStore" )
@ResponseBody
/*将内容或对象作为 HTTP 响应正文返回,使用@ResponseBody将会跳过视图处理部分,
而是调用适合HttpMessageConverter,将返回值写入输出流。*/
public
Map<String,Object> getPrice(HttpServletRequest
request
,HttpServletResponse response ,Store store ,String rksjsstr ,String rksjestr ,Integer page ,Integer rows) throws Exception{
Date
rksj
=
null
;
Date
rksjend
=
null
;
//设置当前页
int
intPage
=page == null|| page<=0?1: page;
//设置每页显示的数量
int
intPageSize
=rows == null|| rows<=0?10: rows;
SimpleDateFormat
sdf
=
new
SimpleDateFormat(
"yyyy-MM-dd"
);
if (rksjsstr != null && ! rksjsstr.equals( "" )){
try {
rksj= sdf.parse( rksjsstr);
}
catch
(ParseException
e
) {
e.printStackTrace();
}
}
if (rksjestr != null && ! rksjestr.equals( "" )){
try {
rksjend= sdf.parse( rksjestr);
}
catch
(ParseException
e
) {
e.printStackTrace();
}
}
Map<String,Object>
reMap
=
new
HashMap<String,Object>();
int statu =0;
PageParameter
pagination
=
this
.
storeService
.getStoreListByPage( store, statu, intPage , intPageSize );
reMap.put( "total" , pagination .getTotalCount()); // 当前页的数据
reMap.put( "pageSize" ,pagination .getTotalPage()); //总页数
reMap.put( "pageNo" , pagination .getCurrentPage()); //当前页数
reMap.put( "rows" ,pagination .getList()); //列表信息
return reMap ;
}
}
2、service类
package
my.service;
import
my.comm.page.PageParameter;
import
my.model.Store;
public
interface
StoreService {
public
PageParameter getStoreListByPage (Store
store
,
int
statu ,
int intPage , int intPageSize) throws Exception;
}
serviceImpl类
package
my.service.impl;
import
java.util.List;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service;
import
my.comm.page.PageParameter;
import
my.dao.StoreMapper;
import
my.model.Store;
import
my.service.StoreService;
@Service
(
"storeService"
)
public
class
StoreServiceImpl implements StoreService {
private
StoreMapper
storeMapper
;
public
StoreMapper getStoreMapper() {
return storeMapper ;
}
@Autowired
public
void
setStoreMapper(StoreMapper
storeMapper
) {
this .storeMapper = storeMapper ;
}
@Override
public
PageParameter getStoreListByPage(Store
store
,
int
statu
, int pageNO, int pageSize) throws Exception{
try {
PageParameter
page
=
new
PageParameter();
page.setCurrentPage( pageNO);
page.setPageSize( pageSize);
//store.setPage(page);
List<Store>
list
=
this
.
storeMapper
.getStoreListByPage( store, page);
page.setList( list);
return page ;
}
catch
(Exception
e
) {
return null ;
}
}
}
3、mapper类
package
my.model;
import
java.math.BigDecimal;
public
class
Store {
private
String
id
;
private
String
bh
;
private
String
bjmc
;
private
BigDecimal
jhprice
;
private
BigDecimal
lsprice
;
private
BigDecimal
pfprice
;
private
String
gg
;
private
String
dw
;
private
String
cfwz
;
// private Pagination page;
public
String getId() {
return
id
;
}
public
void
setId(String
id
) {
this
.
id
= id == null ? null : id.trim();
}
public
String getBh() {
return
bh
;
}
public
void
setBh(String
bh
) {
this
.
bh
= bh == null ? null : bh.trim();
}
public
String getBjmc() {
return
bjmc
;
}
public
void
setBjmc(String
bjmc
) {
this
.
bjmc
= bjmc == null ? null : bjmc.trim();
}
public
BigDecimal getJhprice() {
return
jhprice
;
}
public
void
setJhprice(BigDecimal
jhprice
) {
this
.
jhprice
= jhprice ;
}
public
BigDecimal getLsprice() {
return
lsprice
;
}
public
void
setLsprice(BigDecimal
lsprice
) {
this
.
lsprice
= lsprice ;
}
public
BigDecimal getPfprice() {
return
pfprice
;
}
public
void
setPfprice(BigDecimal
pfprice
) {
this
.
pfprice
= pfprice ;
}
public
String getGg() {
return
gg
;
}
public
void
setGg(String
gg
) {
this
.
gg
= gg == null ? null : gg.trim();
}
public
String getDw() {
return
dw
;
}
public
void
setDw(String
dw
) {
this
.
dw
= dw == null ? null : dw.trim();
}
public
String getCfwz() {
return
cfwz
;
}
public
void
setCfwz(String
cfwz
) {
this
.
cfwz
= cfwz == null ? null : cfwz.trim();
}
}
4、mapper.xml
<?
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
=
"my.dao.StoreMapper" >
<
resultMap id= "BaseResultMap" type = "my.model.Store" >
<
id
column = "id" property= "id" jdbcType= "VARCHAR" />
<
result
column = "bh" property= "bh" jdbcType= "VARCHAR" />
<
result
column = "bjmc" property= "bjmc" jdbcType= "VARCHAR" />
<
result
column = "jhprice" property= "jhprice" jdbcType= "DECIMAL" />
<
result
column = "lsprice" property= "lsprice" jdbcType= "DECIMAL" />
<
result
column = "pfprice" property= "pfprice" jdbcType= "DECIMAL" />
<
result
column = "gg" property= "gg" jdbcType= "VARCHAR" />
<
result
column = "dw" property= "dw" jdbcType= "VARCHAR" />
<
result
column = "cfwz" property= "cfwz" jdbcType= "VARCHAR" />
</
resultMap>
<
sql id= "Base_Column_List" >
id, bh, bjmc, jhprice, lsprice, pfprice, gg, dw, cfwz
</
sql>
<
select id= "selectByPrimaryKey" resultMap = "BaseResultMap" parameterType ="java.lang.String" >
select
<
include
refid = "Base_Column_List" />
from store
where id = #{id,jdbcType=VARCHAR}
</
select>
<!-- 根据查询条件查询库存 -->
<
select
id = "getStoreListByPage" resultMap= "BaseResultMap"
parameterType= "my.model.Store" >
select
<include refid = "Base_Column_List" />
from store
where 1=1
<if test = "store !=null">
<if test = "store.bh != null and store.bh !=''">
and bh like CONCAT('%',#{store.bh},'%')
</if >
<if test = "store.bjmc != null and store.bjmc !=''">
and bjmc like CONCAT('%',#{store.bjmc},'%')
</if >
</if >
</
select
>
<
delete id= "deleteByPrimaryKey" parameterType ="java.lang.String" >
delete from store
where id = #{id,jdbcType=VARCHAR}
</
delete>
<
insert id= "insert" parameterType = "my.model.Store" >
insert into store (id, bh, bjmc,
jhprice, lsprice, pfprice,
gg, dw, cfwz)
values (#{id,jdbcType=VARCHAR}, #{bh,jdbcType=VARCHAR}, #{bjmc,jdbcType=VARCHAR},
#{jhprice,jdbcType=DECIMAL}, #{lsprice,jdbcType=DECIMAL}, #{pfprice,jdbcType=DECIMAL},
#{gg,jdbcType=VARCHAR}, #{dw,jdbcType=VARCHAR}, #{cfwz,jdbcType=VARCHAR})
</
insert>
<
insert id= "insertSelective" parameterType = "my.model.Store" >
insert into store
<
trim
prefix = "(" suffix= ")" suffixOverrides= "," >
<
if
test = "id != null" >
id,
</
if
>
<
if
test = "bh != null" >
bh,
</
if
>
<
if
test = "bjmc != null" >
bjmc,
</
if
>
<
if
test = "jhprice != null" >
jhprice,
</
if
>
<
if
test = "lsprice != null" >
lsprice,
</
if
>
<
if
test = "pfprice != null" >
pfprice,
</
if
>
<
if
test = "gg != null" >
gg,
</
if
>
<
if
test = "dw != null" >
dw,
</
if
>
<
if
test = "cfwz != null" >
cfwz,
</
if
>
</
trim
>
<
trim
prefix = "values (" suffix= ")" suffixOverrides= "," >
<
if
test = "id != null" >
#{id,jdbcType=VARCHAR},
</
if
>
<
if
test = "bh != null" >
#{bh,jdbcType=VARCHAR},
</
if
>
<
if
test = "bjmc != null" >
#{bjmc,jdbcType=VARCHAR},
</
if
>
<
if
test = "jhprice != null" >
#{jhprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "lsprice != null" >
#{lsprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "pfprice != null" >
#{pfprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "gg != null" >
#{gg,jdbcType=VARCHAR},
</
if
>
<
if
test = "dw != null" >
#{dw,jdbcType=VARCHAR},
</
if
>
<
if
test = "cfwz != null" >
#{cfwz,jdbcType=VARCHAR},
</
if
>
</
trim
>
</
insert>
<
update id= "updateByPrimaryKeySelective" parameterType ="my.model.Store" >
update store
<
set
>
<
if
test = "bh != null" >
bh = #{bh,jdbcType=VARCHAR},
</
if
>
<
if
test = "bjmc != null" >
bjmc = #{bjmc,jdbcType=VARCHAR},
</
if
>
<
if
test = "jhprice != null" >
jhprice = #{jhprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "lsprice != null" >
lsprice = #{lsprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "pfprice != null" >
pfprice = #{pfprice,jdbcType=DECIMAL},
</
if
>
<
if
test = "gg != null" >
gg = #{gg,jdbcType=VARCHAR},
</
if
>
<
if
test = "dw != null" >
dw = #{dw,jdbcType=VARCHAR},
</
if
>
<
if
test = "cfwz != null" >
cfwz = #{cfwz,jdbcType=VARCHAR},
</
if
>
</
set
>
where id = #{id,jdbcType=VARCHAR}
</
update>
<
update id= "updateByPrimaryKey" parameterType = "my.model.Store" >
update store
set bh = #{bh,jdbcType=VARCHAR},
bjmc = #{bjmc,jdbcType=VARCHAR},
jhprice = #{jhprice,jdbcType=DECIMAL},
lsprice = #{lsprice,jdbcType=DECIMAL},
pfprice = #{pfprice,jdbcType=DECIMAL},
gg = #{gg,jdbcType=VARCHAR},
dw = #{dw,jdbcType=VARCHAR},
cfwz = #{cfwz,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</
update>
</
mapper
>
五、jar包,本个实际项目所有jar包,可以根据自己的实际需求增删改
六、源码(包括数据库表)
http://download.csdn.net/detail/ericnany/8018745