Mybatis使用注解进行增删改查
// 增
public interface StudentMapper{
@Insert("insert into student (stud_id, name, email, addr_id, phone)values(#{studId},#{name},#{email},#{address.addrId},#{phone})")
int insertStudent(Student student);
}
public interface StudentMapper{
@Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})")
@Options(useGeneratedKeys=true,keyProperty="studId")
int insertStudent(Student student);
}
public interface StudentMapper{
@Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})")
@SelectKey(statement="select stud_id_seq.nextval from dual",keyProperty="studId",resultType=int.calss,before=true)
int insertStudent(Student student);
}
// 改
@Update("update students set name=#{name},email=#{email}")
int updateStudent(Student student);
// 删
@Delete("delete form students where stud_id=#{studId}")
int deleteStudent(int studId)
// 查
@Select("select name,email,phone from students where stud_id=#{studId}")
Student findStudentById(Integer studId);
推荐使用xml文件进行配置,方面后续修改容易
Mybatis使用注解进行增删改查的更多相关文章
- Spring Boot 使用Mybatis注解开发增删改查
使用逆向工程是遇到的错误 错误描述 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): c ...
- Mybatis_3.基于注解的增删改查
1.实体类User.java public class User { private int id; private String name; private int age; //getter.se ...
- MyBatis学习系列二——增删改查
目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring 数据库的经典操作:增删改查. 在这一章我们主要说明一下简单的查询和增删改, ...
- Mybatis实现数据的增删改查
Mybatis实现数据的增删改查 1.项目结构(使用maven创建项目) 2.App.java package com.GetcharZp.MyBatisStudy; import java.io.I ...
- SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成增删改查逻辑
习惯使用jpa操作对象的方式,现在用mybatis有点不习惯. 其实是懒得写SQL,增删改查那么简单的事情你帮我做了呗,mybatis:NO. 没办法,自己搞喽! 这里主要是实现了通过代码自动生成my ...
- MyBatis学习--简单的增删改查
jdbc程序 在学习MyBatis的时候先简单了解下JDBC编程的方式,我们以一个简单的查询为例,使用JDBC编程,如下: Public static void main(String[] args) ...
- idea+spring4+springmvc+mybatis+maven实现简单增删改查CRUD
在学习spring4+springmvc+mybatis的ssm框架,idea整合简单实现增删改查功能,在这里记录一下. 原文在这里:https://my.oschina.net/finchxu/bl ...
- SSM-MyBatis-02:Mybatis最基础的增删改查(查全部和查单独一个)
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 继续上次的开始,这次记录的是增删改查,上次重复过的代码不做过多解释 首先先创建mysql的表和实体类Book ...
- Mybatis实现部门表增删改查以及排序
废话不说,直接开门见山! 需要在WebContent下的lib下导入两个包 mybatis-3.2.5.jar ojdbc6.jar package com.xdl.entity; import ja ...
随机推荐
- hdu 1075 What Are You Talking About(map)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 51nod-1273: 旅行计划
[传送门:51nod-1273] 简要题意: 给出一棵树,点数为n,现在你有一个旅行计划,从k城市出发,每天前往一个没去过的城市,并且旅途中经过的没有去过的城市尽可能的多(如果有2条路线,经过的没有去 ...
- PHP 二维数组去掉重复值并保持原结构
PHP 二维数组去掉重复值并保持原结构 直接上代码,解释很详细 //二维数组去掉重复值 function arrunique($a){ foreach($a[0] as $k => $v){ / ...
- thinkphp5.0的验证码安装和相关错误
thinkphp5.0的验证码安装和相关错误 问题 只要是之前使用thinkphp5框架搭建网站的时候发现不管如何调用验证码都无法使用,按照官网要求,使用composer安装验证码出现报错Fatal ...
- zzulioj--1827--石锅全拌(区间求和水题)
1827: 石锅全拌 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 6 Solved: 3 SubmitStatusWeb Board Descri ...
- 熟悉了下HTTP协议
HTML是一种用来定义网页的文本,会HTML,就可以编写网页: HTTP是在网络上传输HTML的协议,用于浏览器和服务器的通信.200表示一个成功的响应,后面的OK是说明.失败的响应有404 Not ...
- 加载等待loading
自己写的一个小插件,还有很多需要完善... (function ($) { $.fn.StartLoading = function (option) { var defaultV ...
- 《剑指offer》跳台阶
一.题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.输入描述 输入n级台阶 三.输出描述 输出总有多少种不同跳法 四.牛客网提供的框架 cla ...
- 洛谷P2197 nim游戏模板
Code: #include<iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ int ...
- 关于 nginx 的配置的 location
精准匹配和普通匹配: server{ location =/index.htm{ ////精准匹 ...