简介 目录 评价 推荐
  • hungry_quiter 2022-04-02

    spring mvc

    0赞 · 0采集
  • 慕雪7488167 2021-12-20

    intercaptor对controller前后的操作

    0赞 · 0采集
  • 慕盖茨8296265 2021-07-21


    springmvc结构图

    0赞 · 0采集
  • WE_Xing 2021-07-19

    Spring MVC

    0赞 · 0采集
  • WE_Xing 2021-07-19

    JSON

    0赞 · 0采集
  • WE_Xing 2021-07-19

    JSON

    0赞 · 0采集
  • WE_Xing 2021-07-19

    文件上传

    0赞 · 0采集
  • WE_Xing 2021-07-18

    forward & redirect

    0赞 · 0采集
  • WE_Xing 2021-07-17

    Controller

    0赞 · 0采集
  • 慕UI7189114 2021-07-17

    import 的 model 是 “import org.springframework.ui.Model;”,而不是maven里的model类

    0赞 · 0采集
  • WE_Xing 2021-07-17

    Spring MVC

    0赞 · 0采集
  • WE_Xing 2021-07-16

    DispatcherServlet

    0赞 · 0采集
  • WE_Xing 2021-07-16

    Maven

    0赞 · 0采集
  • WE_Xing 2021-07-16

    修改中心仓库

    0赞 · 0采集
  • WE_Xing 2021-07-16
    mvn -version
    0赞 · 0采集
  • WE_Xing 2021-07-16

    Maven

    0赞 · 0采集
  • WE_Xing 2021-07-16

    Spring MVC

    0赞 · 0采集
  • WE_Xing 2021-07-16

    Spring MVC

    0赞 · 0采集
  • WE_Xing 2021-07-16

    MVC 架构

    0赞 · 0采集
  • WE_Xing 2021-07-16

    Front Controller

    0赞 · 0采集
  • 慕UI7189114 2021-07-15

    虽然和教程里的运行结果一样,但是很多地方我不理解,所以下面的代码里很可能有错误的地方

    web.xml

    <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd" >
    
    <web-app>
      <display-name>Archetype Created Web Application</display-name>
      
      <servlet>
       <servlet-name>mvc-dispatcher</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <!--DispatcherServlet对应的上下文配置,默认为/WEB-INF/$servlet-name$-servlet.xml,下面语句改变了该默认参数
       -->
       <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/configs/spring/mvc-dispatcher-servlet.xml</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
      <servlet-name>mvc-dispatcher</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>
      
    </web-app>

    ------------------------------------------------------------------------------------------

    mvc-dispatcher-servlet

    <?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/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    <context:annotation-config/>
    
    <!-- 让DispatcherServelt上下文只搜索@Controller标注的类,不搜索其他标注的类 -->
    <context:component-scan base-package="com.imooc.mvcdemo.controller" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    
    <mvc:annotation-driven />
    
    <!-- viewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="ViewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsps/" />
    <property name="suffix" value=".jsp"/>
    </bean>
    
    </beans>

    ---------------------------------------------------------------------------------------------

    pom.xml(与教程中不太一样,教程里的一些东西我没有写上去)

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.how2java</groupId>
      <artifactId>springmvc2021071501</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>springmvc2021071501 Maven Webapp</name>
      <url>http://maven.apache.org</url>
      
      <dependencyManagement>
          <dependencies>
              <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-framework-bom</artifactId>
              <version>${spring.version}</version>
              <type>pom</type>
              
              </dependency>
          </dependencies>
      </dependencyManagement>
      
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.43</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.0-b07</version>
        </dependency>
        <dependency>
            <groupId>apache-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
            <type>pom.lastUpdated</type>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.13.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.3.0.M1</version>
            <type>maven-plugin</type>
        </dependency>
      </dependencies>
      <build>
        <finalName>springmvc2021071501</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.0.M1</version>
            </plugin>
        </plugins>
      </build>
    </project>

    ------------------------------------------------------------------------------------------

    文件位置:

    http://img2.mukewang.com/60f01c41000131fc10191268.jpg




    0赞 · 0采集
  • 慕工程729959 2021-06-04

    Controller处理


    异步请求,赋值


    引入Json类后,定义相关方法

    0赞 · 0采集
  • 慕工程729959 2021-06-04

    json服务的2种模式

    1. @RequestMapping(value="/{courseId}",method=RequestMethod.GET)

      public @ResponseBody Course getCourseInJson(@PathVariable Integer courseId)

    2. @RequestMapping(value="/jsontype/{courseId}",method=RequestMethod.POST)

      public ResponseEntity<Course> getCourseInJson(@PathVariable Integer courseId)

    0赞 · 0采集
  • 慕工程729959 2021-06-04

    文件上传:

    继承Multipartfile类

    0赞 · 0采集
  • 慕工程729959 2021-06-04

    绑定参数方法、重定向路径

    0赞 · 0采集
  • 慕工程729959 2021-06-04

    Contrller 传统方式

    利用HttpServletRequest处理请求参数,使用request.setAttribute("course",course)传参

    //  /courses/view3?courseId=456 形式的URL

    @RequestMapping("view3")

    public String viewCourse3(HttpServletRequest request){

        Integer courseId = Integer.valueOf(request.getParameter("courseId"));

        log.debug("In viewCourse3 ,courseId = {}",courseId);

        Course course = courseService.getCoursebyId(courseId);

        request.setAttribute("course",course);

        return "course_overview";

    }


    @Controller 定义

    @RequestMapping映射路径,定义被拦截路径

    URL template(@RequestParam   and  @PathVariable) 入参定义方法,普通模式:@RequestParam ,Restful模式:@PathVariable

    0赞 · 0采集
  • 慕工程729959 2021-06-04

    Controller 现代方式

    Controller 现代方式

    两种URL请求模

    1. 传统URL请求路径

    2. Restful方式URL请求路径

    两种Model定义

    1. Model model定义,对应传参方法:model.addAttribute(course)

    2. Map<String,Object> model定义,对应传参方法:model.put("course",course)

    0赞 · 0采集
  • silence1210 2021-04-28

    SpringMVC基本概念

      

    0赞 · 0采集
  • silence1210 2021-04-28

    SpringMVC概念:

    0赞 · 0采集
  • silence1210 2021-04-28

    什么是MVC?

    0赞 · 0采集
数据加载中...
开始学习 免费