【Spring Boot】service 业务层简单使用

  • 在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

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