一、目录展示

  

二、导入依赖

  

三、配置文件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)查询数据

    

最新文章

  1. BZOJ1367 [Baltic2004]sequence
  2. BZOJ 1051 受欢迎的牛(Tarjan缩点)
  3. java对称加密(AES)
  4. Deferred Shading(延迟渲染)
  5. hdoj 2502 月之数
  6. .NET基础拾遗(7)多线程开发基础1
  7. Halloween party
  8. poj 3177
  9. Android常用工具类封装---SharedPreferencesUtil
  10. 开源 免费 java CMS - FreeCMS1.4-功能说明-站点管理
  11. Windows 查看端口占用
  12. 1、Flutter_初体验_创建第一个应用_AndroidStudio_windows
  13. express 遇到问题 - Error: Can&#39;t set headers after they are sent
  14. HDFS的Java客户端编写
  15. Java Integer常量池——IntegerCache内部类
  16. Hibernate的多表关系
  17. redis数据操作笔记
  18. Spring boot 远程调试
  19. oracle-闪回技术2
  20. 0_Simple__simpleVoteIntrinsics + 0_Simple__simpleVoteIntrinsics_nvrtc

热门文章

  1. attach()与detach()的使用
  2. CSS3选择器归类整理
  3. 高逼格利器之Python闭包与装饰器
  4. linux进程间通信之共享内存学习记录
  5. Flink应用程序结构开发介绍
  6. 鲲鹏性能优化十板斧——鲲鹏处理器NUMA简介与性能调优五步法
  7. Seata AT 模式启动源码分析
  8. 嵌入式—ASCII码
  9. Zabbix与ELK整合实现对日志数据的实时监控
  10. HTML5变化