-
在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
相关推荐
木木子99991 小时前
业务架构、应用架构、数据架构、技术架构qq_5470261793 小时前
Flowable 工作流引擎鼓掌MVP4 小时前
Java框架的发展历程体现了软件工程思想的持续进化编程爱好者熊浪5 小时前
两次连接池泄露的BUGlllsure5 小时前
【Spring Cloud】Spring Cloud Config鬼火儿5 小时前
SpringBoot】Spring Boot 项目的打包配置NON-JUDGMENTAL5 小时前
Tomcat 新手避坑指南:环境配置 + 启动问题 + 乱码解决全流程cr7xin5 小时前
缓存三大问题及解决方案摇滚侠6 小时前
Spring Boot3零基础教程,Spring Boot 应用打包成 exe 可执行文件,笔记91 笔记92 笔记93chxii6 小时前
Maven 详解(上)