SpringBBoot整合MyBatis
一、目录展示

二、导入依赖

三、配置文件application.yml

四、Student实体类
package com.zn.entity;
public class Student {
private Integer stu_id;
private String stu_name; @Override
public String toString() {
return "Student{" +
"stu_id=" + stu_id +
", stu_name='" + stu_name + '\'' +
'}';
} public Student() {
} public Student(String stu_name) {
this.stu_name = stu_name;
} public Student(Integer stu_id, String stu_name) {
this.stu_id = stu_id;
this.stu_name = stu_name;
} public Integer getStu_id() {
return stu_id;
} public void setStu_id(Integer stu_id) {
this.stu_id = stu_id;
} public String getStu_name() {
return stu_name;
} public void setStu_name(String stu_name) {
this.stu_name = stu_name;
}
}
五、StudentDao层
package com.zn.dao; import com.zn.entity.Student;
import org.springframework.stereotype.Repository; import java.util.List; @Repository
public interface StudentDao { //添加数据
int insertStudent(Student student); //修改数据
int updateStudent(Student student); //删除数据
int deleteStudent(Integer id); //查询数据
List<Student> findAll();
}
六、resources下的mapper中的StudentDao.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="com.zn.dao.StudentDao" >
<!--添加数据-->
<insert id="insertStudent">
insert into studentinfo(stu_name) values(#{stu_name})
</insert> <!--修改数据-->
<update id="updateStudent">
update studentinfo set stu_name=#{stu_name} where stu_id=#{stu_id}
</update> <!--删除数据-->
<delete id="deleteStudent">
delete from studentinfo where stu_id=#{stu_id}
</delete> <!--查询数据-->
<select id="findAll" resultType="com.zn.entity.Student">
select * from studentinfo
</select>
</mapper>
七、StudentService层
package com.zn.service; import com.zn.dao.StudentDao;
import com.zn.entity.Student;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.List; @Service
public class StudentService { @Resource
StudentDao studentDao; //增加数据
public int insertStudent(Student student) {
return studentDao.insertStudent(student);
} //修改数据
public int updateStudent(Student student) {
return studentDao.updateStudent(student);
} //删除数据
public int deleteStudent(Integer id) {
return studentDao.deleteStudent(id);
} //查询数据
public List<Student> findAll(){
return studentDao.findAll();
}
}
八、StudentController层
package com.zn.controller; import com.zn.entity.Student;
import com.zn.service.StudentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource;
import java.util.List; @RestController
public class StudentController { @Resource
StudentService studentService; //添加数据
@RequestMapping("/insertStudent")
public int insertStudent(){
return studentService.insertStudent(new Student("刘姐"));
} //修改数据
@RequestMapping("/updateStudent")
public int updateStudent(){
return studentService.updateStudent(new Student(5,"小傻子"));
} //删除数据
@RequestMapping("/deleteStudent")
public int deleteStudent(){
return studentService.deleteStudent(4);
} //查询数据
@RequestMapping("/findAll")
public List<Student> findAll(){
return studentService.findAll();
}
}
九、测试类

十、效果展示
省略增删改效果
(1)查询数据

SpringBBoot整合MyBatis的更多相关文章
- springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件
整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...
- Spring学习总结(六)——Spring整合MyBatis完整示例
为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简 ...
- Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二
接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...
- SpringMVC入门二: 1规范结构, 2简单整合MyBatis
昨天拿springMVC写的helloworld结构不好, 这次先调整一下体系结构 , 然后简单整合一下MyBatis spring的配置还是以注解为主, 不过MyBatis的映射文件什么的还是拿xm ...
- 分析下为什么spring 整合mybatis后为啥用不上session缓存
因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...
- 2017年2月16日 分析下为什么spring 整合mybatis后为啥用不上session缓存
因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...
- Spring Boot 整合 MyBatis
前言 现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便 ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path reso ...
随机推荐
- drf目录
drf目录 1 web接口与restful规范 2 django中的restful规范 3 CBV请求分析 4 请求模块分析 5 响应模块分析 6 异常模块 7 解析模块 8 序列化类 9 视图组件 ...
- Chapter 07-Basic statistics(Part4 t-tests&&nonparametric tests of group difference)
一. t-tests 这一部分我们使用分布在MASS包中的UScrime数据集.它是关于美国47个州在1960年时,关于惩罚制度对犯罪率的影响. Prob:监禁(坐牢)的概率: U1:14到24岁的城 ...
- mysql那些事(5)建表存储引擎的选择
在mysql见表的时候,会遇到选择存储引擎:MyISAM和InnoDB.究竟用哪种存储引擎好呢? 1.MyISAM:表锁:支持全文索引:读并发性能较好. 2.InnoDB:行锁:支持事务,支持外键:写 ...
- JavaScript实现返回顶部效果
仿淘宝回到顶部效果 需求:当滚动条到一定位置时侧边栏固定在某个位置,再往下滑动到某一位置时显示回到顶部按钮.点击按钮后页面会动态滑到顶部,速度由快到慢向上滑. 思路: 1.页面加载完毕才能执行js代码 ...
- 【原创】002 | 搭上SpringBoot事务源码分析专车
前言 如果这是你第二次看到师长,说明你在觊觎我的美色! 点赞+关注再看,养成习惯 没别的意思,就是需要你的窥屏^_^ 专车介绍** 该趟专车是开往Spring Boot事务源码分析的专车 专车问题 为 ...
- python上下文管理器细读
test 1 上下文管理器,将生成器转化为上下文管理器 import contextlib @contextlib.contextmanager def a(): print(1) yield pri ...
- mint UI MessageBox 使用
一.全局注册 1.在main.js中引入 //引入 import { MessageBox } from 'mint-ui'; //全局使用,挂载到原型上 Vue.prototype.$messa ...
- P4072 [SDOI2016](BZOJ4518) 征途 [斜率优化DP]
题目描述 Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜.所以,一段路 ...
- HDU-3727 Jewel
Jimmy wants to make a special necklace for his girlfriend. He bought many beads with various sizes, ...
- nginx的一些知识(一)
第8章 web网站的搭建 curl -Lv 网站地址:查看网站的请求信息和响应信息,并且会将结果输出出来 8.1 web网站的的传输原理过程 会进行DNS的解析 进行客户端和服务端进行三次握手协议 客 ...