-
在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
相关推荐
程序员游老板26 分钟前
基于SpringBoot3_vue3_MybatisPlus_Mysql_Maven的社区养老系统/养老院管理系统码事漫谈43 分钟前
VS Code 1.107 更新:多智能体协同与开发体验升级福尔摩斯张1 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)码事漫谈1 小时前
从概念开始开始C++管道编程@淡 定1 小时前
Spring中@Autowired注解的实现原理时空无限1 小时前
Java Buildpack Referenceserendipity_hky2 小时前
【go语言 | 第2篇】Go变量声明 + 常用数据类型的使用疯狂的程序猴2 小时前
App Store上架完整流程与注意事项详解爱笑的眼睛112 小时前
超越剪枝与量化:下一代AI模型压缩工具的技术演进与实践开心就好20252 小时前
把 H5 应用上架 App Store,并不是套个壳这么简单