Java什么情况下不进入控制器_无法进入SpringMvc的Controller

使用的IntelliJ IDEA+Maven+SpringMvc+Mybatis等搭建的JavaWeb项目,添加Controller却无法访问,提示:no URL paths identified。

项目能够正常启动无报错,整合配置都是我从eclipse项目中复制的,配置应该都没问题,可能是IntelliJ需要设置什么,望大神就诊

web.xml

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_3_0.xsd"

id="WebApp_ID" version="3.0">

SimpleLeaveSystem

default.jsp

springmvc

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/springmvc.xml

springmvc

/

contextConfigLocation

classpath:spring/applicationContext-*.xml

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

webAppRootKey

springmvc.root

15

log4jConfigLocation

classpath:log4j.properties

log4jRefreshInterval

6000

org.springframework.web.util.Log4jConfigListener

SpringEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

SpringEncodingFilter

/*

springmvc.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"

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

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

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

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

http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

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

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

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

http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

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

http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

org.ctony.simpleleavesystem.controller.TestController类

package org.ctony.simpleleavesystem.controller;

import org.springframework.stereotype.Controller;

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

/**

* Created by Ctony on 2016/10/24.

*/

@Controller

public class TestController {

@RequestMapping("/index")

public String index(){

return "index";

}

}

好的,我明白了。对于你的问题,我可以这样回答: 利用 SpringMVC 拦截器可以控制 Controller 返回值。拦截器是一种 AOP 的技术,可以在请求处理过程中对请求进行拦截和处理,如校验用户权限、记录请求日志等。在处理 Controller 返回值时,可以通过拦截器对返回值进行处理,如对返回值进行加密、压缩等操作。 具体实现步骤如下: 1. 自定义一个拦截器类并实现 HandlerInterceptor 接口。 2. 在 Spring 配置文件中注册拦截器。 3. 在拦截器中重写 preHandle() 和 postHandle() 方法,分别在请求处理前和请求处理后进行拦截和处理。 4. 在 postHandle() 方法中获取 Controller 返回值并进行处理,如加密、压缩等操作。 下面是一个简单的示例代码: ```java public class MyInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 在请求处理前进行拦截和处理 return true; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { // 在请求处理后进行拦截和处理 if (modelAndView != null) { // 对返回值进行加密、压缩等操作 } } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { // 在请求完成后进行拦截和处理 } } ``` 在 Spring 配置文件中注册拦截器: ```xml <mvc:interceptors> <bean class="com.example.MyInterceptor"/> </mvc:interceptors> ``` 这样就可以利用 SpringMVC 拦截器控制 Controller 返回值了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值