搭建好mybatis之后 进行对数据库的操作

  添加语句

  在映射文件中添加语句

  insert into student(name,age,score) values(#{name},#{age},#{score})

  映射文件要放在与接口一个目录下

  namespace:必须是对应接口的全限定名

  id :dao中的方法名字

  parameterType:传入的参数类型 可以省略

  添加语句后 获取主键的值 赋值给主键

  insert into student(name,age,score) values(#{name},#{age},#{score})

  select @@identity

  2.删除语句

  update student set name=#{name} ,age=#{age},score=#{score}

  where id = #{id}

  3.查询语句

  /**

  * 静态参数

  * @param student

  */

  void insertStudent(StudentBean student);

  List selectStudentAll();

  //根据姓名模糊查询

  List selectStudentByName(String name);

  //多参数查询 使用map作为方法参数

  List selectStuByMap1(Map map);

  List selectStuByMap2(Map map);

  List selectStuByParameters1(String name , int age);

  List selectStuByParameters2(String name , StudentBean student);

  List selectStuByParameters3(@Param("name") String name , @Param("age")int age);

  List selectStuByParameters4(@Param("name") String name , @Param("student") StudentBean student);

  select * from student

  select * from student where name like '%' #{name} '%'

  select * from student where name like '%' #{name} '%' and age>#{age}

  select * from student where name like '%' #{name} '%' and age > #{student.age}

  select * from student where name like '%' #{0} '%' and age > #{1}

  select * from student where name like '%' #{0} '%' and age > #{1.age}

  动态参数

  /**

  * 动态参数

  */

  //mybatis 动态参数类似域jstl《c:》

  //if拼接 sql语句要跟上 where 1 =1

  List selectStudentByIf(StudentBean student);

  select * from student where 1=1

  and name like '%' #{name} '%'

  and age > #{age}

  //不生成 1= 1 提高效率 自动在sql语句拼接的时候加上where 关键字

  List selectStudentByWhere(StudentBean student);

  select * from student

  and name like '%' #{name} '%'

  and age > #{age}

  //多选一无锡人流医院 http://www.bhnfkyy.com/

  List selectStudentByChoose(StudentBean student);

  select * from student

  where name like '%' #{name} '%'

  where age > #{age}

  where 1 = 2

  List selectStudentByForeachArray(int[] ids);

  select * from student

  where id in

  #{id}

  List selectStudentByForeachList(List ids);

  select * from student

  where id in

  #{id}

  List selectStudentByForeachStudent(List students);

  select * from student

  where id in

  #{student.id}

  List selectStudentBySqlFragement();

  select student

  * from

  //统计一张表的总数据条数 分页的总条数

  int selectStudentCount();

  select count(*) from student

MyBatis的增删改查操作的更多相关文章

  1. 学习MyBatis必知必会(5)~了解myBatis的作用域和生命周期并抽取工具类MyBatisUtil、mybatis执行增删改查操作

    一.了解myBatis的作用域和生命周期[错误的使用会导致非常严重的并发问题] (1)SqlSessionFactoryBuilder [ 作用:仅仅是用来创建SqlSessionFactory,作用 ...

  2. MyBatis批量增删改查操作

      前文我们介绍了MyBatis基本的增删该查操作,本文介绍批量的增删改查操作.前文地址:http://blog.csdn.net/mahoking/article/details/43673741 ...

  3. Mybatis之增删改查操作

    准备工作 建立整体项目目录 新建一个java工程,创建如下工程目录 其中com.kang.pojo中存放pojo类,com.kang.test中存放测试类. 源码目录config中存放Mybatis的 ...

  4. MyBatis学习之简单增删改查操作、MyBatis存储过程、MyBatis分页、MyBatis一对一、MyBatis一对多

    一.用到的实体类如下: Student.java package com.company.entity; import java.io.Serializable; import java.util.D ...

  5. 从0开始完成SpringBoot+Mybatis实现增删改查

    1.准备知识: 1)需要掌握的知识: Java基础,JavaWeb开发基础,Spring基础(没有Spring的基础也可以,接触过Spring最好),ajax,Jquery,Mybatis. 2)项目 ...

  6. mongoVUE的增删改查操作使用说明

    mongoVUE的增删改查操作使用说明 一. 查询 1. 精确查询 1)右键点击集合名,再左键点击Find 或者直接点击工具栏上的Find 2)查询界面,包括四个区域 {Find}区,查询条件格式{& ...

  7. (转)SQLite数据库增删改查操作

    原文:http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059182.html SQLite数据库增删改查操作 一.使用嵌入式关系型SQLite数 ...

  8. 详谈easyui datagrid增删改查操作

    转自:http://blog.csdn.net/abauch_d/article/details/7734395 前几天我把easyui dadtagrid的增删改查的实现代码贴了出来,发现访问量达到 ...

  9. PHP程序中使用PDO对象实现对数据库的增删改查操作的示例代码

    PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty) dbconn.php <?php //------------------------使用PDO方式连接数据库文件- ...

随机推荐

  1. ASP.NET Core Linux

    环境说明 CentOS / 7.1 (64bit) (Linux操作系统) 3MySQL5.7(网站应用数据库) .NET Core SDK 2.0.0(网站应用环境) Nginx(反向代理服务器) ...

  2. sqlserver 数据库 的数据库个数统计 表个数统计 表的数据量统计(转载)

    http://www.cnblogs.com/qinche/archive/2012/08/09/app.html 由于今天要监控数据,急需统计实例中1有多少库2库里有多少表3每个表有多少数据 --将 ...

  3. python3 socke 服务端与客户端实现(回炉)

    #服务端#!/usr/bin/env python3 # -*- coding:utf-8 -*- from socket import * # 创建socket tcpSerSocket = soc ...

  4. RSA_new()初始化和RSA_free()释放RSA结构体后依然会有内存泄漏(转)

    在使用OpenSSL的RSA加解密的时候,发现RSA_new()初始化和RSA_free()释放RSA结构体后依然会有内存泄漏.网上Baidu.Google之,发现这个相关信息很少(至少中文搜索结果是 ...

  5. (二)我的JavaScript系列:JavaScript面向对象旅程(下)

    剪不断,理还乱,是离愁. 前面已经提到过新语言开发的两个步骤,分别是:一.定义基本的数据类型,完善结构化编程语言的设计:二.为函数类型绑定this的概念,好在对象的方法中可以引用到对象自身.下面是继续 ...

  6. 在Office 365 添加就地保留用户邮箱

    基于客户需求,要求将用户批量添加到Office 365中的现有就地保留.如您所了解的,我们可以通过Exchange在线图形用户GUI界面完成,也可以通过PowerShell完成. 要将用户批量添加到O ...

  7. APP自动化测试

    CTS工具,主要是基于Androidinstrumentation和JUnit测试原理推单元测试用例: Monkey用来对UI进行压力测试,伪随机的模拟用户的按键输入,触摸屏输入,手势输入等: ASE ...

  8. 用代码判断当前系统是否支持某个版本的feature

    JDK9已经出来有一段时间了,因此很多流行的Java应用纷纷增添了对JDK9乃至JDK10的支持,比如Tomcat. 我们通过这个链接下载最新的Tomcat源文件包,总共7MB: https://to ...

  9. Java 设计模式之中介者模式

    本文继续23种设计模式系列之中介者模式.   定义 用一个中介者对象封装一系列的对象交互,中介者使各对象不需要显示地相互作用,从而使耦合松散,而且可以独立地改变它们之间的交互.   角色 抽象中介者: ...

  10. 小技巧:unicode RLO

    unicode 控制字符 RLO 可以将位于其后的文字翻转. 于是可以被病毒利用. 如图 重命名文件,在gpj前插入unicode RLO,之后若不小心,可能会被欺骗,误以为是jpg文件. 如果修改程 ...