1、mybatis一级缓存二级缓存的区别?2、mybatis中#与$的区别?3、mybatis注解有哪些?

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值