怎么下载网站的模板,快乐麻花网站源码,连云港网站优化方案,站酷网素材图库让mybatis自动生成dao层接口的实现类
这是dao层接口的实现类#xff0c;在mybatis中我们可以省略这种实现接口的方式#xff0c;直接面向接口操作数据库#xff0c;mybatis可以帮我们自动生成接口的实现类#xff0c;也就是下面这个实现类mybatis帮我们生成了。 1、修改se…让mybatis自动生成dao层接口的实现类
这是dao层接口的实现类在mybatis中我们可以省略这种实现接口的方式直接面向接口操作数据库mybatis可以帮我们自动生成接口的实现类也就是下面这个实现类mybatis帮我们生成了。 1、修改service生成代理对象调用接口方法等同于上述图片内容的作用。
public class NewAccountService {SqlSession sqlSession SqlSessionUtil.openSession();Account accountnew Account();public void changeAccount(String from_number,String to_number,Double balance){//获取接口对象相当于AccountDao accountDaonew AccountDaoImpl();AccountDao mapper sqlSession.getMapper(AccountDao.class);//判断余额是否充足Account accountnew Account();if(mapper.select(from_number)balance){System.out.println(余额不足);}else{account.setAccountNumber(from_number);account.setBalance(mapper.select(to_number)-balance);mapper.updata(account);account.setAccountNumber(to_number);account.setBalance(mapper.select(to_number)balance);mapper.updata(account);}sqlSession.commit();sqlSession.close();}
}
2、修改映射文件将映射文件中的namespace标签属性修改为Dao层接口所在的位置将查询更新语句中的id修改该为与接口中对应的方法一致。 3、测试
初始数据库数据 结果