1.創建一個web工程
2.導入所需的jar包

3.配置文件中的DispatcherServlet,由於已經安裝了插件,所以只需通過快捷鍵alt+/即可
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-annotation.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
4.創建一個配置文件里classpath后的xml文件(插件可直接插入此類xml),並進行包掃描,打開注釋驅動以及師徒解析器的編寫
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"> <context:component-scan base-package="com.zhiyou.zt.annotation"></context:component-scan> <mvc:annotation-driven /> <mvc:default-servlet-handler/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
5.創建一個包掃描下的包,通過注釋@進行操作
package com.zhiyou.zt.annotation; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.zhiyou.zt.bean.Users; @Controller @RequestMapping("/user") public class my { }
6.接受參數,如果接收的是單獨的參數,方法的參數列表對應的名字必須與傳過來的名字一致,如果為對象,則必須與實體類屬


7.Controller如何進行重定向跳轉加入redirect:即可

8.解決靜態資源的映射(springmvc.xml加入即可)
<mvc:default-servlet-handler/>
