1.一级缓存是储存在内存里,随着SqlSession关闭在清除缓存,二级缓存默认是关闭的要在配置文件里配置
<mapper namespace="mapper.DoLonginMapper">
<cache></cache>
</mapper>
二级缓存是储存在磁盘里的,随着SqlSessionFactory关闭来关闭
2.#与$的区别是#{}里值是安全的,$是字符串拼接的
<!-- <select id="selectProductstest" resultType="Products" parameterType="map">-->
<!-- select * from products where ${pname}=#{value}-->
<!-- </select>-->
在sql语句中#{}不能做为查询的表的列名
3注解有
package mapper;
import Jopo.Category;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface CategoryMapper {
@Select("select *\n" +
" from category\n" +
" order by cid asc")
public List<Category> select();
@Select("insert into category(cid, cname)\n" +
" values (#{cId}, #{cName})")
public int insert(Category category);
@Update("update category\n" +
" set cname=#{cName}\n" +
" where cid = #{cId}")
public int updata(Category category);
@Select(" delete\n" +
" from category\n" +
" where cId = #{cId}")
public int delete(String cId);
@Select(" select *\n" +
" from category\n" +
" where cid = #{id}")
public List<Category> selectbyid(String id);
public List<Category> selectProductsByCid (String id);
@Results(value = {
@Result(column="cid", property="cId",id = true),
@Result( column="cname" ,property="cName"),
@Result(column = "cid" ,property = "list",many = @Many(
select = "mapper.ProductsMapper.selectProductsByCid"
)
)
})
@Select("select *\n" +
" from category\n" +
" where cid = #{cid}")
public List<Category> selectProductsByCidv2 (String id);
}