-
在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 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑想用offer打牌2 小时前
MCP (Model Context Protocol) 技术理解 - 第二篇曹牧3 小时前
Spring Boot:如何测试Java Controller中的POST请求?KYGALYX4 小时前
服务异步通信掘了4 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己爬山算法4 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?kfyty7254 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案猫头虎4 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题李少兄4 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址Moment5 小时前
富文本编辑器在 AI 时代为什么这么受欢迎