zoukankan      html  css  js  c++  java
  • 06 图书管理系统(SSM+LayUi)

    整合spring和springmvc

    1、在web.xml中添加spring监听器

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">
    
    
        <display-name>Archetype Created Web Application</display-name>
    
    
        <!-- 配置spring监听器 -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    
        <!-- 配置前端控制器 -->
        <servlet>
            <servlet-name>dispatcherServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <!-- 加载springmvc的配置文件 -->
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:springmvc.xml</param-value>
            </init-param>
            <!-- 启动服务器 -->
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>dispatcherServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
    
        <!-- 配置中文乱码过滤器 -->
        <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>characterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
    </web-app>
    
    

    2、测试spring和springmvc

    • 在com.gychen.controller的TestDemo里写测试代码
    package com.gychen.controller;
    
    import com.gychen.service.ClassInfoService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class TestController {
    
        @Autowired
        private ClassInfoService classInfoService;
    
        @RequestMapping("/test")
        public String testIndex(){
            System.out.println("测试springmvc内容");
            return "test";
        }
    
        @RequestMapping("/test01")
        public String testSpring(){
            classInfoService.queryClassInfoAll();
            System.out.println("测试spring和springmvc整合");
            return "test01";
        }
    }
    
    
    • 在pages里新建test01.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Spring和SpringMVC整合测试</title>
    </head>
    <body>
        Spring和SpringMVC整合测试
    </body>
    </html>
    
  • 相关阅读:
    软件测试自学建议
    软件测试-整理的自学资料
    软件测试自动化…python学习到什么程度?代码好不好学!
    软件测试为什么需要学习Linux的知识?Linux学到什么程度?-log5
    软件测试-Svn服务器搭建全过程-基于Centos6.7-64bit
    迁移虚拟机打开快照报错:CPUID错误
    软件测试-培训的套路-log3
    jaxb
    Java Sax解析
    【IOS】应用之间调用
  • 原文地址:https://www.cnblogs.com/nuister/p/13361185.html
Copyright © 2011-2022 走看看