SSM 实现单表 CRUD

文章目录

  • SSM 实现单表 CRUD
  • 一、数据库
  • 二、后端
    • 1.依赖项
    • 2.项目结构
    • 3.Student.java 实体类
    • 4.StudentDao 接口
    • 5.StudentMapper.xml
    • 6.StudentService 接口
    • 7.StudentServiceImpl.java
    • 8.StudentController.java
    • 9.application.yml
    • 10.StudentSsmApplication.java

一、数据库

数据库名 student
表名 student


字段

二、后端

1.依赖项

2.项目结构

3.Student.java 实体类

package com.sisyphus.studentssm.pojo;/*** @Description: $* @Param: $* @return: $* @Author: Sisyphus* @Date: $*/
public class Student {private Integer id;private String name;private String email;private Integer age;@Overridepublic String toString() {return "Student{" +"id=" + id +", name='" + name + '\'' +", email='" + email + '\'' +", age=" + age +'}';}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}
}

4.StudentDao 接口

package com.sisyphus.studentssm.dao;import com.sisyphus.studentssm.pojo.Student;public interface StudentDao {Student queryById(Integer id);void insert(Integer id, String name, String email, Integer age);void deleteById(Integer id);void update(Student student);
}

5.StudentMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.sisyphus.studentssm.dao.StudentDao"><select id="queryById" resultType="com.sisyphus.studentssm.pojo.Student">select id,name,email,age from student where id = #{id}</select><insert id="insert">insert into student values (#{id},#{name},#{email},#{age})</insert><delete id="deleteById">delete from student where id = #{id}</delete><update id="update">update student set name=#{name},email=#{email},age=#{age} where id = #{id}</update>
</mapper>

6.StudentService 接口

package com.sisyphus.studentssm.service;import com.sisyphus.studentssm.pojo.Student;public interface StudentService {Student queryById(Integer id);void insert(Integer id, String name, String email, Integer age);void deleteById(Integer id);void update(Student student);
}

7.StudentServiceImpl.java

package com.sisyphus.studentssm.service;import com.sisyphus.studentssm.dao.StudentDao;
import com.sisyphus.studentssm.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** @Description: $* @Param: $* @return: $* @Author: Sisyphus* @Date: $*/
@Service
public class StudentServiceImpl implements StudentService{@Autowiredprivate StudentDao studentDao;@Overridepublic Student queryById(Integer id) {return studentDao.queryById(id);}@Overridepublic void insert(Integer id, String name, String email, Integer age) {studentDao.insert(id,name,email,age);}@Overridepublic void deleteById(Integer id) {studentDao.deleteById(id);}@Overridepublic void update(Student student) {studentDao.update(student);}
}

8.StudentController.java

package com.sisyphus.studentssm.controller;import com.sisyphus.studentssm.pojo.Student;
import com.sisyphus.studentssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;/*** @Description: $* @Param: $* @return: $* @Author: Sisyphus* @Date: $*/
@RestController
@RequestMapping("student")
public class StudentController {@Autowiredprivate StudentService studentService;@RequestMapping("query")public Student queryById(@RequestParam("id") Integer id){return studentService.queryById(id);}@RequestMapping("insert")public void insert(@RequestParam("id") Integer id, @RequestParam("name") String name, @RequestParam("email") String email, @RequestParam("age") Integer age){studentService.insert(id,name,email,age);}@RequestMapping("delete")public void deleteById(@RequestParam("id") Integer id){studentService.deleteById(id);}@RequestMapping("update")public void update(@RequestParam("student") Student student){studentService.update(student);}
}

9.application.yml

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTCusername: rootpassword: rootmybatis:mapper-locations: classpath:mapper/*.xml

10.StudentSsmApplication.java

package com.sisyphus.studentssm;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.sisyphus.studentssm.dao")
public class StudentSsmApplication {public static void main(String[] args) {SpringApplication.run(StudentSsmApplication.class, args);}}

【小项目】SSM 实现单表 CRUD相关推荐

  1. SSM8==纯注解SSM项目:实现单表CRUD、事务、自定义异常和统一异常处理、RESTFUL风格接口、统一返回值格式(状态码、内容、消息)、JSON传参、axios、vue.js、elementUI

    环境:IDEA2021+JDK8+MAVEN3.8+TOMCAT7插件 前端:axios.vue.js.elementUI 后端:见POM.XML相关依赖,主要有数据库MySQL5.7 ,数据源Dru ...

  2. SQLSERVER单表CRUD通用方法

    一.适用场景 ①当你书写简单的增删改查心累了 ②当你的项目不考虑并发.高性能 ③当你追求更快速的开发效率 ④当你的业务只涉及单表 二.代码展示 ①单表Insert 1 public bool Inse ...

  3. 手写ORM框架----(数据库单表CRUD万能框架)

    目录 一.准备 1.1 ORM介绍 1.2 准备工作 二.手写ORM的CRUD 2.1 数据库准备 2.2 所需注解 2.3 实体类student 2.4 CRUD 2.4.1 添加功能 2.4.2 ...

  4. 【小项目】Axios 实现前后端交互

    Axios 实现前后端交互 文章目录 Axios 实现前后端交互 一.数据库 二.前端 三.后端 1.StudentServiceImpl.java 2.StudentController.java ...

  5. MapReduce编程(五) 单表关联

    一.问题描述 下面给出一个child-parent的表格,要求挖掘其中的父子辈关系,给出祖孙辈关系的表格. 输入文件内容如下: child parent Steven Lucy Steven Jack ...

  6. springdata jpa单表操作crud

    spring data jpa 1. 项目搭建 1.1 配置 1.2 实体类 1.3 继承JpaRepository接口 2. 批量新增 3. 查询 4. 修改 by hql 5. 删除 by hql ...

  7. 使用Servlet完成单表的CRUD

    实现步骤 第一步:准备一张数据库表.(sql脚本) 第二步:准备一套HTML页面(项目原型)[前端开发工具使用HBuilder] 第三步:分析我们这个系统包括哪些功能 第四步:在IDEA当中搭建开发环 ...

  8. 「mysql优化专题」单表查询优化的一些小总结,非索引设计(3)

    单表查询优化:(关于索引,后面再开单章讲解) (0)可以先使用 EXPLAIN 关键字可以让你知道MySQL是如何处理你的SQL语句的.这可以帮我们分析是查询语句或是表结构的性能瓶颈. (1)写sql ...

  9. ssm练手小项目_20 个 JavaScript+Html+CSS 练手的小项目

    前言: 最近在 GitHub 上发现了一个 vanillawebprojects[1] 开源仓库,里面收集了 20 个 JavaScript+Html+CSS的练手项目,没有使用任何框架,可以让你从基 ...

最新文章

  1. 9月,最值得看的30篇肠道健康文献!
  2. 他们让云撸猫变成现实,台湾大学开发手持VR设备解救吸猫人
  3. 《Ruby程序员修炼之道》(第2版)—第1章1.2节剖析Ruby的安装
  4. 【C语言学习笔记】——1.起始
  5. 从 25 倍稀释下的蘑菇街期权说起
  6. amd显卡显存测试程序_AMD发布Radeon 6000系列显卡:能耗比大提升
  7. ASP.NET Core应用的7种依赖注入方式
  8. 马斯克发布脑机接口重大突破:蓝牙连接,一小时植入,已获FDA认证,人体实验在即...
  9. 华为EMUI10的美学哲思:让美不止初见
  10. 银行不放款算买房人违约吗?
  11. JAVA之列表集合ArrayList
  12. 操作系统原理(三)操作系统用户界面
  13. mysql 创建数据库 utf8 命令_mysql创建数据库 utf8
  14. 机器学习之有监督学习,无监督学习,半监督学习
  15. win7系统设置cmd窗口默认以管理员权限运行
  16. 如何用计算机整理数据,总结:如何在excel中制作数据统计表(最简单的excel分类汇总教程)...
  17. ssh_exchange_identification read Connection reset by peer
  18. RPM REBUILD
  19. 求两个数的 最大公约数 和最小公倍数
  20. linux lvm分区表丢失,重启系统后lvm分区没了,附带错误信息

热门文章

  1. 创建目录_聊聊Word创建目录那些事儿
  2. 贵阳学python_python学习类
  3. LOJ10157——皇宫看守(树形DP)
  4. python基础--numpy.random
  5. 一个整数,它加上100后是一个完全平方数,加上168又是一个完全平方数,请问该数是多少?...
  6. Linux CA证书与https讲解
  7. spine 2.1.27 Pro 叠加方式(Blending)
  8. HDOJ 1896 Stones
  9. Objective-C基础3:内存管理续
  10. (66)UART接口波特率是多少?以及异步采样时钟是多少频率?