SpringMVC 是现在广泛应用的框架结构,我也只是一个初学者,一遍学习一遍梳理整合,如有错误,希望大神指点,别误人。

MVC :Model-View-Control

框架性质的C 层要完成的主要工作:封装web 请求为一个数据对象、调用业务逻辑层来处理数据对象、返回处理数据结果及相应的视图给用户。

现在我们先说一下Spring的插件安装,我用的是Eclipse4.5.2版本

如果你不知道自己用的什么版本的eclipse,在你eclipse的安装目录,打开:

(直接拖到浏览器上就可以打开)

然后打开eclipse,如图:

在这个地址中填上:http://dist.springsource.com/release/TOOLS/update/e4.5.2/

在4.5.2处改成你自己的版本就好。安装好,创建文件的时候就会有这个:

(一会儿会用到)

创建个动态项目工程,导入以下几个jar包:

然后,我们需要在WEB-INF文件下创建一个上面的那个.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:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.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.0.xsd"> <context:component-scan base-package="com.ysu.controller"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

然后我们再配置以下web.xml文件,和配置servlet很像:

<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param> -->
<load-on-startup>1</load-on-startup>
</servlet> <!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

下面是我练习的一个例子,包含Ant风格及PathVariable变量、rest请求风格、POST请求转化为PUT请求。上传了一个.java 文件一个jsp文件:

package com.ysu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; @Controller
public class AController {
private static final String SUCCESS="success"; @RequestMapping(value="/testAnt/{id}")
public String testAnt(@PathVariable(value="id") Integer id){
System.out.println("++++++++++"+id); return SUCCESS;
} @RequestMapping("/sayHello")
public String sayHello(){
return SUCCESS;
}
@RequestMapping(value="/order/{id}",method=RequestMethod.GET)
public String getOrderById(@PathVariable(value="id") Integer id){
System.out.println("----------"+id);
return SUCCESS; }
@RequestMapping(value="/order/{id}",method=RequestMethod.POST)
public String getOrderById1(@PathVariable(value="id") Integer id){
System.out.println("~~~~~~~~~~"+id);
return SUCCESS; }
@RequestMapping(value="/order/{id}",method=RequestMethod.PUT)
public String getOrderById2(@PathVariable(value="id") Integer id){
System.out.println("************"+id);
return SUCCESS; }
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/sayHello">GoGoGo</a>
<a href="${pageContext.request.contextPath}/testAnt">GoGoGo</a>
<a href="${pageContext.request.contextPath}/order/123">GetGoGoGo</a>
<form action="${pageContext.request.contextPath}/order/123" method="post">
<input type="submit" value="submit"/>
</form>
<form action="${pageContext.request.contextPath}/order/123" method="post">
<input type="submit" value="submit"/>
<input type="hidden" name="_method" value="put"/>
</form>
</body>
</html>

SpringMVC插件安装、环境配置及快速入门_学习笔记的更多相关文章

  1. 【笔记目录2】【jessetalk 】ASP.NET Core快速入门_学习笔记汇总

    当前标签: ASP.NET Core快速入门 共2页: 上一页 1 2  任务27:Middleware管道介绍 GASA 2019-02-12 20:07 阅读:15 评论:0 任务26:dotne ...

  2. 【笔记目录1】【jessetalk 】ASP.NET Core快速入门_学习笔记汇总

    当前标签: ASP.NET Core快速入门 共2页: 1 2 下一页  任务50:Identity MVC:DbContextSeed初始化 GASA 2019-03-02 14:09 阅读:16 ...

  3. ASP.NET Core快速入门_学习笔记汇总

    第2章 配置管理 任务12:Bind读取配置到C#实例 任务13:在Core Mvc中使用Options 任务14:配置的热更新 任务15:配置框架设计浅析 第3章 依赖注入 任务16:介绍- 任务1 ...

  4. .NET Core on K8S快速入门课程学习笔记

    课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 目录 01-介绍K8s是什么 02-为什么要学习k8s 03-如何学习k8s ...

  5. .NET Core on K8S快速入门课程--学习笔记

    课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 目录 01-介绍K8s是什么 02-为什么要学习k8s 03-如何学习k8s ...

  6. Percona-toolkit的安装和配置-杨建荣的学习笔记

    http://blog.itpub.net/23718752/viewspace-2091818/#rd

  7. Maven的安装、配置及使用入门

    Maven的安装.配置及使用入门 本书代码下载 大家可以从我的网站下载本书的代码:http://www.juvenxu.com/mvn-in-action/,也可以通过我的网站与我取得联系,欢迎大家与 ...

  8. MyEclipse TestNG插件安装与配置

    MyEclipse TestNG插件安装与配置   by:授客 QQ:1033553122 测试环境 jdk1.8.0_121 myeclipse-10.0-offline-installer-win ...

  9. nodejs安装及npm模块插件安装路径配置

    在学习完js后,我们就要进入nodejs的学习,因此就必须配置nodejs和npm的属性了. 我相信,个别人在安装时会遇到这样那样的问题,看着同学都已装好,难免会焦虑起来.于是就开始上网查找解决方案, ...

随机推荐

  1. Mysql时间范围分区(RANGE COLUMNS方式)

    1.创建测试表 CREATE TABLE `t_test` ( `id` ), `dates` DATETIME ); ALTER TABLE t_test ADD PRIMARY KEY (id); ...

  2. 2014 3.22 校队选拔——A

    依然非常失望,我为什么现在还是那么弱,今天就做出了一道题,垫底. 一个大家都看出来的C题,我居然没找到规律,想了一会儿就放弃了. A题是这样的,有n种珍珠,给出这n种珍珠各自的数目,再给出一个M,表示 ...

  3. Img转base64

    function getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width ...

  4. 监听home键的广播

    public class HomeKeyReceiver extends BroadcastReceiver implements SanbotConstants{ private HomeKeyLi ...

  5. Codeforces Round #571 (Unrated for Div. 1+Div. 2)

    A 略 B 被删了,被这个假题搞自闭了,显然没做出来. C 开始莽了个NTT,后来发现会TLE,其实是个SB前缀和,对于这题,我无**说. #include<bits/stdc++.h> ...

  6. 利用salt-stack 对多台分布式应用进行简单部署jar包项目:

    /appsystems/JQM-SERVER/shell/stopServer.sh:                                         ----用脚本停止应用 cmd. ...

  7. 88.QuerySet API使用详解:get_or_create和bulk_create方法

    get_or_create 根据某个条件进行查找,如果找到了匹配的数据就会返回这条数据,如果没有找到匹配到的数据,就会创建一个.示例代码如下: from django.http import Http ...

  8. git常用操作及其基本命令

    克隆远程仓库代码到本地 本地创建有文件夹 git clone 远程仓库地址 本地文件夹名称 本地没有创建文件夹 git clone 远程仓库地址 文件夹名称 克隆完成之后,使用“cd 文件夹”的方式进 ...

  9. 离群点检测(Novelty Detection, Outlier Detenction)

    适合问题: 对于无标签的数据, 又想找出坏用户,完成业务目标. 参考: https://scikit-learn.org/stable/modules/outlier_detection.html 算 ...

  10. build模式入门,build模式理解(转载)

    问:为何要用? 普通做法: 1.创建pojo public class Person { private String name; private int age; private double he ...