importcn.ccut.model.Coffee;importorg.apache.ibatis.annotations.Insert;importorg.apache.ibatis.annotations.Mapper;importorg.apache.ibatis.annotations.Options;importorg.apache.ibatis.annotations.Param;importorg.apache.ibatis.annotations.Result;importorg.apache.ibatis.annotations.Results;importorg.apache.ibatis.annotations.Select;importjava.util.List;@MapperpublicinterfaceCoffeeMapper{@Insert("insert ignore into t_coffee (name, price, create_time, update_time)"+"values (#{name}, #{price}, now(), now())")@Options(useGeneratedKeys =true, keyProperty="id", keyColumn="id")intsave(Coffee coffee);@Select("select * from t_coffee where id = #{id}")@Results({@Result(id =true, column ="id", property ="id"),@Result(column ="create_time", property ="createTime"),// map-underscore-to-camel-case = true 可以实现一样的效果// @Result(column = "update_time", property = "updateTime"),})CoffeefindById(@Param("id")Long id);@Select("select * from t_coffee where name like concat('%',#{es},'%')")List<Coffee>getInfoByName(@Param("es")String es);@Select(" CREATE TABLE IF NOT EXISTS `demo11111111111` (\n"+" `id` int(11) NOT NULL AUTO_INCREMENT,\n"+" `path` varchar(128) NOT NULL COMMENT '路径'\n"+" ) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n")voidcreateTim();@Insert("insert ignore into t_coffee (name, price)"+"values (#{name}, #{price})")@Options(useGeneratedKeys =true, keyProperty="id", keyColumn="id")intsave1(Coffee coffee);List<Coffee>selectByOne(@Param("list")List<Integer> id);}
07.mapper.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="cn.ccut.mapper.CoffeeMapper"><selectid="selectByOne"resultType="cn.ccut.model.Coffee">
select * from t_coffee
<where><iftest="!@org.springframework.util.CollectionUtils@isEmpty(list)">
and id in
<foreachcollection="list"index="index"item="item"open="("separator=","close=")">
#{item}
</foreach></if></where></select></mapper>