MyEclipse搭建spring MVC+Hibernate
環境配置:MyEclipse6.5
1、新建web Project 專案 test-springMVC
2、在src目錄下分別新建 controller、service、dao、pojo 四個資料夾
3、新增hibernate支援(add hibernate capabilities)
4、將jar包拷貝到專案目錄下,然後next
5、新建hibernate.cfg.xml,next
6、配置資料來源(資料庫連線配置),next
7、建立sessionFactory,去掉 √,不建立sessionFactory(留到spring建立,ioc管理,應該想得通)。
-------------------------------------------分隔線-------------hibernate支援已經配置好了--------------------------------------------------------------------------------
1、新增spring支援 add hibernate add spring capabilities
2、選擇搭建所需要的jar包並拷貝到專案中
所需要的包是 AOP、Core、Persistence Core(支援hibernate)、Misc、Web 共5個包,對應的勾選圖中5項。
3、新增spring配置檔案applicationContext.xml
4、建立sessionFactory
---------------------------分隔線-----------spring支援已經配置好了--------------------------------------------------------------------------
生成pojo
1、點選myEclipse程式右上角的 框,選擇 MyEclipse database Explorer
2、DB Broser --》選中要連線資料庫的表,右鍵選擇 Hibernate Reverse Engineering
3、打上下圖這些勾,不能多不能少
4、點選next,配置id生成策略 ,一般選native(如果id是多對多的中間表的id,記得勾選Enable many-to-many detection)。然後點選Next,
5、由表生成實體類的配置
當我們點選Finish的那一剎那,再回到 MyEclipse Java Enterprise perspective ,就會看到專案成這樣的了,這個時候就說明大功告成了。