記——Myeclipse springmvc框架搭建
阿新 • • 發佈:2019-02-01
<span style="font-family: Arial, Helvetica, sans-serif;"> 本人使用版本為:myeclipse10.0</span>
最近一直在看springmvc,由於之前使用myeclipse並沒有注意到有myeclipse能便捷搭設框架。所有基本都是自己一個檔案一個檔案的建,自己下jar包。然後匯入進去再寫web.xml和springmvc-servlet.xml。 後來覺得麻煩 就專門查了下myeclipse搭建springmvc框架,終於,在度孃的幫助下,讓我找到了。
1.在myeclipse中建立一個web project。
2.右鍵點選這個專案選擇Myeclipse
3.選擇要匯入的spring包,然後next,選擇spring-servlet要放的位置然後finish
4.根據自己的習慣修改web.xml和spring-servlet.xml檔案
程式碼如下:
web.xml
spring-servlet.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name> spring </servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name> spring </servlet-name> <url-pattern> *.do </url-pattern> </servlet-mapping> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans <span style="white-space:pre"> </span> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <span style="white-space:pre"> </span> http://www.springframework.org/schema/tx <span style="white-space:pre"> </span> http://www.springframework.org/schema/tx/spring-tx-3.0.xsd <span style="white-space:pre"> </span> http://www.springframework.org/schema/context <span style="white-space:pre"> </span> http://www.springframework.org/schema/context/spring-context-3.0.xsd <span style="white-space:pre"> </span> http://www.springframework.org/schema/mvc <span style="white-space:pre"> </span> http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 掃描controller --> <span style="white-space:pre"> </span><context:component-scan base-package="com.yu.conl" /> <span style="white-space:pre"> </span> <span style="white-space:pre"> </span><bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <span style="white-space:pre"> </span><property name="prefix"><value>/WEB-INF/jsp/</value></property> <span style="white-space:pre"> </span><property name="suffix"><value>.jsp</value></property> <span style="white-space:pre"> </span></bean> </beans>
一切搞定就可以開始寫你的程式了