在xml文件中写sql语句
如 查询语句需要写
<select id="checkCutomExist" parameterType="com.oracle.entitys.Custom" resultType="String">
select name from Custom where phoneNo = #{phoneNo} and email=#{email}
</select>
这里查询语句需要写select标签 其中
- id 必须要和调用的方法对应 大小写敏感
- parameterType 代表着 你要传入的数据类型 所在的具体类的地址
- parameterMap 是你之前定义的resultMap标签id
<resultMap id="BaseResultMap" type="com.oracle.entitys.Custom">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="CHAR" />
<result column="education" property="education" jdbcType="CHAR" />
<result column="phoneNo" property="phoneNo" jdbcType="CHAR" />
<result column="qq" property="qq" jdbcType="CHAR" />
<result column="email" property="email" jdbcType="CHAR" />
<result column="customStatu" property="customStatu" jdbcType="CHAR" />
<result column="createDate" property="createDate" javaType="java.sql.Date" />
<result column="inviteName" property="inviteName" jdbcType="CHAR" />
</resultMap>
- resultType是你要返回的数据类型,基本类型可以直接写resultType=“基本类型和String”
- resultMap和之前的parameterMap 方式一样
- 其中批量插入不需要写useGeneratedKeys和keyProperty
- 插入语句
<insert id="insertSelective" parameterType="com.oracle.entitys.Custom" useGeneratedKeys="true"
keyProperty="id">
useGeneratedKeys把新增加的主键赋值到自己定义的keyProperty(id)中
- 更新语句
- if条件语句
<update id="updateByPrimaryKeySelective" parameterType="com.oracle.entitys.Custom">
update custom <set>
<if test="name !=null"> name = #{name},</if>
<if test="education !=null"> education = #{education},</if>
<if test="phoneNo !=null"> phoneNo = #{phoneNo},</if>
<if test="qq !=null"> qq = #{qq},</if>
<if test="email !=null"> email = #{email},</if>
<if test="customStatu !=0"> customStatu = #{customStatu},</if>
</set>
where id = #{id}
</update>
- 删除语句
<delete id="deleteCstomIfos" parameterType="java.util.List">
delete from customInfo where customId in (
<foreach collection="list" item="item" index="index"
separator=";">
#{item}
</foreach>
)
</delete>