-
在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
相关推荐
焗猪扒饭3 小时前
redis stream用作消息队列极速入门树獭非懒3 小时前
AI大模型小白手册|Embedding 与向量数据库NE_STOP4 小时前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类IT_陈寒6 小时前
SpringBoot实战:5个让你的API性能翻倍的隐藏技巧梦想很大很大6 小时前
拒绝“盲猜式”调优:在 Go Gin 项目中落地 OpenTelemetry 链路追踪唐叔在学习7 小时前
就算没有服务器,我照样能够同步数据用户68545375977697 小时前
同步成本换并行度:多线程、协程、分片、MapReduce 怎么选才不踩坑javaTodo8 小时前
Claude Code 记忆机制详解:从 CLAUDE.md 到 Auto Memory,六层体系全拆解LSTM978 小时前
使用 C# 和 Spire.PDF 从 HTML 模板生成 PDF 的实用指南