随笔分类 -  Mybatis入门过程记录

摘要:Mybatis 源码 1、注解与mapper同时存在,不会覆盖直接报错 2、#{} 静态SQL (安全,防止SQL注入) ${}动态SQL 3、param参数 阅读全文
posted @ 2020-12-12 22:58 Spring_Xian 阅读(84) 评论(0) 推荐(0)
摘要:<select id="queryBookByName" resultType="Books"> select * from ssmbuild.books where bookName like CONCAT('%',#{bookName},'%') </select> CONCAT('%',#{b 阅读全文
posted @ 2020-09-29 19:43 Spring_Xian 阅读(201) 评论(0) 推荐(0)
摘要:<if> 相当于java中的if,用于单分支的条件判断 <choose>、<when>、<otherwise> 相当于java中的switch...case...default,用于多分支的条件判断,从多个选项中选择一个 <foreach> 循环,常和sql的in语句搭配使用 <where>、<tr 阅读全文
posted @ 2020-08-20 22:27 Spring_Xian 阅读(150) 评论(0) 推荐(0)
摘要:1、开启缓存(二级缓存) <settings> <setting name="logImpl" value="LOG4J"/> <setting name="cacheEnabled" value="true"/> </settings> 2、对应Mapper中只需添加一步 <cache /> 完成 阅读全文
posted @ 2020-08-19 21:44 Spring_Xian 阅读(73) 评论(0) 推荐(0)
摘要:前情提要:Student和Teacher表,student,tid关联老师的tid 一对多 一个老师对应多个学生 老师和学生的接口,在两个文件里,太短了,就放在一起 public interface TeacherMapper { List<Teacher> selectTeacher(@Param 阅读全文
posted @ 2020-08-17 16:13 Spring_Xian 阅读(120) 评论(0) 推荐(0)
摘要:注解完成增删改查非常的简单,但是也只能完成一些简单的,不建议使用,建议使用xml文件配置(了解) mybatis-config.xml,utils,pojo都一样这里就不重复了最重要的是UserMapper.class public interface UserMapper { //查询所有 @Se 阅读全文
posted @ 2020-07-06 19:20 Spring_Xian 阅读(151) 评论(0) 推荐(0)
摘要:分页查询对比正常的查询差别不大,只是在sql语句上有区别 userMapper.class文件 //limit分页List<User> limit(Map<String,Integer> map); User mapper.xml 文件下映射对应文件 <select id="limit" param 阅读全文
posted @ 2020-07-05 16:19 Spring_Xian 阅读(1895) 评论(0) 推荐(0)
摘要:在User Mapper.xml文件下 1 <select id="getUserById" resultType="com.xian.pojo.User"> 2 select * from testdb.test001 where id=#{id} 3 </select> com.xian.poj 阅读全文
posted @ 2020-07-04 15:24 Spring_Xian 阅读(152) 评论(0) 推荐(0)
摘要:入门的时候感觉写了很多的代码,其实这些并不多 接下来对之前写的代码进行优化 首先Mybatis-config.xml 1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE configuration 3 PUBLIC "-//mybatis.or 阅读全文
posted @ 2020-07-03 16:24 Spring_Xian 阅读(141) 评论(0) 推荐(0)
摘要:1.浏览器打开Mybatis官网,跟着入门教程走 1.1 新建maven项目 删除src文件作为父项目 1.2 在pom.xml文件下导入依赖 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache 阅读全文
posted @ 2020-07-01 19:48 Spring_Xian 阅读(217) 评论(0) 推荐(0)
摘要:<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includ 阅读全文
posted @ 2020-07-01 19:13 Spring_Xian 阅读(1624) 评论(0) 推荐(1)