一、目录展示

  

二、导入依赖

  

三、配置文件application.yml

  

四、Student实体类

  

  1. package com.zn.entity;
  2. public class Student {
  3. private Integer stu_id;
  4. private String stu_name;
  5.  
  6. @Override
  7. public String toString() {
  8. return "Student{" +
  9. "stu_id=" + stu_id +
  10. ", stu_name='" + stu_name + '\'' +
  11. '}';
  12. }
  13.  
  14. public Student() {
  15. }
  16.  
  17. public Student(String stu_name) {
  18. this.stu_name = stu_name;
  19. }
  20.  
  21. public Student(Integer stu_id, String stu_name) {
  22. this.stu_id = stu_id;
  23. this.stu_name = stu_name;
  24. }
  25.  
  26. public Integer getStu_id() {
  27. return stu_id;
  28. }
  29.  
  30. public void setStu_id(Integer stu_id) {
  31. this.stu_id = stu_id;
  32. }
  33.  
  34. public String getStu_name() {
  35. return stu_name;
  36. }
  37.  
  38. public void setStu_name(String stu_name) {
  39. this.stu_name = stu_name;
  40. }
  41. }

五、StudentDao层

  1. package com.zn.dao;
  2.  
  3. import com.zn.entity.Student;
  4. import org.springframework.stereotype.Repository;
  5.  
  6. import java.util.List;
  7.  
  8. @Repository
  9. public interface StudentDao {
  10.  
  11. //添加数据
  12. int insertStudent(Student student);
  13.  
  14. //修改数据
  15. int updateStudent(Student student);
  16.  
  17. //删除数据
  18. int deleteStudent(Integer id);
  19.  
  20. //查询数据
  21. List<Student> findAll();
  22. }

六、resources下的mapper中的StudentDao.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.zn.dao.StudentDao" >
  4. <!--添加数据-->
  5. <insert id="insertStudent">
  6. insert into studentinfo(stu_name) values(#{stu_name})
  7. </insert>
  8.  
  9. <!--修改数据-->
  10. <update id="updateStudent">
  11. update studentinfo set stu_name=#{stu_name} where stu_id=#{stu_id}
  12. </update>
  13.  
  14. <!--删除数据-->
  15. <delete id="deleteStudent">
  16. delete from studentinfo where stu_id=#{stu_id}
  17. </delete>
  18.  
  19. <!--查询数据-->
  20. <select id="findAll" resultType="com.zn.entity.Student">
  21. select * from studentinfo
  22. </select>
  23. </mapper>

七、StudentService层

  1. package com.zn.service;
  2.  
  3. import com.zn.dao.StudentDao;
  4. import com.zn.entity.Student;
  5. import org.springframework.stereotype.Service;
  6.  
  7. import javax.annotation.Resource;
  8. import java.util.List;
  9.  
  10. @Service
  11. public class StudentService {
  12.  
  13. @Resource
  14. StudentDao studentDao;
  15.  
  16. //增加数据
  17. public int insertStudent(Student student) {
  18. return studentDao.insertStudent(student);
  19. }
  20.  
  21. //修改数据
  22. public int updateStudent(Student student) {
  23. return studentDao.updateStudent(student);
  24. }
  25.  
  26. //删除数据
  27. public int deleteStudent(Integer id) {
  28. return studentDao.deleteStudent(id);
  29. }
  30.  
  31. //查询数据
  32. public List<Student> findAll(){
  33. return studentDao.findAll();
  34. }
  35. }

八、StudentController层

  1. package com.zn.controller;
  2.  
  3. import com.zn.entity.Student;
  4. import com.zn.service.StudentService;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7.  
  8. import javax.annotation.Resource;
  9. import java.util.List;
  10.  
  11. @RestController
  12. public class StudentController {
  13.  
  14. @Resource
  15. StudentService studentService;
  16.  
  17. //添加数据
  18. @RequestMapping("/insertStudent")
  19. public int insertStudent(){
  20. return studentService.insertStudent(new Student("刘姐"));
  21. }
  22.  
  23. //修改数据
  24. @RequestMapping("/updateStudent")
  25. public int updateStudent(){
  26. return studentService.updateStudent(new Student(5,"小傻子"));
  27. }
  28.  
  29. //删除数据
  30. @RequestMapping("/deleteStudent")
  31. public int deleteStudent(){
  32. return studentService.deleteStudent(4);
  33. }
  34.  
  35. //查询数据
  36. @RequestMapping("/findAll")
  37. public List<Student> findAll(){
  38. return studentService.findAll();
  39. }
  40. }

九、测试类

  

十、效果展示

  省略增删改效果

  (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. 你真的了解foreach吗?

    引言 有C#基础的,当问到循环有哪些,会毫不犹豫的说出的for.do while.foreach及while这几种,但是到具体实际开发中,我们遇到一些问题,比如:到底选择哪种?为什么选择这种?哪种好像 ...

  2. Spring Boot中使用Jpa的findOne方法不能传入id

    最近通过慕课网学习spring boot,视频中通过jpa的findOne方法以id为参数查询出对应的信息, 而当我自己做测试的时候却发现我的findOne方法的参数没有Integer类型的id,而是 ...

  3. JS&jQuery

    1.JavaScript概述    1.什么是JavaScript        JavaScript简称JS,是一种专门运行于JS解释器/引擎中的解释型脚本语言    2.JS发展史         ...

  4. Spring Data JPA 条件查询的关键字

    Spring Data JPA 为此提供了一些表达条件查询的关键字,大致如下: And --- 等价于 SQL 中的 and 关键字,比如 findByUsernameAndPassword(Stri ...

  5. 小白的springboot之路(七)、事务支持

    0-前言 事务管理对于企业级应用来说必不可少,用来确保数据的完整性和一致性: 1-开启事务 spring boot支持编程式事务和声明式事务,用声明式事务即可: spring boot开启事务非常简单 ...

  6. gulp+webpack+angular1的一点小经验(第三部分使用一些angular1的插件ui-bootstrap与highcharts)

    第一个要介绍的是我们的麻烦制造器:angular-ui-bootstrap ui-bootstrap可以有很多通用的插件给大家用,比如弹窗啊(modal),翻页控件啊(pagination),为什么说 ...

  7. 华为云&#183;寻找黑马程序员#海量数据的分页怎么破?【华为云技术分享】

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...

  8. Java修炼——面向对象_抽象类和抽象方法

    抽象类和抽象方法 什么是抽象类? 使用 abstract 修饰的类称为抽象类 public abstract class Person { } 抽象类的特征 1) 抽象类不可以创建对象 2) 抽象类可 ...

  9. python实现十大核心算法(桶排没实例)

    # author:sevenduke # 2019-06-11 # 一.交换排序 # 排序算法的温故:冒泡排序 def dubblesort(arr): for i in range(0, len(a ...

  10. django上传并显示图片

    环境 python 3.5 django 1.10.6 步骤 创建名为 testupload的项目 django-admin startproject testupload 在项目testupload ...