最近在做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文件进行增删改查操作的方法。详细展示了mapper.xml中关于查询和更新的SQL语句,包括单个条件查询、多个条件in查询,以及插入和更新的SQL语句。同时提到了resultMap和parameterType的使用注意事项,以及在使用in查询时如何处理参数。
1万+

被折叠的 条评论
为什么被折叠?



