-
在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
相关推荐
界面开发小八哥42 分钟前
「Java EE开发指南」如何用MyEclipse创建一个WEB项目?(三)ai小鬼头1 小时前
Ollama+OpenWeb最新版0.42+0.3.35一键安装教程,轻松搞定AI模型部署idolyXyz1 小时前
[java: Cleaner]-一文述之一碗谦谦粉1 小时前
Maven 依赖调解的两大原则萧曵 丶2 小时前
Rust 所有权系统:深入浅出指南netyeaxi2 小时前
Java:使用spring-boot + mybatis如何打印SQL日志?收破烂的小熊猫~2 小时前
《Java修仙传:从凡胎到码帝》第四章:设计模式破万法小七mod2 小时前
【MyBatis】MyBatis与Spring和Spring Boot整合原理猴哥源码2 小时前
基于Java+SpringBoot的动物领养平台老任与码2 小时前
Spring AI Alibaba(1)——基本使用