1、配置web.xml
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
請注意上面紅色字體部分。
2、SPRING配置
在spring配置文件中加入<mvc:default-servlet-handler/> 以防止靜態資源被攔截
3、具體實現
參數telNum名保持一致,請求映射還可以有多個參數存在,也可以有通配符*存在,最重要一點是查詢使用get,添加使用post,更新使用put,刪除使用delete請求方式;
@GetMapping("/{telNum}/getUser.do")
public Map<String, Object> getUser(@PathVariable("telNum") String telNum) throws Exception {
List<MallUser> userList=testService.selectUserByPhone(telNum);
for(MallUser user:userList){
System.out.println(user.getUserName()+"--------->");
}
return jsonResult;
}
最後瀏覽器中輸入http://服務器地址:端口號/項目名/131232353/getUser.do即可