動機
之前一直都是從網上看視頻學的SSM三大框架,但只是快速過了一下,很多東西都沒學好,寫簡歷的時候只敢寫了解(笑),趁畢業前還有段時間,想再回顧一下三個框架的知識,也翻一翻買了好久的書。
這個人事管理系統幾乎完全參考瘋狂軟件的《Spring+MyBatis企業應用實戰》(這本書已經有第二版了)第14章。我會將其改爲maven項目,因爲現在流行這個,還可能做出一些其它的修改,不過那都是後話。我會把這個項目更加有條理地構建出來,這是寫作的目的。
開始
首先將項目創建起來,我使用的IDE是Eclipse IDE for Enterprise Java Developers,可以點此連接直接下載,安裝之前需要安裝JDK(推薦1.8)。然後打開IDE,配置好tomcat和maven以及jdk版本web版本(詳細配置見我之前的博客)。就可以創建人事管理項目了:
包名和項目名任取,合法合理即可。
創建好後會有紅叉,這個需要右擊項目->選擇Build path->Configure Build path->Libraries中添加Library->Server Runtime->選擇自己的tomcat即可。
如果你配置好,就將項目添加到tomcat中並運行,在命令行或者瀏覽器中訪問,就可以看到結果:
下一步,在src/main/resources目錄下創建兩個xml文件,spring配置文件applicationContext.xml和springmvc.xml。
接下來稍微完善這兩個配置文件:
首先是applicationContext.xml,參考Spring官網bean配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
然後是springmvc.xml,同樣參考官網配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
</beans>
這樣項目就創建出來了,而且還加了兩個配置文件(雖然不全)。現在,可以把這個項目暫時放一放,休息一會兒,下一篇來談談項目的基本需求與數據庫模型設計。