【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

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