- 在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
文章来源地址https://www.toymoban.com/news/detail-848769.html
文章来源:https://www.toymoban.com/news/detail-848769.html
到了这里,关于【Spring Boot】service 业务层简单使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!