springboot+springmvc+mybatis 使用xml文件来写增查改的sql
来源:互联网 发布:淘宝卖家手机必备软件 编辑:程序博客网 时间:2024/04/29 20:37
最近在做Java后台所遇到的问题和总结,本文针对的是springboot+springmvc+mybatis 环境下的,所用的数据库是oracle。
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="com.mapper.CustomerFieldMapper">
<resultMap type="com.entity.MstbCrmCustomerField" id="CustomerField">
<result column="ID" property="id" jdbcType="INTEGER"/>
<result column="BUSINESS_ID" property="businessId" jdbcType="VARCHAR"/>
<result column="CUSTOMER_BUS_ID" property="customerBusId" jdbcType="VARCHAR"/>
<result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP"/>
<result column="UPDATE_TIME" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="SPARE1" property="spare1" jdbcType="VARCHAR"/>
<result column="SPARE2" property="spare2" jdbcType="VARCHAR"/>
<result column="SPARE3" property="spare3" jdbcType="VARCHAR"/>
</resultMap>
<select id="findCustomerFieldByMap" resultMap="CustomerField" parameterType="java.util.HashMap">
select * from
mstb_crm_customer_field t
where t.business_id = #{businessId,jdbcType=VARCHAR}
</select>
<select id="findCustomerFieldList" resultMap="CustomerField">
select * from mstb_crm_customer_field t where t.CUSTOMER_BUS_ID in
<foreach collection="list" item="customerBusId"
index="index" open="(" close=")" separator=",">
#{customerBusId}
</foreach>
</select>
<insert id="insert" parameterType="com.entity.MstbCrmCustomerField">
INSERT INTO
mstb_crm_customer_field(ID,BUSINESS_ID,CUSTOMER_BUS_ID,
MD5,OWNERADA,STATUS,FIELD_NAME,FIELD_INDEX,FIELD_CONTENT,
CREATE_TIME,UPDATE_TIME,SPARE1,SPARE2,SPARE3)
VALUES(MSTB_CRM_CUSTOMER_FIELD_SEQ.nextval,
#{businessId,jdbcType=VARCHAR},
#{customerBusId,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP},
#{spare1,jdbcType=VARCHAR},
#{spare2,jdbcType=VARCHAR},
#{spare3,jdbcType=VARCHAR})
</insert>
<update id="update" parameterType="com.entity.MstbCrmCustomerField">
UPDATE mstb_crm_customer_field SET
BUSINESS_ID=#{businessId,jdbcType=VARCHAR},
CUSTOMER_BUS_ID=#{customerBusId,jdbcType=VARCHAR},
CREATE_TIME=#{createTime,jdbcType=TIMESTAMP},
UPDATE_TIME=#{updateTime,jdbcType=TIMESTAMP},
SPARE1=#{spare1,jdbcType=VARCHAR},
SPARE2=#{spare2,jdbcType=VARCHAR},
SPARE3=#{spare3,jdbcType=VARCHAR}
WHERE ID=#{id,jdbcType=INTEGER}
</update>
</mapper>
方法如下:
public MstbCrmCustomerField findCustomerFieldByMap(Map<String, Object> map);
public List<MstbCrmCustomerField> findCustomerFieldList(List<String> list);
public void insert(MstbCrmCustomerField customerField) ;
public void update(MstbCrmCustomerField customerField) ;
注意:
1.当查询的时候只要搞清楚resultMap、parameterType指的是什么就差不多了。返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部ResultMap的引用,但是resultType跟resultMap不能同时存在。
2.在用in查询的时候要注意了,要使用迭代。参考http://fireinjava.iteye.com/blog/1779420
- springboot+springmvc+mybatis 使用xml文件来写增查改的sql
- springboot 使用mybatis (xml Mapper)
- SpringBoot集成Mybatis+xml格式的sql配置文件
- springboot整合mybatis xml方式配置SQL
- MyBatis学习(三):解析MyBatis的SQL映射XML文件写法和使用原理
- MyBatis中SQL映射的XML文件
- springboot+springmvc+mybatis 使用注解对数据库的增、改和查操作
- 使用springboot+springmvc+mybaits-spring+mybatis-generator开发
- 使用MyBatis的ScriptRunner执行sql文件
- 使用mybatis的ScriptRunner执行sql文件
- 使用MyBatis的ScriptRunner执行sql文件
- mybatis的mapper.xml文件的动态sql编辑
- mybatis框架的mapper.xml文件中sql的使用方法:
- springboot+spring+springmvc+mybatis详解
- 【SpringMVC+mybatis】7.mybatis SqlMapConfig.xml文件详解
- springboot使用generator-mybatis插件自动生成mybatis文件
- SpringBoot+Mybatis显示sql
- springboot mybatis打印sql
- Android Journey: Graphics
- 【leetcode】153. Find Minimum in Rotated Sorted Array
- PowerDesigner教程系列(三)概念数据模型
- 对vector使用指针
- RESTful API 设计最佳实践(3)
- springboot+springmvc+mybatis 使用xml文件来写增查改的sql
- 彩色屏显示点阵字库(2016年9月工作)
- Jave字符串替换
- SharedPreferences源码解析及使用
- PowerDesigner教程系列(四)概念数据模型
- Unsupported gpu architecture 'compute_11'解决方法
- 视频源码免费下载
- 拍照与图片上传,附全部源码!
- 关于Android中的adb环境变量配置详解