-
在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
相关推荐
flyinmind几秒前
Java环境与Android环境中使用QuickJS不吃鱼的羊2 分钟前
DaVinci Developer自动连接farerboy8 分钟前
15-Java while 和 do...while循环在繁华处10 分钟前
Java从零到熟练(十二):Java与AI工具整合凯瑟琳.奥古斯特15 分钟前
力扣1235完整解法详解quan_泉17 分钟前
DIDCTF 取证初学者i220818 Faiz Ul20 分钟前
民谣网站|基于Springboot的民谣网站管理系统(源码+数据库+文档)z落落20 分钟前
C# 继承基础详解(代码实战+权限规则)Oneslide22 分钟前
windows cmd输入输出都很卡摇滚侠30 分钟前
JDBC 基础到高级一套通关!基础篇 00-15