
mybatis
syf_wfl
java
展开
-
Mybatis主配置xml文件映射mapper文件的两种方法
<mappers> <!-- 第一种方式指定mapper文件,有多少个就需要写多少行 resource为xml文件所在的类路径--> <mapper resource="org/example/Dao/StudentDao.xml"/> <!-- 第二种使用包名 name:XML文件(mapper文件)所在的包名,这个包中的所有XML文件一次都能加载给mybatis配置文件 使用pack...原创 2021-01-22 16:12:17 · 1043 阅读 · 0 评论 -
mybatis中使用分页PageHelper
1.在porm中加入PageHelper的依赖。 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency> 2.在著配置文件中配置插件,在environments原创 2021-01-22 16:09:43 · 68 阅读 · 0 评论 -
Mybatis中将驱动、用户名、url和密码用properties文件存放引用方法
1、在resources文件夹中创建一个.properties文件,存放以下信息(这是我的数据库连接信息)放自己的,一般只改第二个和第三四。 jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/syfwfl jdbc.user=root jdbc.password=19980605 2、在mybatis主配置文件中的configuration加入以下代码。 <!-- 指定properties位置,从类原创 2021-01-22 15:24:44 · 444 阅读 · 0 评论 -
Mybatis中动态Sql的if、for和foreach使用
//where使用接口中定义的方法 List<Student> SelAll2(Student student); where和if联合使用,当if中test条件成立时,才会将标签体的内容拼接在SQL语句中 <!-- where--> <select id="SelAll2" resultType="org.example.Entity.Student"> select id,name,email,age from stud...原创 2021-01-22 14:31:51 · 3195 阅读 · 1 评论 -
Mybatis中的Like两种模糊查询
<!-- 第一种模糊查询,送进来之前已经拼接好--> <select id="selMoHu" resultType="org.example.Entity.Student"> select id,name,email,age from student where name like #{SN} </select> <!-- 第二种:在mapper文件中拼接like内容--> <select id="s原创 2021-01-21 20:03:58 · 195 阅读 · 0 评论 -
Mybatis中的全限定名称别名,以及#和$的不同
在mybatis主配置文件configuration中加入typeAliases标签。 有以下两种方法。 <typeAliases> <!-- 可以指定一个类型一个自定义别名 type:自定义类型的全限定名称 alias:别名(短小,容易记忆) --> <typeAlias type="org.example.Entity.Student" alias="stu"/> &原创 2021-01-21 18:50:41 · 595 阅读 · 0 评论 -
Mybatis当数据库属性名字和java对象属性名字不一样时,2种查询方法
mapper文件的配置 <!-- 在mapper文件中创建resultMap,其中id为自定义,type为返回类型的全限定名称 里面的标签id为主键,其余为result --> <resultMap id="GetMap" type="org.example.Entity.Student"> <id column="id" property="Sid"/> <result column="name" pr原创 2021-01-21 18:46:00 · 381 阅读 · 0 评论 -
Mybatis传参数两种方法
接口里面的两种,一种是多个参数传入,另一种是传进去的一个java对象 //@param()里面的名字就是mapper文件里面传入参数的名字 public List<Student> SelMulStu(@Param("myid") int id, @Param("myage") int age); //多个参数使用java对象作为接口中的方法 List<Student> SelMutObj(Q原创 2021-01-21 13:34:12 · 318 阅读 · 1 评论 -
Maven中的Servelet依赖,Mybatis依赖,Mysql依赖,以及两个xml配置文件
<!--Servlet依赖声明开始(2个)--> <dependency> <groupId>jakarta.servlet.jsp</groupId> <artifactId>jakarta.servlet.jsp-api</artifactId> <version>3.0.0</version> <scope>provided</sco原创 2021-01-20 21:30:58 · 535 阅读 · 0 评论 -
Mybatis封装简化
引用该封装后,在测试中只需创建SqlSession 还有定位的String,然后用SqlSession定义的变量选择方式即可,记住关闭。 package utils; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.Sq原创 2021-01-20 21:18:52 · 105 阅读 · 1 评论 -
Mybatis的两个xml配置文件和test文件
Dao中的xml文件代码 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.example.Dao.StudentDao"> <selec原创 2021-01-20 19:02:00 · 658 阅读 · 0 评论