-
在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
相关推荐
程序员爱钓鱼2 分钟前
Rust 控制流 if 详解:条件判断与 if 表达式Demon_Hao9 分钟前
Spring Boot 4、JDK 25 与 GraalVM:Java 云原生进化,能否撼动 Go 的地位?kyle~1 小时前
Swagger ---基于 描述文件 生成 交互式API文档 的工具wuqingshun3141599 小时前
什么是责任链模式,一般用在什么场景?江畔柳前堤9 小时前
GO01-Go 语言与主流编程语言深度对比世界哪有真情9 小时前
拿人类意识卡 AI?等于用 bug 验收正式产品:-)10 小时前
算法-归并排序wuqingshun31415910 小时前
说一下消息队列的模型有哪些?fīɡЙtīиɡ ℡11 小时前
布隆过滤器yaoxin52112311 小时前
462. Java 反射 - 获取声明类与封闭类