访问不到Controller,也访问不到controller路径。

Controller代码:

/*** Created by 李柏霖* 2020/10/19 17:35*/package com.lbl.controller;import com.lbl.domain.Employee;
import com.lbl.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;import java.util.List;@Controller
@RequestMapping("/employee")
public class EmployeeController {@Autowiredprivate IEmployeeService employeeService;@RequestMapping(path = "/list",method = {RequestMethod.GET,RequestMethod.POST})public String list(Model model){System.out.println("employee....list.....run");//显示所有的person数据List<Employee> employeeList = employeeService.findAll();System.out.println(employeeList);model.addAttribute("employeeList",employeeList);return "list";}
}

原因是我在spingmvc的配置文件中加了过滤静态资源的配置,当我删除这段,又可以正常访问.

springmvc.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: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.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--只扫@Controller注解--><context:component-scan base-package="com.lbl"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"></property><property name="suffix" value=".jsp"></property></bean><!--过滤静态资源   .js .css png--><mvc:resources location="/css/" mapping="/css/**" /><mvc:resources location="/images/" mapping="/images/**" /><mvc:resources location="/js/" mapping="/js/**" /><context:annotation-config></context:annotation-config>
</beans>

这个问题,困扰了我两个小时.后面终于让我发现了问题所在.

原来是我springmvc中的配置写错了.

修改配置为<mvc:annotation-driven/>

springmvc.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: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.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--只扫@Controller注解--><context:component-scan base-package="com.lbl"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"></property><property name="suffix" value=".jsp"></property></bean><!--过滤静态资源   .js .css png--><mvc:resources location="/css/" mapping="/css/**" /><mvc:resources location="/images/" mapping="/images/**" /><mvc:resources location="/js/" mapping="/js/**" /><mvc:annotation-driven></mvc:annotation-driven></beans>

修改了配置之后 ,再运行.

可以访问到,问题解决!!!

解决springmvc中添加了静态资源访问路径之后就访问不到Controller路径的问题相关推荐

  1. Spring-Boot:写出来的网站访问不到静态资源?怎样通过url访问SpringBoot项目中的静态资源?localhost:8989/favicon.ico访问不了工程中的图标资源?

    Spring-Boot:Spring-Boot写出来的网站访问不到静态资源?怎样通过url访问SpringBoot项目中的静态资源?localhost:8989/favicon.ico访问不了工程中的 ...

  2. springboot 请求路径有后缀_SpringBoot中配置Web静态资源路径的方法

    介绍: 本文章主要针对web项目中的两个问题进行详细解析介绍:1- 页面跳转404,即controller转发无法跳转页面问题:2- 静态资源文件路径问题. 项目工具: Intelij Idea, J ...

  3. nginx配置静态资源html,通过nginx服务器访问静态资源(示例代码)

    通过nginx服务器访问静态资源 引言 之前在做毕设的时候接触过nginx,那时候是用来做前后端分离的.一转眼都快一年了,nginx的相关内容也忘的差不多了. 有过接触前端的同学都知道,直接在标签的s ...

  4. eclips中配置tomcat静态资源

    eclips配置一个或多个本地资源路径或者是给tomcat server添加一个静态资源路径的方法 方法一:GUI操作 1.找到eclips面板上server tab选项卡  2.在server列表上 ...

  5. Django实现media、static静态资源通过url加载访问

    Django实现media.static静态资源通过url加载访问 Django项目中一般上传的静态文件会存储在根目录的media文件夹下,template模板使用的静态css.js.image等文件 ...

  6. 静态资源部署到服务器不能访问

    静态资源部署到服务器不能访问 背景 前端静态资源部署到服务器后不能访问,手机上可以访问,发现是10080端口的锅,谷歌浏览器认为10080端口是不安全的端口

  7. 中大型网站静态资源优化及存储

    为什么80%的码农都做不了架构师?>>>    静态资源优化: 合并 减少http请求有这样几个优点: (1) 减少DNS请求所耗费的时间 (2) 减少服务器压力(CPU,IO) ( ...

  8. web中什么是静态资源和动态资源

    静态资源和动态资源的概念: 静态资源:我的理解是前端的固定页面,这里面包含HTML.CSS.JS.图片等等,不需要查数据库也不需要程序处理,直接就能够显示的页面. 具体形式为:客户端发送请求到web服 ...

  9. springMVC中添加命名空间(edit namespace)

    小编有一篇文章写的是如何在eclipse中添加约束,首先需要在配置好这些约束之后才能添加约束的命名空间,点击下面一个链接可以直接查看: https://blog.csdn.net/xuan_lu/ar ...

最新文章

  1. Python 自动化 - 浏览器chrome打开F12开发者工具自动Paused in debugger调试导致无法查看网站资源问题原因及解决方法,javascript反调试问题处理实例演示
  2. badminton training
  3. CodeForces - 1287C Garland(贪心)
  4. 携程发布2020年财报:四季度营业利润率10% 疫情以来连续两季度盈利
  5. ES6语法---箭头函数/关于this指向
  6. 淘客基地淘客小程序微信审核通过率90%以上的独家秘籍
  7. 服务器上网站文件无法删除不了怎么办啊,Windows服务器上文件夹删不掉怎么办...
  8. detached entity passed to persist问题与解决方案
  9. CTFSHOW WEB入门
  10. MySQL 8——学习笔记03(插入、更新、删除 数据 [DML语句]、查询数据 [DQL语句])
  11. 使用Git上传项目到码云
  12. 关于对称四舍五入和非对称四舍五入的分析
  13. 动态规划:高阶马尔科夫模型
  14. 【环境问题】基础Web环境搭建问题记录2——Failed to obtain JDBC Connection;
  15. Java架构-微信交流群
  16. java pkcs7 和 pkcs5_PKCS5Padding与PKCS7Padding的区别
  17. Perl 安装包下载链接,官网太慢
  18. 安全控件资料下载链接
  19. 我的世界服务器物品编辑器没用,我的世界背包编辑器服务器bug | 手游网游页游攻略大全...
  20. android中打开查看pdf文件可用mupdf

热门文章

  1. 常用127个ASK码对照表
  2. Latex公式与Word公式相互转换(使用MathType)
  3. 一、Ubuntu安装HomebridgeUI
  4. 浏览器兼容性测试工具Browser Sandbox
  5. web前端作业--响应式美食菜谱网页设计(HTML+CSS+JavaScript+)实现
  6. 独立站卖家如何利用Google广告引流
  7. linux 系统内存nand flash,uboot在nandflash存储时内存和NandFlash存储空间
  8. 笛卡尔生平及其成就介绍
  9. SQLServer_ER关系模型图
  10. C语言:A+B的几种实现方式