多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## dao ~~~ package com.like.dao.impl; @Repository public class AccountDaoImpl implements IAccountDao { @Autowired private JdbcTemplate jt; public Account findAccountById(Integer id) { List<Account> accounts = jt.query("select * from account where id = ?", new BeanPropertyRowMapper<Account>(Account.class), id); return accounts.isEmpty() ? null : accounts.get(0); } public Account findAccountByName(String name) { List<Account> accounts = jt.query("select * from account where name = ?", new BeanPropertyRowMapper<Account>(Account.class), name); if (accounts.isEmpty()) { return null; } if (accounts.size() > 1) { throw new RuntimeException("结果集不唯一"); } return accounts.get(0); } public void updateAccount(Account account) { jt.update("update account set name = ? where id = ?", account.getName(), account.getId()); } } ~~~ ## 根据ID查找 ~~~ IAccountDao accountDaoImpl = (IAccountDao) context.getBean("accountDaoImpl"); Account account = accountDaoImpl.findAccountById(3); System.out.println(account); ~~~ ## 根据name查找 ~~~ System.out.println(accountDaoImpl.findAccountByName("jack")); ~~~ ## 更新 ~~~ IAccountDao accountDaoImpl = (IAccountDao) context.getBean("accountDaoImpl"); Account account = new Account(); account.setId(3); account.setName("milan"); accountDaoImpl.updateAccount(account); ~~~