-
在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
相关推荐
geovindu21 分钟前
python:DecisionTreeCosolar27 分钟前
从 Java 21 升到 25、Spring Boot 3 升 4:一次可复现的迁移踩坑实录geovindu2 小时前
python: Decision Tree Regressor码事漫谈2 小时前
黄仁勋的来时路IT空门:门主2 小时前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线bai2732 小时前
path.join('C:\a', '\b') 给我 C:\a\b,path.resolve 给 C:\b:Windows 上 51 行路径实测hackhase3 小时前
Django 多表数据整合:7 张异构表如何收敛成 4 类页面用户3721574261354 小时前
Java 批量操作 Excel 超链接:添加、读取、修改和删除Cosolar5 小时前
需求做完了,经验归零了:Agent 真正缺的是第二条闭环用户3721574261355 小时前
Java 将 Excel 图表导出为图片:指定图表、批量导出与图表工作表