摘要: log4j 阅读全文
posted @ 2021-12-17 19:52 卡卡发 阅读(30) 评论(0) 推荐(0)
摘要: 解决属性名和字段名不一致的问题 解决办法: 1.起别名 2.resultMap 结果集映射 一个例子: <!-- resultMap最终还是要将结果映射到pojo上,type就是指定映射到哪一个pojo --> <!-- id:设置ResultMap的id --> <resultMap type=" 阅读全文
posted @ 2021-12-17 17:01 卡卡发 阅读(34) 评论(0) 推荐(0)
摘要: ![](https://img2020.cnblogs.com/blog/2181692/202112/2181692-20211217160620030-362666689.png) ![](https://img2020.cnblogs.com/blog/2181692/202112/2181692-20211217160703642-1089726659.png) ![](https://i 阅读全文
posted @ 2021-12-17 16:08 卡卡发 阅读(33) 评论(0) 推荐(0)
摘要: 注册绑定mapper文件 1.方式一:推荐使用 <mappers> <mapper resource="com/kakafa/dao/UserMapper.xml"/> </mappers> 2.方式二:用class文件绑定注册 <mappers> <mapper class="com.kakafa 阅读全文
posted @ 2021-12-17 15:55 卡卡发 阅读(72) 评论(0) 推荐(0)
摘要: 配置要按照顺序来: 1.给实体类起别名: 2.也可以给实体类起别名:MyBatis会在指定的包名下搜索需要的JavaBean,默认的别名即为这个类的类名,首字母小写! 在实体类比较多的时候建议使用第二种,但是第一种可以自定义别名;第二种不行,其默认别名就是首字母小写的类名。 如果第二种非要自定义名字 阅读全文
posted @ 2021-12-17 15:32 卡卡发 阅读(90) 评论(0) 推荐(0)
摘要: 1.环境配置environments myBatis可以配置成适应多种环境,但是每个sqlSessionFactory实例只能选择一种环境 myBatis默认事务管理器时jdbc,连接池:pooled 2.属性properties 外部配置文件 db.properties: driver=com.m 阅读全文
posted @ 2021-12-17 14:40 卡卡发 阅读(55) 评论(0) 推荐(0)
摘要: 假设实体类或者数据库中的表,参数字段太多,我们应当使用Map,这样只需要修改或者插入需要的几个参数即可。 1.map 以插入为例子如下: 原来: 使用map: 测试: @Test public void addUser2(){ SqlSession sqlSession = MybatisUtils 阅读全文
posted @ 2021-12-17 10:57 卡卡发 阅读(97) 评论(0) 推荐(0)
摘要: mybatis-config.xml核心配置文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis. 阅读全文
posted @ 2021-12-17 10:15 卡卡发 阅读(69) 评论(0) 推荐(0)