Spring mvc整合mybatis时找不到handler method

xxyh 发布于 2016/03/24 19:07
阅读 1K+
收藏 0

访问路径:http://localhost:8080/SpringMVC_Mybatis/queryItems.action

Controller:

@Controller
@RequestMapping("/items")
public class ItemsController {
	
	@Autowired
	private ItemsService itemsService;
	
	// 商品查询
	@RequestMapping("/queryItems")
	public ModelAndView queryItems() throws Exception {

		// 调用service查找数据库,查询商品列表
		List<ItemsCustom> itemsList = itemsService.findItemList(null);

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("itemsList", itemsList);
		modelAndView.setViewName("items/itemsList");

		return modelAndView;
	}
}

springmvc.xml配置:

<!-- 组件扫描 -->
	<context:component-scan base-package="com.xxyh.ssm.controller"></context:component-scan>

    <mvc:annotation-driven/>
    
    <!-- 视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/"/>
		<property name="suffix" value=".jsp"/>
    </bean>


前端控制器:

<!-- 前端控制器 -->
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/springmvc.xml</param-value>
		</init-param>
	</servlet>

	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>



需要访问的文件路径:WEB-INF/jsp/items/itemsList.jsp

日志信息:

DEBUG [http-apr-8080-exec-6] - Servlet 'springmvc' configured successfully
DEBUG [http-apr-8080-exec-6] - DispatcherServlet with name 'springmvc' processing GET request for [/SpringMVC_Mybatis/queryItems.action]
DEBUG [http-apr-8080-exec-6] - Looking up handler method for path /queryItems.action
DEBUG [http-apr-8080-exec-6] - Did not find handler method for [/queryItems.action]
 WARN [http-apr-8080-exec-6] - No mapping found for HTTP request with URI [/SpringMVC_Mybatis/queryItems.action] in DispatcherServlet with name 'springmvc'
DEBUG [http-apr-8080-exec-6] - Successfully completed request

请问下,错在哪里了??



加载中
0
buglife
buglife

Did not find handler method for [/queryItems.action]

 为啥要加.action,你的RequestMapping里明明写的是/items/queryItem

buglife
buglife
回复 @xxyh : 噢,问题解决了吗?完全可以不用配那个.action
xxyh
xxyh
在前端控制器中的配置刚刚忘了加了,在<url-pattern>*.action</url-pattern>作了限制
0
阿信sxq
阿信sxq

web.xml里面配置为

<servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
访问“http://localhost:8080/SpringMVC_Mybatis/items/queryItems”即可

xxyh
xxyh
嗯嗯,你说的应该是对的,在Controller里面多加了@RequestMapping("/items")
0
开源中国一人游
开源中国一人游
好明显的错误
一日游
一日游
是错在哪里?
0
wangkang80
wangkang80

关于spring和mybatis的详细配置,可参考:http://git.oschina.net/wangkang/llsfw

希望能够帮到你.

0
灬一棵大树灬
灬一棵大树灬

问题解决了吗?我遇到同样的问题了,代码都是一模一样的。

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部