<?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.9</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.itheima</groupId><artifactId>day10-SpringBoot-Case</artifactId><version>0.0.1-SNAPSHOT</version><name>day10-SpringBoot-Case</name><description>day10-SpringBoot-Case</description><properties><java.version>11</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.3.0</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--引入分页插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.4.6</version></dependency><!--阿里云OSS依赖--><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.15.1</version></dependency><dependency><groupId>javax.xml.bind</groupId><artifactId>jaxb-api</artifactId><version>2.3.1</version></dependency><dependency><groupId>javax.activation</groupId><artifactId>activation</artifactId><version>1.1.1</version></dependency><!-- no more than 2.3.3--><dependency><groupId>org.glassfish.jaxb</groupId><artifactId>jaxb-runtime</artifactId><version>2.3.3</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>
packagecom.itheima.mapper;importcom.itheima.pojo.Dept;importorg.apache.ibatis.annotations.Mapper;importorg.apache.ibatis.annotations.Select;importorg.apache.ibatis.annotations.Update;importjava.util.List;@MapperpublicinterfaceDeptMapper{List<Dept>list();voiddeleteById(Integer id);voidinsert(Dept dept);@Select("select * from dept where id = #{id}")DeptselectById(long id);@Update("update dept set name = #{name},update_time = #{updateTime} where id = #{id}")voidupdate(Dept dept);// void update(Dept dept);}
DeptMapper.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.itheima.mapper.DeptMapper"><selectid="list"resultType="Dept">
select id,name, create_time, update_time from dept;
</select><deleteid="deleteById">
delete from dept where id = #{id};
</delete><insertid="insert">
insert into dept(name,create_time,update_time) values(#{name},#{createTime},#{updateTime});
</insert><!-- <update id="update">--><!-- update dept set name = #{name},create_time = #{createTime},update_time = #{updateTime}--><!-- where id = #{id};--><!-- </update>--></mapper>
EmpMapper
packagecom.itheima.mapper;importcom.itheima.pojo.Emp;importorg.apache.ibatis.annotations.Mapper;importorg.apache.ibatis.annotations.Select;importjava.time.LocalDate;importjava.util.List;@MapperpublicinterfaceEmpMapper{/* @Select("select count(*) from emp")
long count();*/@Select("select * from emp")List<Emp>list();List<Emp>listByConditions(String name,Short gender,LocalDate begin,LocalDate end);voiddeleteByIds(List<Integer> ids);voidadd(Emp emp);@Select("select * from emp where id = #{id}")EmpselectById(Integer id);voidupdate(Emp emp);}
EmpMapper.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.itheima.mapper.EmpMapper"><insertid="add">
insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)
values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime},
#{updateTime})
</insert><updateid="update">
update emp <set><iftest="username != null and username != ''">
username = #{username},
</if><iftest="password != null and password != ''">
password = #{password},
</if><iftest="name != null and name != ''">
name = #{name},
</if><iftest="gender != null">
gender = #{gender},
</if><iftest="image != null and image != ''">
image = #{image},
</if><iftest="job != null">
job = #{job},
</if><iftest="entrydate != null">
entrydate = #{entrydate},
</if><iftest="deptId != null">
dept_id = #{deptId},
</if><iftest="updateTime != null">
update_time = #{updateTime}
</if></set>
where id = #{id}
</update><deleteid="deleteByIds">
delete from emp where id in
<foreachcollection="ids"item="id"separator=","open="("close=")">
#{id}
</foreach></delete><selectid="listByConditions"resultType="com.itheima.pojo.Emp">
select * from emp
<where><iftest="name!=null and name!=''">
name like concat('%',#{name},'%')
</if><iftest="gender!=null">
and gender=#{gender}
</if><iftest="begin!=null and end!=null">
and entrydate between #{begin} and #{end}
</if></where>
order by update_time desc
</select></mapper>