Spring整合SpringMVC和Mybatis框架

本文展示了如何将Spring、SpringMVC和Mybatis框架整合在一起,包括AccountService接口及其实现、AccountDao接口、AccountController以及相关配置文件的详细代码。通过这个教程,读者可以了解到如何在Java应用中进行数据操作并实现业务逻辑。
摘要由CSDN通过智能技术生成

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

  • 29
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值