一、目录展示

  

二、导入依赖

  

三、配置文件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. Django总结目录

    Django总结目录 1. django框架简介及自定义简易版框架 2. 路由层 3. 视图层 4. 模板层 5. 模型层 5.1 基本操作 5.2 多表操作 5.3 进阶相关 6. 组件 6.1 a ...

  2. django-ajax传输数据

    AJAX简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是"异步Javascript和XML". 即使用Javascript语言与服务器 ...

  3. warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID XXXXXX: NOKEY

    我在使用Centos时,会出现这种错误: 本人实践有效的办法是: 加上"--nogpgcheck"参数 就是在你要执行的语句后面加上该参数就行了! 我当时是为了安装jenkins时 ...

  4. PHP函数include include_once require和require_once的区别

    了解下include.include_once.require和require_once这4个函数: include函数:会将指定的文件读入并且执行里面的程序: require函数:会将目标文件的内容 ...

  5. FastAdmin的基本使用

    FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架. 1.在线命名管理 (1)菜单的生成 (2)一键 crud  首先要安装在线命名 在翡翠分类生成菜单,如下: 它的 ...

  6. UML类图绘制

    UML图简介 含义:UML-Unified Modeling Language 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言 主要模型: 功能模型:从用户的角度展示系统 ...

  7. 如何编写可怕的Java代码?

    我决定告诉你如何编写可怕的Java代码.如果你厌倦了所有这些美丽的设计模式和最佳实践,并且想写些疯狂的东西,请继续阅读. 如果你正在寻找有关如何编写良好代码的建议,请查看其它文章! 对一切使用异常 你 ...

  8. Sql增加,删除,修改列

    1. 查看约束条件 - MySQL: SELECT * FROM information_schema.`TABLE_CONSTRAINTS` where table_name = 'book'; - ...

  9. luogu P5002 专心OI - 找祖先

    题目描述 这个游戏会给出你一棵树,这棵树有NN个节点,根结点是RR,系统会选中MM个点P_1,P_2...P_MP 1 ​ ,P 2 ​ ...P M ​ ,要Imakf回答有多少组点对(u_i,v_ ...

  10. Bless You Autocorrect!

    题目链接: https://odzkskevi.qnssl.com/0c87453efec2747f8e8a573525fd42f9?v=1533651456 题解: 这是一道Trie+BFS的题目: ...