SpringBoot:实战项目TILAS智能学习辅助系统1.2

news/2024/10/10 19:26:38/

SpringBootWeb项目

TILAS智能学习辅助系统

@RequestMapping()注解可以抽取资源链接的共性

新增员工

//控制层
@PostMapping("/emps")Result insert(@RequestBody Emp emp);@Overridepublic Result insert(Emp emp) {empService.insert(emp);return Result.success();}//业务层
void insert(Emp emp);@Overridepublic void insert(Emp emp) {emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());empMapper.insert(emp);}//持久层
void insert(Emp emp);<insert id="insert">insert into emp values (#{id},#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})</insert>
文件上传
本地存储

前端通过设置enctype="multipart/form-data"传给我们二进制文件参数

我们需要用MultipartFile类型的对象进行接收

传入的文件实际上是暂存在了系统的临时文件中

所以我们需要先将临时文件保存

@Overridepublic Result upload(MultipartFile multipartFile) throws IOException {String ofn = multipartFile.getOriginalFilename();String nfn = UUID.randomUUID() + "." + ofn.split("\\.")[ofn.split("\\.").length - 1];multipartFile.transferTo(new File("D:\\documents\\code\\TLIAS\\" + nfn));System.out.println(nfn);return Result.success(nfn);}

multipart/form-data:将文件以二进制形式上传

上传到阿里云存储
@Overridepublic Result upload(MultipartFile multipartFile) throws IOException {String url = aliOSSUtils.upload(multipartFile);System.out.println(url);return Result.success(url);}
工具类
package com.example.tlias.util;import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;/*** 阿里云 OSS 工具类*/
@Component
public class AliOSSUtils {@Value("${aliyun.oss.endpoint}")private String endpoint;@Value("${aliyun.oss.accessKeyId}")private String accessKeyId;@Value("${aliyun.oss.accessKeySecret}")private String accessKeySecret;@Value("${aliyun.oss.bucketName}")private String bucketName;/*** 实现上传图片到OSS*/public String upload(MultipartFile multipartFile) throws IOException {// 获取上传的文件的输入流InputStream inputStream = multipartFile.getInputStream();// 避免文件覆盖String fileName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")) + multipartFile.getOriginalFilename();//上传文件到 OSSOSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);ossClient.putObject(bucketName, fileName, inputStream);//文件访问路径String url = endpoint.split("//")[0] + "//" + bucketName + "." + endpoint.split("//")[1] + "/" + fileName;// 关闭ossClientossClient.shutdown();return url;// 把上传到oss的路径返回}}

配置文件注入

使用@Value注解注入
@Value("${aaa.bbb.ccc}")
使用@ConfigurationProperties注解注入封装
@ConfigurationProperties(prefix = "aliyun.oss")
public class AliOSSProperties{........
}
yml

较properties来说更为简化,重数据轻格式

server.port=8080#propertiesserver:#ymlport: 8000#值前需要加空格

员工修改

数据回显
//控制层
@GetMapping("/{id}")Result selectById(@PathVariable Integer id);@Overridepublic Result selectById(Integer id) {return Result.success(empService.selectById(id));}
//业务层
Emp selectById(Integer id);@Overridepublic Emp selectById(Integer id) {return empMapper.selectById(id);}//持久层
@Select("select * from emp where id = #{id}")Emp selectById(@Param("id") Integer id);
数据修改
//控制层
@PutMapping("")Result update(@RequestBody Emp emp);@Overridepublic Result update(Emp emp) {empService.update(emp);return Result.success();}//业务层
void update(Emp emp);@Overridepublic void update(Emp emp) {emp.setUpdateTime(LocalDateTime.now());empMapper.update(emp);}//持久层
void update(Emp emp);<update id="update">update emp<set><if test="username != ''">username = #{username},</if><if test="password != ''">password = #{password},</if><if test="name != ''">name = #{name},</if>gender = #{gender},image = #{image},job = #{job},entrydate = #{entrydate},dept_id = #{deptId},<if test="create_time = null">create_time = now(),</if>update_time = #{updateTime}</set>where id = #{id}</update>

http://www.ppmy.cn/news/1455714.html

相关文章

LLM——用于微调预训练大型语言模型(LLM)的GPU内存优化与微调

前言 GPT-4、Bloom 和 LLaMA 等大型语言模型&#xff08;LLM&#xff09;通过扩展至数十亿参数&#xff0c;实现了卓越的性能。然而&#xff0c;这些模型因其庞大的内存需求&#xff0c;在部署进行推理或微调时面临挑战。这里将探讨关于内存的优化技术&#xff0c;旨在估计并优…

Golang | Leetcode Golang题解之第62题不同路径

题目&#xff1a; 题解&#xff1a; func uniquePaths(m, n int) int {return int(new(big.Int).Binomial(int64(mn-2), int64(n-1)).Int64()) }

炒股自动化:散户如何通过API查询资产和持仓,Python接口

券商官方的接口&#xff0c;个人账户可申请&#xff0c;入金门槛低&#xff0c;接入文档完善&#xff0c;技术支持好的&#xff0c;经过我们筛选后&#xff0c;只有一家符合&#xff0c;会编程&#xff0c;有基础&#xff0c;只是需要API接口的朋友不用看这些内容&#xff0c;不…

OpenHarmony实战开发-应用侧调用前端页面函数

应用侧可以通过runJavaScript()方法调用前端页面的JavaScript相关函数。 在下面的示例中&#xff0c;点击应用侧的“runJavaScript”按钮时&#xff0c;来触发前端页面的htmlTest()方法。 前端页面代码。 <!-- index.html --> <!DOCTYPE html> <html> <…

【Web】CTFSHOW 新手杯 题解

目录 easy_eval 剪刀石头布 baby_pickle repairman easy_eval 用script标签来绕过 剪刀石头布 需要赢100轮&#x1f914; 右键查看源码拿到提示 一眼session反序列化 打PHP_SESSION_UPLOAD_PROGRESS 脚本 import requestsp1 a|O:4:"Game":1:{s:3:"log…

一竞技MSI:淘汰赛抽签结果出炉 BLG和T1同半区,TES首轮交手TL!

北京时间5月6日&#xff0c;MSI在今天进入短暂的休赛&#xff0c;在昨天结束的入围赛之后&#xff0c;PSG战队作为外卡赛区唯一的队伍进入到正赛&#xff0c;另外欧洲赛区的FNC战队也是击败GAM战队拿到正赛的资格。在比赛结束之后&#xff0c;也是进行了淘汰赛的胜败分组赛的抽…

一款开源高性能AI应用框架

前言 LobeChat 是一个基于 Next.js 框架构建的 AI 会话应用&#xff0c;旨在提供一个 AI 生产力平台&#xff0c;使用户能够与 AI 进行自然语言交互。 LobeChat应用架构 LobeChat 的整体架构由前端、EdgeRuntime API、Agents 市场、插件市场和独立插件组成。这些组件相互协作&a…

ICode国际青少年编程竞赛- Python-1级训练场-变量入门

ICode国际青少年编程竞赛- Python-1级训练场-变量入门 1、 a 4 Dev.turnRight() Dev.step(a)2、 a 4 Spaceship.step(a) Dev.step(a)3、 a 4 Dev.step(a) Dev.turnLeft() Dev.step(a)4、 a 5 Dev.step(a) Spaceship.step(a) Dev.step(a)5、 a 3 Dev.step(a) Dev.tur…