当前位置: 首页 > news >正文

SpringBoot:实战项目TLIAS智能学习辅助系统1.1

SpringBootWeb项目

TILAS智能学习辅助系统

需求

部门管理

查询部门列表
删除部门
新增部门
修改部门

员工管理

查询员工列表(分页)
删除员工
新增员工
修改员工

准备工作

导入依赖

web(2.7.6)

mybatis

mysql驱动

lombok

准备好包结构

Controller->Service->Mapper->Pojo

controller

@Controller
public interface DeptController{
}@Controller
public interface EmpController {
}

mapper

@Mapper
public interface DeptMapper {
}
@Mapper
public interface EmpMapper {
}

service/serviceImpl

@Service
public interface DeptService {
}
@Service
public interface EmpService {
}
@Slf4j
@Service
public class DeptServiceImpl {
}
@Slf4j
@Service
public class EmpServiceImpl {
}
创建数据库表和对应的实体类
@Data
public class Dept {private Integer id;private String username;private String password;private String name;private Short gender;private String image;private Short job;private LocalDate entrydate;private Integer deptId;private LocalDateTime createTime;private LocalDateTime updateTime;
}@Data
public class Emp {private Integer id;private String name;private LocalDateTime createTime;private LocalDateTime updateTime;
}
在配置文件中引入数据库连接
server.port=8080
#下面这些内容是为了让MyBatis映射
#指定Mybatis的Mapper文件
mybatis.mapper-locations=classpath:mappers/*xml
#指定Mybatis的实体目录
mybatis.type-aliases-package=com.example.tlias.mybatis.entityspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/Tlias_db
spring.datasource.username=root
spring.datasource.password=ljymysqlpwd
#开启日志
mybatis.configuration.logimpl=org.apache.ibatis.logging.stdout.StdOutImpl
#开启字段到实体类的驼峰映射
mybatis.configuration.map-underscore-to-camel-case=true

开发规范

基于前后端分离模式进行开发

定义主流的REST风格API接口进行交互

REST:(Representational State Transfer)表现形式状态转换,一种软件架构风格
url/aaa/1 GET:查询
url/aaa   POST:新增
url/aaa	  PUT:修改
url/aaa/1 DELETE

通过请求方式的不同进行不同操作

在@RequestMapping()中设置method = {RequestMethod.请求方式} RequestMethod是一个枚举类型

或者直接使用

@GetMapping

@PostMapping

@PutMapping

@DeleteMapping

开发流程

根据如下流程进行开发

查看页面原型明确需求

阅读接口文档

思路分析

接口开发:开发后台业务功能(功能按接口划分)

接口测试;通过Postman进行接口测试

前后端联调:和前端工程一起进行测试

功能实现

1,部门管理

查询部门

无需分页

请求路径:/depts

请求方式:GET

//控制层
@GetMapping("/depts")Result getDept();@AutowiredDeptService deptService;@Overridepublic Result getDept() {return Result.success(deptService.selectDept());}//业务层
List<Dept> selectDept();@Autowiredprivate DeptMapper deptMapper;@Overridepublic List<Dept> selectDept(){List<Dept> deptList = deptMapper.selectDept();return deptList;}//持久层
@Select("select * from dept")List<Dept> selectDept();
删除部门

前端传递ID,后端删除对应数据

请求路径:/depts/{id}

请求方式:DELETE

//控制层
//接收路径参数
@DeleteMapping("/depts/{id}")Result DeleteDept(@PathVariable Integer id);@AutowiredDeptService deptService;@Overridepublic Result DeleteDept(Integer id) {deptService.deleteDept(id);return Result.success();}//业务层
void deleteDept(Integer id);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void deleteDept(Integer id) {deptMapper.deleteDept(id);}//持久层
@Delete("delete from dept where id = #{id}")void deleteDept(@Param("id") Integer id);
新增部门

前端输入部门名称,后端创建部门保存到数据库

请求路径:/depts

请求方式:POST

//控制层
//接收JSON参数,使用@RequestBody进行映射
@PostMapping("/depts")Result PostDept(@RequestBody Dept dept);@AutowiredDeptService deptService;@Overridepublic Result PostDept(@RequestBody Dept dept) {deptService.insertDept(dept);return Result.success();}//业务层
void insertDept(Dept dept);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void insertDept(Dept dept) {dept.setCreateTime(LocalDateTime.now());dept.setUpdateTime(LocalDateTime.now());deptMapper.insertDept(dept);}//持久层
@Insert("insert into dept (id, name, create_time, update_time) values (null,#{name},#{createTime},#{updateTime})")void insertDept(Dept dept);
修改部门

先通过selectById进行数据回填,再通过updateDept进行数据修改

//控制层@PutMapping("/depts")Result PutDept(@RequestBody Dept dept);@GetMapping("/depts/{id}")Result getDeptByID(@PathVariable Integer id);@AutowiredDeptService deptService;@Overridepublic Result PutDept(Dept dept) {deptService.putDept(dept);return Result.success();}@Overridepublic Result getDeptByID(Integer id) {return Result.success(deptService.selectDeptByID(id));}//业务层void putDept(Dept dept);Dept selectDeptByID(Integer id);@Autowiredprivate DeptMapper deptMapper;@Overridepublic void putDept(Dept dept) {dept.setUpdateTime(LocalDateTime.now());deptMapper.putDept(dept);}@Overridepublic Dept selectDeptByID(Integer id) {return deptMapper.selectDeptByID(id);}//持久层//修改部门@Update("update dept set name = #{name} where id = #{id}")void putDept(Dept dept);//查询部门数据byID@Select("select * from dept where id = #{id}")Dept selectDeptByID(Integer id);

员工管理

分页查询

使用sql中的LIMIT语句

前端发送查询第几页,后端根据前端返回的页码进行计算对应显示的数据

参数传递:页码page,每页展示数pageSize

后端响应:当前页展示的数据,总共的记录数,封装到对象中以json格式数据进行响应回复

//控制层
@GetMapping("/emps")
Result pageSelect(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer num);@Override
public Result pageSelect(@RequestParam(defaultValue = "1") Integer 		page, @RequestParam(defaultValue = "10") Integer num) {PageBean bean = empService.selectPage(page,num);return Result.success(bean);
}//服务层
PageBean selectPage(Integer page, Integer num);
//返回一个pagebean对象,封装了数据总条数和数据列表@Overridepublic PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer num) {List<Emp> empList = empMapper.selectEmp();List<Emp> empList = empMapper.selectEmi(name,gender,begin,end);return new pageBean(count,emplist);//在持久层中计算总数据条数}//持久层
@Select("select * from emp limit #{index},#{num}")List<Emp> selectPage(@Param("index") Integer index, @Param("num") Integer num);
分页插件

PageHelper,Mybatis的一款分页插件,简化了在Mapper层手动分页的操作,直接使用列表查询,在Service层调用mapper方法设置分页参数.在查询之后解析分页结果,最后封装到PageBean对象中返回即可.

仅在服务层中不同,可以

//服务层
PageBean selectPage(Integer page, Integer num);
//返回一个pagebean对象,封装了数据总条数和数据列表@Overridepublic PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer num) {PageHelper.startPage(page,num);
//        List<Emp> empList = empMapper.selectEmp();List<Emp> empList = empMapper.selectEmi(name,gender,begin,end);Page<Emp> p = (Page<Emp>) empList;PageBean pageBean = new PageBean(p.getTotal(),p.getResult());return pageBean;}
条件分页查询

使用动态SQL

请求路径/emps

请求方式:GET

<select id="selectEmi" resultType="com.example.tlias.pojo.Emp">select * from emp<where><if test="name != null and name != ''">name like concat('%',#{name},'%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if></where></select>

删除员工

请求路径:/emps/{ids}

请求方式:DELETE

在路径参数中传递多个id,在后端springboot中对其封装到集合中,在Mybatis中通过动态sql来完成批量删除操作

//控制层@DeleteMapping("/emps/{ids}")Result delete(@PathVariable List<Integer> ids);@Overridepublic Result delete(List<Integer> ids) {empService.delete(ids);return Result.success();}//业务层void delete(List<Integer> id);@Overridepublic void delete(List<Integer> id) {empMapper.delete(id);System.out.println(id);}//持久层void delete(@Param("id") List<Integer> id);
<delete id="delete">delete from emp where id in<foreach collection="id"item = "item"open = "("separator=","close=")">#{item}</foreach></delete>

遍历集合进行sql判断

相关文章:

SpringBoot:实战项目TLIAS智能学习辅助系统1.1

SpringBootWeb项目 TILAS智能学习辅助系统 需求 部门管理 查询部门列表 删除部门 新增部门 修改部门 员工管理 查询员工列表(分页) 删除员工 新增员工 修改员工 准备工作 导入依赖 web(2.7.6) mybatis mysql驱动 lombok 准备好包结构 Controller->Servi…...

ubuntu-meta-22.04桌面版+ros2-humble 镜像

ubuntu-meta-22.04桌面版ros2-humble 镜像 下载地址&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1PSBe4EqWch44OQUlkCCEig?pwdknty 提取码&#xff1a;knty 镜像文件较大&#xff0c;分成了两个压缩包&#xff0c;下载后直接解压ubuntu22.04-desk-meta-ros2-arm (…...

『大模型笔记』Code Example: Function Calling with ChatGPT

Code Example: Function Calling with ChatGPT 文章目录 一. Code Example: Function Calling with ChatGPT二. 参考文献一. Code Example: Function Calling with ChatGPT from openai import OpenAI from dotenv import load_dotenv import json# --------------------------…...

【智能算法应用】混合粒子群算法求解CVRP问题

目录 1.算法原理2.数学模型3.结果展示4.参考文献5.代码获取 1.算法原理 【智能算法】粒子群算法&#xff08;PSO&#xff09;原理及实现 经典PSO算法用于连续空间优化问题&#xff0c;VRP问题为离散组合优化问题&#xff0c;涉及如何有效地分配一组车辆去访问多个客户点&…...

Python项目开发实战:飞机大战游戏(案例教程)

一、引言 飞机大战游戏是一款经典的射击类游戏&#xff0c;玩家需要驾驶飞机在空中与敌人进行战斗&#xff0c;躲避敌人的攻击&#xff0c;同时发射子弹消灭敌人。本文将详细介绍如何使用Python及其相关库来开发一款简单的飞机大战游戏&#xff0c;包括游戏的设计思路、开发过…...

音频压缩的方法有哪些?3种简单的压缩工具分享

音频压缩的方法有哪些&#xff1f;音频压缩是处理音频文件时的一个重要步骤&#xff0c;旨在减小文件大小&#xff0c;同时尽量保持原始音频的质量。随着数字媒体的普及&#xff0c;音频文件的大小成为了一个重要的考虑因素。通过有效的音频压缩技术&#xff0c;我们能够在保持…...

阿里云CentOS7 打开/关闭防火墙 开放端口

#查看防火墙状态# systemctl status firewalld #关闭防火墙# systemctl stop firewalld #打开防火墙# systemctl start firewalld #添加开放2375端口# firewall-cmd --add-port2375/tcp --permanent #重载入添加的端口# firewall-cmd --reload #查询2375端口是否开启成…...

React 组件性能优化

React 组件性能优化的核心是减少渲染真实 DOM 节点的频率&#xff0c;减少 Virtual DOM 比对的频率。 1. 组件卸载前进行清理操作 window 注册的全局事件, 以及定时器 useEffect(()>{return ()>{// do somethingclearTimeout(tiemr)window.removeEventListener(xxx, c…...

jvm 马士兵 01 JVM简介,class文件结构

01.JVM是什么 JVM是一个跨平台的标准 JVM只识别class文件&#xff0c;符合JVM规范的class文件都可以被识别 u1 是一个字节 u2是两个字节...

PostgreSQL自带的命令行工具02- createdb

PostgreSQL自带的命令行工具02- createdb 基础信息 OS版本&#xff1a;Red Hat Enterprise Linux Server release 7.9 (Maipo) DB版本&#xff1a;16.2 pg软件目录&#xff1a;/home/pg16/soft pg数据目录&#xff1a;/home/pg16/data 端口&#xff1a;5777createdb 是 Postgr…...

软件设计师-重点的构造型设计模式

一、桥接模式&#xff08;Bridge&#xff09;&#xff1a; 意图&#xff1a; 将抽象部分与其实现部分分离&#xff0c;使它们都可以独立地变化。 结构&#xff1a; 适用性&#xff1a; 不希望在抽象和它的实现部分之间有一个固定的绑定关系。例如&#xff0c;这种情况可能是…...

Java面试问题及答案

Java面试问题及答案 以下是几个Java面试中可能会问到的问题及其答案。 1. 解释Java中的多态性是什么&#xff0c;以及它是如何工作的&#xff1f; 问题&#xff1a; 在Java中&#xff0c;多态性是指允许不同类的对象对同一消息做出响应的能力&#xff0c;即同一个接口可以被…...

STM32 01

1、编码环境 1.1 安装keil5 1.2 安装STM32CubeMX 使用STM32CubeMX可以通过界面的方式&#xff0c;快速生成工程文件 安装包可以从官网下载&#xff1a;https://www.st.com/zh/development-tools/stm32cubemx.html#overview 安装完要注意更新一下固件包的位置&#xff0c;因为…...

学习笔记:【QC】Android Q - phone 模块

一、phone init 流程图 二、phone MO 流程图 三、phone MT 流程图 四、Log分析(MO_qcril_hal_分析) 1、RILJ请求dial enqueue进队列&#xff0c;QCRIL-hal pop出来处理&#xff0c;最后还是调用qmi_client_send_msg_async发送给modem 11-07 17:29:23.598 2758 2758 D RILJ …...

webscoket+webrtc实现语音通话

1.项目方案 前端采用webrtc创建音频上下文&#xff0c;后创建音频源输入和音频处理器&#xff0c;连接音频输入与处理器&#xff0c;处理器再连接到音频输出&#xff08;扬声器&#xff09;&#xff0c;再通过事件获取音频数据&#xff0c;把音频数据转换成字节数据通过webscok…...

PHP源码_众筹商城

众筹商城源码 众筹商品平台 商城加共识元富之路 网上商城众筹 前端是编译后的&#xff0c;后端PHP&#xff0c;带商城 运行截图 源码贡献 https://githubs.xyz/boot?app39 部分数据库表 CREATE TABLE ti_shopro_store (id int(11) NOT NULL AUTO_INCREMENT COMMENT ID,nam…...

智能小程序 Ray 开发——表单组件 Button 和 Checkbox 实操讲解

Button 多端按钮基础组件&#xff0c;可用于进行强交互的操作。 导入 import { Button } from ray-js/ray; 属性说明 属性类型默认值必填说明支持平台sizekeyof Sizedefault否按钮的大小涂鸦、微信typekeyof Typedefault否按钮的样式类型涂鸦、微信plainbooleanfalse否按钮…...

渗透之sql注入联合查询的注入

sql注入产生的原因&#xff1a; 由于程序过滤不严谨&#xff0c;导致用户有一些异常输入&#xff0c;最终触发数据库的查询。所以会出现sql注入这个问题。有些恶意的人就会利用这些信息导致数据库泄露。 注意&#xff1a;一般我们存在注入点我们会查询管理员的账号和密码&#…...

NLP transformers - 文本分类

Text classification 文章目录 Text classification加载 IMDb 数据集Preprocess 预处理EvaluateTrainInference 本文翻译自&#xff1a;Text classification https://huggingface.co/docs/transformers/tasks/sequence_classification notebook : https://colab.research.googl…...

QT 开发COM(ActiveX)组件基础介绍和方案验证

一、COM简介 1.1 COM是什么&#xff1f; COM&#xff0c;Component Object Model&#xff0c;即组件对象模型&#xff0c;是一种以组件为发布单元的对象模型&#xff0c;这种模型使各软件组件可以用一种统一的方式进行交互。COM 既提供了组件之间进行交互的规范&#xff0c;也…...

开源创富的三大支柱:技术、流量与商业化的完美结合

开源创富的三大支柱&#xff1a;技术、流量与商业化的完美结合 关键词&#xff1a;开源项目、技术壁垒、流量运营、商业化闭环、社区生态、价值变现、开源经济学 摘要&#xff1a;很多人对“开源”的理解停留在“免费送代码”&#xff0c;但实际上&#xff0c;开源是一套用技术…...

自建轻量级Web监控信标:前端性能与错误数据采集实践

1. 项目概述&#xff1a;一个轻量级、可扩展的Web应用监控信标最近在梳理个人项目和团队内部工具链时&#xff0c;我重新审视了一个名为“beacon”的小工具。这个项目源自一个非常具体的痛点&#xff1a;在开发和运维Web应用时&#xff0c;我们常常需要一种简单、无侵入的方式来…...

METSO A413150输出模块

METSO A413150 是美卓&#xff08;Metso Automation&#xff09;BIU 8 分布式控制系统中的一款输出模块&#xff0c;主要用于向现场执行机构输出模拟量控制信号。中间15个特点METSO A413150 提供8通道模拟量输出&#xff0c;适用于多路控制信号输出。该模块分辨率为16位&#x…...

终极指南:三分钟掌握全网盘高速下载神器LinkSwift

终极指南&#xff1a;三分钟掌握全网盘高速下载神器LinkSwift 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 &#xff0c;支持 百度网盘 / 阿里云盘 / 中国移动云盘 / 天翼云盘…...

认识Python网络套接字编程之流式套接字(一)

流式套接字当你需要使用 TCP 协议进行通信时&#xff0c;需要创建流式套接字。这是套接字编程中最常用的一种。光谈这些概念显得很抽象&#xff0c;还是举送外卖的这个例子&#xff0c;假设你点了一份烤鸭&#xff0c;外卖骑手需要先去店铺取餐&#xff0c;然后送到你的家门口&…...

虚拟机开发环境中如何通过Taotoken管理多个项目的API Key与用量

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 虚拟机开发环境中如何通过Taotoken管理多个项目的API Key与用量 应用场景类&#xff0c;开发者在同一虚拟机中维护多个不同项目&am…...

ONLYOFFICE集成踩坑实录:90%的“内容丢失”和“版本已更新”都因为document.key用错了

在集成OnlyOffice DocumentServer的过程中&#xff0c;很多开发者都会遇到两个非常典型的问题&#xff1a; 多人协同编辑后&#xff0c;再次打开文档发现内容缺失重新打开文档时提示“文档版本已更新” 很多人会认为&#xff1a; 是 ONLYOFFICE 不稳定是缓存机制异常是协同编…...

电气噪声抑制实战:从原理到电磁屏蔽的电子系统稳定性设计

1. 项目概述&#xff1a;无处不在的“隐形杀手”——电气噪声作为一名在电子硬件开发一线摸爬滚打了十多年的工程师&#xff0c;我处理过无数稀奇古怪的故障。很多时候&#xff0c;问题不是出在核心算法或主控芯片上&#xff0c;而是一个看不见摸不着的“隐形杀手”——电气噪声…...

Nodejs后端服务接入Taotoken多模型API的完整配置指南

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 Nodejs后端服务接入Taotoken多模型API的完整配置指南 对于Node.js后端开发者而言&#xff0c;将大模型能力集成到服务中已成为提升…...

浏览器扩展开发实战:光标交互防火墙的设计与实现

1. 项目概述与核心价值最近在折腾浏览器插件开发&#xff0c;偶然在GitHub上看到了一个名为“Raidu Firewall Cursor Extension”的项目。光看这个名字&#xff0c;就让我这个对网络安全和效率工具都感兴趣的老码农眼前一亮。这玩意儿本质上是一个浏览器扩展&#xff0c;但它把…...