- 在controller同級(jí)目錄下創(chuàng)建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
文章來源地址http://www.zghlxwxcb.cn/news/detail-848769.html
文章來源:http://www.zghlxwxcb.cn/news/detail-848769.html
到了這里,關(guān)于【Spring Boot】service 業(yè)務(wù)層簡(jiǎn)單使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!