SpringMVC基础框架搭建

SpringMVC框架搭建步骤:        

  1、将需要jar包导入lib文件夹下   2、配置web.xml  3、配置springMVC核心配置文件  4、编码Controller类

说明:本项目源码导入eclipse,在tomcat运行后 输入http://localhost:8080/BrainTrain/welcome.jsp进行测试

所需的jar包:http://pan.baidu.com/s/1i3QKYNF(百度云盘)

项目源码:http://pan.baidu.com/s/1kTWM9Rh​;(百度云盘)

一、配置web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>BrainTrain</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

 

  <servlet>

  <servlet-name>springMVC</servlet-name>

  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  <init-param>

  <param-name>contextConfigLocation</param-name>

  <!--springMVC配置文件地址,config是src下的包  -->

  <param-value>classpath*:config/springAnnotation-servlet.xml</param-value>

  </init-param>

  <load-on-startup>1</load-on-startup>

  </servlet>

 

  <servlet-mapping>

  <servlet-name>springMVC</servlet-name>

  <url-pattern>/</url-pattern>

  </servlet-mapping>

</web-app>

​二、配置springMVC核心配置文件:springAnnotation-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" 

 xmlns:context="http://www.springframework.org/schema/context" 

 xmlns:p="http://www.springframework.org/schema/p" 

 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 

      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

      http://www.springframework.org/schema/context 

      http://www.springframework.org/schema/context/spring-context.xsd 

      http://www.springframework.org/schema/mvc 

      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    

<!-- 注解扫描包 -->

<context:component-scan base-package="com.chuck.codeResource"></context:component-scan>

   

     <!-- 开启注解 -->

<mvc:annotation-driven/>

<!-- 静态资源访问 -->

<mvc:resources location="/img/" mapping="/img/**"/> 

<mvc:resources location="/js/" mapping="/js/**"/>

<mvc:resources location="/staticHtml/" mapping="/staticHtml/**"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/"></property>

<property name="suffix" value=".jsp"></property>

</bean>

 </beans> 

三、编写Controller类

package com.chuck.codeResource.user;

import java.util.HashMap;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

@Controller

@RequestMapping("/user")

public class LoginController extends MultiActionController {

@RequestMapping("/addUser")

    public String addUser(HttpServletRequest request,HttpServletResponse response){

    System.out.println("-----add----");

    String result="this is addUser";

    request.setAttribute("result",result);

    return "/welcome";

    }

@RequestMapping("/delUser")

    public String delUser(HttpServletRequest request,HttpServletResponse response){

    System.out.println("-----delUser----");

    String result="this is delUser";

    request.setAttribute("result",result);

    return "/welcome" ; 

    }

@RequestMapping("/updateUser")

    public String updateUser(HttpServletRequest request,HttpServletResponse response){

    System.out.println("-----update----");

    String result="this is updateUser";

    request.setAttribute("result",result);

    return "/welcome";

  

    }

}


获取【下载地址】     【免费支持更新】
A 代码生成器(开发利器);   
   增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   jsp页面 都生成
   就不用写搬砖的代码了,生成的放到项目里,可以直接运行
B 阿里巴巴数据库连接池druid;
  数据库连接池  阿里巴巴的 druid。Druid在监控、可扩展性、稳定性和性能方面都有明显的优势
C 安全权限框架shiro ;
  Shiro 是一个用 Java 语言实现的框架,通过一个简单易用的 API 提供身份验证和授权,更安全,更可靠
D ehcache 分布式缓存;
  是一个纯Java的进程内缓存框架,具有快速、精干等特点,广泛使用的开源Java分布式缓存。
E 微信接口开发(后续会加入Activiti5 工作流 )赠送一个jbpm工作流大型ERP系统(含OA、财务、分销)参考学习
F WebSocket 通信技术 (即时聊天、及时站内信并声音提醒、实时在线管理)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值