一、目录展示

  

二、导入依赖

  

三、配置文件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的更多相关文章

  1. springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件

    整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...

  2. Spring学习总结(六)——Spring整合MyBatis完整示例

    为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简 ...

  3. Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二

    接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...

  4. SpringMVC入门二: 1规范结构, 2简单整合MyBatis

    昨天拿springMVC写的helloworld结构不好, 这次先调整一下体系结构 , 然后简单整合一下MyBatis spring的配置还是以注解为主, 不过MyBatis的映射文件什么的还是拿xm ...

  5. 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  6. 2017年2月16日 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  7. Spring Boot 整合 MyBatis

    前言 现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便 ...

  8. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  9. 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 ...

随机推荐

  1. 【tf.keras】实现 F1 score、precision、recall 等 metric

    tf.keras.metric 里面竟然没有实现 F1 score.recall.precision 等指标,一开始觉得真不可思议.但这是有原因的,这些指标在 batch-wise 上计算都没有意义, ...

  2. 浅谈ZooKeeper基本原理与源码分析

    最近一直有小伙伴私信我,问一些关于Zookeeper的知识,下边关于的Zookeeper的知识整理了一下,一起学习一下. 看完本文对于Zookeeper想深入全面了解的读者朋友们,小编这里整理了一份更 ...

  3. PHP如何获取视频总时长与码率等信息

    利用PHP中的FFmpeg读取视频播放时长与码率等信息   function getVideoInfo($file) {    define('FFMPEG_PATH', '/usr/local/ff ...

  4. 检测是否引入jQuery

    if (typeof jQuery != 'undefined') { document.write("jquery已经被加载"); } else { document.write ...

  5. 让微信推送Jenkins构建消息

    Jenkins作为开发必备之神器,各家大小公司都在使用.Jenkins自身内置了基于邮件推送构建结果的功能.但是随着移动互联网的发展,邮件这玩意已经越来越少使用了,是否有一种办法能把jenkins构建 ...

  6. MySQL必知必会(Select, Order by子句)

    SELECT prod_name FROM products ORDER BY prod_name; SELECT prod_id, prod_price, prod_name FROM produc ...

  7. 09-Python-Socket编程

    一.Python-Socket编程 1.1.弄懂HTTP.Socket.TCP这几个概念 什么是HTTP协议?浏览器的本质就是一个socket客户端遵循HTTP协议,HTTP协议的本质:通过\r\n分 ...

  8. iOS包管理工具Cocoapods的安装与使用

    转自:http://www.sxt.cn/u/10014/blog/6448 在我们开发移动应用的时候,一般都会使用到第三方工具,而由于第三方类库的种类繁多,我们在项目中进行管理也会相对麻烦,所以此时 ...

  9. [TimLinux] JavaScript BOM浏览器对象模型

    1. 简介 ECMAScript是JavaScript的核心,但是如果要在WEB中使用JavaScript,那么BOM则无疑才是真的的核心.BOM提供了很多对象,用于访问浏览器的功能,这些功能与任何网 ...

  10. promise 进阶 —— async / await 结合 bluebird

    一.背景 1.Node.js 异步控制 在之前写的 callback vs async.js vs promise vs async / await 里,我介绍了 ES6 的 promise 和 ES ...