`
jiasongmao
  • 浏览: 661163 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

ibatis中sql.xml文件配置示例

阅读更多
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Login">
<typeAlias alias="Goods" type="com.globalzt.b2c.domain.administration.Goods"/>
<!-- 修改商品is_delete属性信息 -->
<insert id="insertGoods" parameterClass="Goods" >

INSERT INTO b2c_tbl_goods (goods_id,cat_id,goods_sn,goods_name,goods_name_style,brand_id,market_price,
shop_price,promote_price,promote_start_date,promote_end_date,goods_img,goods_thumb,
add_time,is_new,is_promote,give_integral,goods_desc,last_update,keywords,integral
)
VALUES
(b2c_sp_next_id(),#catId#,#goodsSn#,#goodsName#,"",#brandId#,#marketPrice#,
#shopPrice#,#promotePrice#,#promoteStartDate#,#promoteEndDate#,#goodsImg#,#goodsThumb#,
#addTime#,#isNew#,#isPromote#,#giveIntegral#,"",#lastUpdate#,#keywords#,#integral# ) 
<selectKey resultClass="int" keyProperty="goodsId" >
   SELECT @@IDENTITY AS goodsId
  </selectKey>
</insert>
<!-- 根据商品ID删除商品信息 -->
<delete id="deleteGoodsById" parameterClass="int">
delete from b2c_tbl_goods where goods_id = #goodsId#
</delete>
<!-- 根据商品ID查询商品信息 -->
<select id="getGoodsById" parameterClass="int" resultClass="Goods">
         SELECT
goods_id as goodsId ,
cat_id as catId,
goods_sn as goodsSn,
goods_name as goodsName,
goods_name_style as goodsNameStyle,
click_count as  clickCount,
brand_id as brandId,
provider_name as providerName,
goods_number as goodsNumber,
goods_weight as goodsWeight,
market_price as marketPrice,
shop_price as shopPrice ,
promote_price as promotePrice,
promote_start_date as promoteStartDate,
promote_end_date as promoteEndDate,
warn_number as warnNumber,
keywords as keywords,
goods_brief as goodsBrief,
goods_desc as goodsDesc,
goods_thumb as goodsThumb,
goods_img as goodsImg,
original_img as originalImg,
is_real as isReal,
extension_code as extensionCode,
is_on_sale as isOnSale,
is_alone_sale as isAloneSale,
integral as integral,
add_time as addTime,
sort_order as sortOrder,
is_delete as isDelete,
is_best as isBest,
is_new as isNew,
is_hot as isHot,
is_promote as isPromote,
bonus_type_id as bonusTypeId,
last_update as lastUpdate,
goods_type as goodsType,
seller_note as sellerNote,
give_integral as giveIntegral
         FROM b2c_tbl_goods
         WHERE goods_id = #value#
   </select>
  
   <select id="getGoodsByParameter" parameterClass="java.util.HashMap" resultClass="Goods">
         SELECT
goods_id as goodsId ,
cat_id as catId,
goods_sn as goodsSn,
goods_name as goodsName,
goods_name_style as goodsNameStyle,
click_count as  clickCount,
brand_id as brandId,
provider_name as providerName,
goods_number as goodsNumber,
goods_weight as goodsWeight,
market_price as marketPrice,
shop_price as shopPrice ,
promote_price as promotePrice,
promote_start_date as promoteStartDate,
promote_end_date as promoteEndDate,
warn_number as warnNumber,
keywords as keywords,
goods_brief as goodsBrief,
goods_desc as goodsDesc,
goods_thumb as goodsThumb,
goods_img as goodsImg,
original_img as originalImg,
is_real as isReal,
extension_code as extensionCode,
is_on_sale as isOnSale,
is_alone_sale as isAloneSale,
integral as integral,
add_time as addTime,
sort_order as sortOrder,
is_delete as isDelete,
is_best as isBest,
is_new as isNew,
is_hot as isHot,
is_promote as isPromote,
bonus_type_id as bonusTypeId,
last_update as lastUpdate,
goods_type as goodsType,
seller_note as sellerNote,
give_integral as giveIntegral
         FROM b2c_tbl_goods
         WHERE (#category#=-1 or cat_id=#category#) AND (is_delete = 0)
         and  (#brand#=-1 or brand_id=#brand#)
         and  (#state#!='is_best' or is_best=1)
         and  (#state#!='is_new' or is_new=1)
         and  (#state#!='is_hot' or is_hot=1)
         and  (#state#!='is_promote' or is_promote=1)
         and  (#keywords#='' or (keywords like CONCAT('%', #keywords#, '%')))
      
   </select>

<!-- 修改商品信息 -->
   <update id="updateGoodsById" parameterClass="Goods">
   update b2c_tbl_goods
   set cat_id=#catId#,goods_sn=#goodsSn#,goods_name=#goodsName#,goods_name_style="",brand_id=#brandId#,market_price=#marketPrice#,
shop_price=#shopPrice#,promote_price=#promotePrice#,promote_start_date=#promoteStartDate#,promote_end_date=#promoteEndDate#,
goods_img=#goodsImg#,goods_thumb=#goodsThumb#,
is_promote=#isPromote#,give_integral=#giveIntegral#,last_update=#lastUpdate#,integral=#integral#
where goods_id=#goodsId#

   </update>
   <!-- 修改单个商品is_delete属性信息 -->
   <update id="updateGoodsParamDelete" parameterClass="Goods">
   update b2c_tbl_goods
set is_delete=#isDelete#
where goods_id=#goodsId#
</update>
<!-- 修改多个商品is_delete属性信息为1 -->
<update id="updateMultiGoodsParamDelete" parameterClass="string">
update b2c_tbl_goods set is_delete=1 where goods_id in ($goodsIds$)
</update>

<!-- 商品上架 -->
<update id="updateGoodSsaleTrue" parameterClass="string">
update b2c_tbl_goods set is_on_sale=1 where goods_id in ($goodsIds$)
</update>
<!-- 商品下架 -->
<update id="updateGoodSsaleFalse" parameterClass="string">
update b2c_tbl_goods set is_on_sale=0 where goods_id in ($goodsIds$)
</update>
<!-- 商品精品 -->
<update id="updateGoodBestTrue" parameterClass="string">
update b2c_tbl_goods set is_best=1 where goods_id in ($goodsIds$)
</update>
<!-- 商品取消精品 -->
<update id="updateGoodBestFalse" parameterClass="string">
update b2c_tbl_goods set is_best=0 where goods_id in ($goodsIds$)
</update>
<!-- 商品新品 -->
<update id="updateGoodNewTrue" parameterClass="string">
update b2c_tbl_goods set is_new=1 where goods_id in ($goodsIds$)
</update>
<!-- 商品取消新品 -->
<update id="updateGoodNewFalse" parameterClass="string">
update b2c_tbl_goods set is_new=0 where goods_id in ($goodsIds$)
</update>
<!-- 商品热销 -->
<update id="updateGoodHotTrue" parameterClass="string">
update b2c_tbl_goods set is_hot=1 where goods_id in ($goodsIds$)
</update>
<!-- 商品取消热销 -->
<update id="updateGoodHotFalse" parameterClass="string">
update b2c_tbl_goods set is_hot=0 where goods_id in ($goodsIds$)
</update>
<!-- 商品分类 -->
<update id="updateGoodsCatID" parameterClass="java.util.HashMap">
update b2c_tbl_goods set cat_id=#cat_id# where goods_id in ($goodsIds$)
</update>


</sqlMap>
分享到:
评论

相关推荐

    springboot mybatis mapper.xml 配置

    这个`boot-mybatis-mapper-demo`项目就是一个完整的示例,展示了如何在Spring Boot中配置MyBatis的`mapper.xml`文件,并通过Web接口进行数据操作。通过学习和理解这个例子,你将能够熟练掌握Spring Boot集成MyBatis...

    ibatis-2.3.4.726官方最新开发包

    Ibatis 是一款开源的、基于Java的持久层框架,它简化了数据库与应用程序之间的交互,提供了灵活的SQL映射机制,使得开发者可以将SQL语句直接写在配置文件中,从而避免了传统的JDBC代码编写。这个“ibatis-2.3.4.726...

    整合后的ibatis-2.3.0.677.jar

    开发者在XML文件中定义SQL语句,通过配置文件指定这些XML文件的位置,Ibatis会在运行时动态加载并执行这些SQL。 在2.3.0.677版本中,Ibatis引入了一些关键特性: 1. 动态SQL:Ibatis允许在Mapper XML文件中编写...

    IBatis.net-IBatis.DataAccess.1.9.2/IBatis.DataMapper.1.6.2

    - **XML配置驱动**:SQL语句和映射规则通常写在XML配置文件中,易于管理和维护。 - **动态SQL**:支持在XML映射文件中编写动态SQL,根据条件灵活生成查询。 - **数据缓存**:提供缓存机制,减少对数据库的频繁访问,...

    ibatis-2.3.2.715

    通过分析这份文件,我们可以清晰地知道哪些外部库是iBatis运行所必需的,以便在实际应用中正确配置。 "META-INF"目录下通常包含了项目元数据,如MANIFEST.MF文件,它描述了JAR文件的结构和属性。在这里,我们可以...

    ibatis2.3.4.726增删改查源码实例

    总的来说,这个"Ibatis2.3.4.726增删改查源码实例"为你提供了一个完整的Ibatis应用示例,你可以通过阅读源代码学习如何配置Ibatis,如何编写Mapper接口和XML文件,以及如何在Java代码中调用Ibatis进行数据库操作。...

    Struts2+Spring+Ibatis环境配置.doc

    示例中的`struts.xml`包含了一个过滤器配置,用于设置字符编码,这有助于处理中文字符。 此外,还有一些额外的依赖库,如`commons-codec.jar`、`commons-fileupload-1.2.jar`和`commons-io-1.4.jar`,它们分别提供...

    Ibatis-Demo.rar

    【Ibatis-Demo.rar】是一个压缩包文件,其核心内容是关于Ibatis框架的一个...通过这个示例,你可以学习如何搭建Ibatis环境,编写Mapper XML文件,以及如何在Java代码中调用这些SQL语句,从而掌握Ibatis的基本使用方法。

    Ibatis应用实例.docx

    总结来说,iBatis提供了一种简单但强大的方式来管理数据库操作,通过XML配置文件,我们可以自定义SQL,控制事务,并实现对象与数据库记录之间的映射。这种灵活性使得iBatis成为J2EE开发中一个受欢迎的工具,尤其适用...

    Struts+Spring+iBATIS做的XML文件操作例子

    在提供的"test"压缩包文件中,可能包含了一个模拟的XML文件操作示例,例如测试数据、配置文件或测试用例。这些文件可以帮助我们理解并运行这个例子,以学习如何在实际项目中结合Struts、Spring和iBATIS进行XML文件...

    ibatis-2.3.0.677

    iBatis主要解决了Java应用中的SQL映射问题,它将SQL语句与Java代码分离,通过XML配置文件或注解来定义SQL与Java对象之间的映射关系,实现了数据访问的灵活控制。在2.3.0.677版本中,iBatis提供了一套完整的SQL执行...

    mybatis Mapper.xml中传参多选 字符串形式逗号分隔 AND中拼接OR.rar

    标题和描述所提及的问题是关于如何在Mapper.xml文件中处理字符串形式的参数,这些参数由逗号分隔,并在`AND`语句中拼接`OR`子句来实现动态查询。这种场景在处理用户多选过滤条件时非常常见,比如在一个搜索框中,...

    ibatis开发指南.zip

    本指南将深入探讨iBatis的核心概念、配置、映射文件、动态SQL以及如何将其整合到实际项目中。 1. iBatis简介:iBatis起源于MyBatis的前身,由Clinton Begin创建,旨在解决传统JDBC中的繁琐数据操作问题。iBatis的...

    iBatis_Demo.rar_ibaties demo_ibatis de_ibatis mysql demo_ibati

    - **Mapper接口和XML配置文件**:例如`UserMapper.java`接口和对应的`UserMapper.xml`,定义SQL查询和操作,实现DAO(Data Access Object)层。 - **Model类**:如`User.java`,代表数据库中的表结构,用于数据...

    ibatis视频教程.rar

    4. 动态SQL:Ibatis提供了动态SQL的功能,可以在XML映射文件中直接编写条件语句,极大地简化了复杂的查询逻辑。 5. 支持存储过程:Ibatis可以调用数据库的存储过程,并且可以处理返回的结果。 6. 良好的扩展性:...

    IBatis.net 配置各种数据库

    其主要组成部分包括:SqlMapConfig.xml(全局配置文件)、Mapper.xml(SQL映射文件)以及对应的.NET接口或实体类。 配置数据库连接: 在使用IBatis.net时,首要任务是配置数据库连接。全局配置文件SqlMapConfig.xml...

    ibatis-api.rar_ibatis a_ibatis api_ibatis api.chm_ibatisAPI_java

    Ibatis API 的一个重要特点是动态SQL,它允许在XML配置文件或Mapper接口注解中编写条件语句,使得SQL的生成更加灵活,适应复杂的业务场景。 在实际开发中,Ibatis API 可以与Spring框架集成,通过Spring的`...

    ibatis-2.3.3.720

    iBatis通过映射XML配置文件或注解,实现了SQL语句的动态执行,使得数据库操作更加灵活,降低了系统耦合度。相比Hibernate的全自动ORM(对象关系映射),iBatis更注重控制权的下放,让开发者能够更精确地控制SQL执行...

    ibatis-2.3.3.720.jar 及chm格式帮助文档

    Ibatis 是一个优秀的开源持久层框架,它允许开发者将SQL语句直接写在配置文件中,与Java代码进行分离,使得SQL与Java代码更加清晰,易于维护。Ibatis 2.3.3.720 版本是一个稳定且功能丰富的版本,相比Hibernate,它...

Global site tag (gtag.js) - Google Analytics