工作第五天日誌

④ updateByPrimaryKey() 和 updateByPrimaryKeySelective()

User user =new User();
user.setId(101);
user.setUsername("joe");
user.setPassword("joe");
user.setEmail("[email protected]");
userDAO.updateByPrimaryKey(user);
相當於:update user set username='joe',password='joe',email='[email protected]' where id=101

User user = new User();
user.setId(101);
user.setPassword("joe");
userDAO.updateByPrimaryKeySelective(user);
相當於:
update user set password='joe' where id=101

 updateByExample() 和 updateByExampleSelective()

UserExample example = new UserExample();
Criteria criteria = example.createCriteria();
criteria.andUsernameEqualTo("joe");
User user = new User();
user.setPassword("123");
userDAO.updateByPrimaryKeySelective(user,example);

相當於:update user set password='123' where username='joe'

http://joe5456536.blog.163.com/blog/static/85374773201010273375550/


今天下午配置好一個action後,進入首頁都報404,調試了好久發現ibatorConfig.xml中最好這樣寫:

<daoGenerator targetPackage="com.yzy.admin.dao" targetProject="yzy_b2c" type="SPRING" implementationPackage="com.yzy.admin.dao.impl" />
implementationPackage儘量也要寫上。

調試結果還是不成功,最好請教別人才發現在控制檯中已經有了exception報出了,結果的問題是:單詞寫錯了,應該是xxxDAO卻寫成了xxxDao。噁心了一下午的問題終於解決了。

發佈了20 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章