public void setMoney(double money) {
this.money = money;
}
}
AccountService.java(接口)
/**
-
@author 闲言
-
@Description 业务层接口
-
@create 2021-02-03 12:12
*/
public interface AccountService {
/**
-
根据id查询
-
@param id 账户id
-
@return 账户
*/
@Select(“select * from account where id = #{id}”)
Account findById(Integer id);
/**
-
查询所有账户
-
@return 账户列表
*/
@Select("select * from account ")
List findAll();
/**
-
插入数据
-
@param account 账户
*/
@Insert(“insert into account values(#{id},#{name},#{money})”)
void insert(Account account);
}
AccountServiceImpl.java(实现类)
/**
-
@author 闲言
-
@Description 业务层实现类
-
@create 2021-02-03 12:13
*/
@Service(“accountService”)
public class AccountServiceImpl implements AccountService {
@Autowired
private AccountDao accountDao;
@Override
public Account findById(Integer id) {
return accountDao.findById(id);
}
@Override
public List findAll() {
return accountDao.findAll();
}
@Override
public void insert(Account account) {
accountDao.insert(account);
}
}
AccountDao.java(dao层接口)
/**
-
@author 闲言
-
@Description 持久层接口
-
@create 2021-02-03 12:13
*/
@Repository
public interface AccountDao {
/**
-
根据id查询
-
@par

本文展示了如何将Spring、SpringMVC和Mybatis框架整合在一起,包括AccountService接口及其实现、AccountDao接口、AccountController以及相关配置文件的详细代码。通过这个教程,读者可以了解到如何在Java应用中进行数据操作并实现业务逻辑。
最低0.47元/天 解锁文章

1629

被折叠的 条评论
为什么被折叠?



