MyBatis的增删改查操作
搭建好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的增删改查操作的更多相关文章
- 学习MyBatis必知必会(5)~了解myBatis的作用域和生命周期并抽取工具类MyBatisUtil、mybatis执行增删改查操作
一.了解myBatis的作用域和生命周期[错误的使用会导致非常严重的并发问题] (1)SqlSessionFactoryBuilder [ 作用:仅仅是用来创建SqlSessionFactory,作用 ...
- MyBatis批量增删改查操作
前文我们介绍了MyBatis基本的增删该查操作,本文介绍批量的增删改查操作.前文地址:http://blog.csdn.net/mahoking/article/details/43673741 ...
- Mybatis之增删改查操作
准备工作 建立整体项目目录 新建一个java工程,创建如下工程目录 其中com.kang.pojo中存放pojo类,com.kang.test中存放测试类. 源码目录config中存放Mybatis的 ...
- MyBatis学习之简单增删改查操作、MyBatis存储过程、MyBatis分页、MyBatis一对一、MyBatis一对多
一.用到的实体类如下: Student.java package com.company.entity; import java.io.Serializable; import java.util.D ...
- 从0开始完成SpringBoot+Mybatis实现增删改查
1.准备知识: 1)需要掌握的知识: Java基础,JavaWeb开发基础,Spring基础(没有Spring的基础也可以,接触过Spring最好),ajax,Jquery,Mybatis. 2)项目 ...
- mongoVUE的增删改查操作使用说明
mongoVUE的增删改查操作使用说明 一. 查询 1. 精确查询 1)右键点击集合名,再左键点击Find 或者直接点击工具栏上的Find 2)查询界面,包括四个区域 {Find}区,查询条件格式{& ...
- (转)SQLite数据库增删改查操作
原文:http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059182.html SQLite数据库增删改查操作 一.使用嵌入式关系型SQLite数 ...
- 详谈easyui datagrid增删改查操作
转自:http://blog.csdn.net/abauch_d/article/details/7734395 前几天我把easyui dadtagrid的增删改查的实现代码贴了出来,发现访问量达到 ...
- PHP程序中使用PDO对象实现对数据库的增删改查操作的示例代码
PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty) dbconn.php <?php //------------------------使用PDO方式连接数据库文件- ...
随机推荐
- Codeforces 1159E(拓扑序、思路)
要点 序列上各位置之间的关系常用连边的手段转化为图的问题. 经过一番举例探索不难发现当存在两条有向边交叉时是非法的. -1是模糊的,也就是填多少都可以,那为了尽量避免交叉我们贪心地让它后面那个连它就行 ...
- Git关于Tag操作
Git关于tag的操作 记录下git关于 tag的操作 列出所有标签 git tag : 列出所有的 git tag -l 'v1.2.4.*' : 最后一位任意匹配 新建标签 git tag -a ...
- ]NET Core Lucene.net和PanGu分词实现全文检索
Lucene.net和PanGu分词实现全文检索 Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考 前言:目前自己在做使用Lucene. ...
- centos下svnadmin的部署过程
1. 安装SVN #yum –y install subversion 2. 安装openjdk #yum –y list java* #yum –y install java-1.8.0 ...
- P3290 寻找第K大数
描述 寻找第K大数 N个小朋友在一起做游戏.每个小朋友在自己的硬纸板上写一个数,然后同时举起来.接着,小y老师提一个问题,看哪个小朋友先抢答出来.问题是:在这N个数中,第K大的是哪个数?请你编程完成. ...
- H5的storage(sessionstorage&localStorage)简单存储删除
众所周知,H5的storage有sessionstorage&localStorage,其中他们的共同特点是API相同 下面直接上代码,storage中的存储与删除: <!DOCTYPE ...
- redis 大批量数据插入导致MISCONF Redis is configured to save RDB snapshots的解决
PS:之前写过一遍,那个方法没有彻底解决,现找到真正的解决方法 环境:redis 3.2.100 windows版(注意!!!这是关键),win10,redis客户端spring boot 2.0.7 ...
- Bibtex使用介绍
BibTeX 是一种格式和一个程序, 用于协调LaTeX的参考文献处理. BibTeX 使用数据库的的方式来管理参考文献. BibTeX 文件的后缀名为 .bib . 先来看一个例子 @article ...
- freebsd问题
http://community.spiceworks.com/topic/91708-server-freezes
- Azure 镜像市场支持一键部署到云
本视频教程介绍了Azure 镜像市场和一键部署到云. Azure 镜像市场(AMP)由世纪互联运营,是一个联机应用程序和服务市场,它通过独立软件服务商(ISV)能够成为 Azure 客户(Custom ...