【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

相关推荐
uzong3 小时前
Mermaid: AI 时代画图的魔法工具
后端·架构
Gerardisite3 小时前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
q***69773 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
闲人编程4 小时前
Python的导入系统:模块查找、加载和缓存机制
java·python·缓存·加载器·codecapsule·查找器
故渊ZY4 小时前
Java 代理模式:从原理到实战的全方位解析
java·开发语言·架构
匿者 衍4 小时前
POI读取 excel 嵌入式图片(支持wps 和 office)
java·excel
一个尚在学习的计算机小白4 小时前
java集合
java·开发语言
IUGEI4 小时前
synchronized的工作机制是怎样的?深入解析synchronized底层原理
java·开发语言·后端·c#
q***13615 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
z***I3945 小时前
Java桌面应用案例
java·开发语言