//基于注解 @Mapper public interface reboudapt {@Select("select * from dept")List<dept> huoqudept();//删除语句@Delete("delete from dept where id = #{id}")void deletesc(Integer id);//增加语句@Insert("insert into dept(name, create_time, update_time) values ( #{name},#{createTime}, #{updateTime})")void add(dept posT);//查询语句@Select("select *from dept where id = #{id}")dept getcha(@Param("id") Integer id);//修改语句@Update("update dept set name = #{name} , create_time = #{createTime} , update_time = #{updateTime} where id = #{id}")void setsc(dept xiugai);}
//基于xml文件
<!--专门的文档声名--> <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.tlias.mapperclass.rebouemp"><!--修改语句--><update id="update">update emp<set><if test="username != null and username != ''">username = #{username},</if><if test="password != null and password != ''">password = #{password},</if><if test="name != null and name != ''">name = #{name},</if><if test="gender != null">gender = #{gender},</if><if test="image != null and image != ''">image = #{image},</if><if test="job != null">job = #{job},</if><if test="entrydate != null">entrydate = #{entrydate},</if>dept_id = #{deptId},<if test="updateTime != null">update_time = #{updateTime}</if></set>where id = #{id}</update><!--删除语句--><delete id="deletebs">delete from emp where id in<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach></delete><!--查询语句--><select id="fongzhuang" resultType="com.example.tlias.Resource.emp">select * from emp<where><if test=" name != null">name like concat('%' ,#{name},'%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null ">and entrydate between #{begin} and #{end}</if></where></select></mapper>
//xml文件配置需要同包同名放在resources资源文件下