-
在controller同级目录下创建service

package com.spring2.service;
import com.spring2.entity.User;
import com.spring2.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserService {@Autowired private UserMapper userMapper; public int save(User user){ if(user.getId() == null){ //有id 新增 return userMapper.insert(user); }else{ return userMapper.update(user); } }}
-
在controller里出入service

【Spring Boot】service 业务层简单使用
正函数2024-04-15 19:00
相关推荐
梅孔立1 天前
Java 基于 POI 模板 Excel 导出工具类 双数据源 + 自动合并单元格 + 自适应行高 完整实战dLYG DUMS1 天前
Spring Cloud Data Flow 简介Huangxy__1 天前
java相机手搓(后续是文件保存以及接入大模型)Honmaple1 天前
2026 年做短视频,这 5 个 AI 技能插件我把每个都跑通了j_xxx404_1 天前
用系统调用从零封装一个C语言标准I/O库 | 附源码MY_TEUCK1 天前
从零开始:使用Sealos Devbox快速搭建云原生开发环境覆东流1 天前
第4天:Python输入与输出摇滚侠1 天前
Java Map 类型的数据可以存储到 Redis Hash 类型中人道领域1 天前
【LeetCode刷题日记】:151翻转字符串的单词(两种解法)lifallen1 天前
Flink 深度解析:从 TM、Task、Operator、UDF 到 Mailbox 与 OperatorChain