06 图书管理系统(SSM+LayUi)

整合spring和springmvc

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





    Archetype Created Web Application


    
    
        contextConfigLocation
        classpath:spring.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    


    
    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:springmvc.xml
        
        
        1
    

    
        dispatcherServlet
        /
    


    
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    

    
        characterEncodingFilter
        /*
    



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" %>


    Spring和SpringMVC整合测试


    Spring和SpringMVC整合测试


  • 运行Tomcat并输入
    http://localhost:8080/library/test01
    出现页面结果,表明整合成功

你可能感兴趣的:(06 图书管理系统(SSM+LayUi))