
mybatis
z-m-k
这个作者很懒,什么都没留下…
展开
-
Mybatis的简单使用
1、首先配置mybatis的配置文件,基本配置如下: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-conf...原创 2019-03-02 14:45:10 · 138 阅读 · 0 评论 -
mybatis中的映射器的使用
这里通过举例来说明 !!!!注意:当使用注解的时候,mappers中配置的应该是mapper所在的包,而使用xml时,应该对应的是mapper.xml所对应的目录,而且要将mapper.xml文件放在src目录下,maven项目中要放在resource下 这里声明一个POJO:Role package pojo; public class Role { private int id;...原创 2019-03-02 16:19:58 · 351 阅读 · 0 评论 -
mybatis中分页类RowBounds的使用
在mapper.xml中使用sql配置: <select id="getRolesByrowBounds" resultType="pojo.Role"> select id,role_name as roleName,note from t_role </select> 在mapper接口中配置参数: public List&l...原创 2019-03-02 16:49:22 · 1607 阅读 · 0 评论 -
mybatis中琐碎的小知识点
1、插入时的主键回填问题 答:只要在insert的sql语句中,将属性useGeneratedKeys设置为true和设置keyProperty即可,其中useGeneratedKeys,代表启动获取主键功能,keyProperty,代表将生成的主键放在哪一个属性中 2、自定义主键问题 答:在insert的sql语句中添加如下语句: <insert id="addRole" param...原创 2019-03-02 17:12:40 · 118 阅读 · 0 评论 -
Mybatis 中$与#的区别
Mybatis 中$与#的区别 1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端把id值1,传入到后台的时候,就相当于select id,name,age from student where id ='1'. 2 $是将传入的数据直接显示生成sql语句,eg:select id,name...转载 2019-03-02 17:21:36 · 117 阅读 · 0 评论 -
mybatis中的resultMap元素和级联
Mybaits中的级联分为三种: 鉴别器:根据某些条件决定采用具体的实现方案 一对一:比如学生和学生证 一对多:比如班主任和学生 鉴别器配置: <select id="getRoleByDiscriminator" parameterType="int" resultMap="discriminator"> select...原创 2019-03-04 12:39:04 · 445 阅读 · 0 评论 -
mybatis中的存储过程
这里只强调下存储过程如何编写,其调用过程可以通过将其参数构建成一个类,来进行通常使用 存储过程示例: createor replace procedureName(param1 in varchar,param2 outvarchar,params3out date) IS BEGIN select count(*) into param2 from t_role where role_n...原创 2019-03-04 12:54:44 · 360 阅读 · 0 评论 -
mybatis中的动态sql
if元素用法: <select id="getRoleAndUsers" parameterType="int" resultMap="getRoleByCascade2"> select id ,role_name as roleName ,note from t_role where id = #{id} <if test="ro...原创 2019-03-04 13:41:15 · 175 阅读 · 0 评论