【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
    在这里插入图片描述

相关推荐

  1. springboot业务逻辑写在controller

    2024-04-12 11:00:02       21 阅读
  2. 第一次使用ThreadPoolExecutor处理业务

    2024-04-12 11:00:02       54 阅读
  3. thinkphp 各简介介绍

    2024-04-12 11:00:02       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 11:00:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 11:00:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 11:00:02       87 阅读
  4. Python语言-面向对象

    2024-04-12 11:00:02       96 阅读

热门阅读

  1. 【php快速上手(五)】

    2024-04-12 11:00:02       54 阅读
  2. QT:QT实现TCP协议

    2024-04-12 11:00:02       52 阅读
  3. 设计模式:命令模式

    2024-04-12 11:00:02       189 阅读
  4. uni-app中,页面跳转前,进行拦截处理的方法

    2024-04-12 11:00:02       46 阅读
  5. 容器化部署--知识点标记

    2024-04-12 11:00:02       54 阅读
  6. 每天学习一个Linux命令之pwd

    2024-04-12 11:00:02       39 阅读
  7. 基于springboot的大学城水电管理系统源码数据库

    2024-04-12 11:00:02       34 阅读
  8. 查看Tomcat和JDK版本信息(32位还是64位)

    2024-04-12 11:00:02       39 阅读
  9. L2-047 锦标赛

    2024-04-12 11:00:02       42 阅读