gpt4 book ai didi

java - RequestMappingHandlerMapping 没有映射到这里有什么原因吗?

转载 作者:行者123 更新时间:2023-11-30 07:06:37 25 4
gpt4 key购买 nike

我正在对我使用 mybatis 学到的东西进行回顾(以及给出的练习)。

我想要做的是获取一个带有简单图表的页面,该图表将在图表中获取公司员工列表。

但是当我尝试运行并单击一个链接(这将完成真正的工作)时,我得到了这个:

WARN PageNotFound - No mapping found for HTTP request with URI[/spring_mvc13_batisTest/list] in DispatcherServlet with name'dispatcherServlet'

error message with 404 error on page.

这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples.service.service</groupId>
<artifactId>spring_mvc13_batisTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>

<!-- Generic properties -->
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Web -->
<jsp.version>2.2</jsp.version>
<jstl.version>1.2</jstl.version>
<servlet.version>2.5</servlet.version>


<!-- Spring -->
<spring-framework.version>4.1.3.RELEASE</spring-framework.version>

<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>

<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>

<!-- Test -->
<junit.version>4.11</junit.version>

</properties>

<dependencies>

<!-- Spring MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Other Web dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>

<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>


<!-- Test Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- mariadb jdbc -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>

<!-- //10.7-2-0 added -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>



<!-- MYBATIS -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>


</dependencies>
</project>

我的mvc-config.xml

<context:component-scan base-package="pack.controller"/>

<mvc:annotation-driven />


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>

和应该读取的java文件:

package pack.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import pack.model.SawonDto;
import pack.model.SawonInter;
@Component
@ComponentScan("pack.model")
public class ListController {

@Autowired
private SawonInter inter;

@RequestMapping(value="list", method= RequestMethod.GET)
public Model processSelect(Model model){
model.addAttribute("lists", inter.selectList());
return model;

}
}

[我的作品的 Github 链接][1][1]:https://github.com/zergrage/spring-mybatis

以batisTest结尾的文件夹是我正在做的,另一个是我在上课时写的。我已经拿着这个一整天了,一点运气都没有:(

有好心人解释一下吗?我尝试四处搜索,但就是不明白......

最佳答案

因为你的ListController类还不是Spring MVC Controller 。您需要在 Controller 中添加 spring @Controller 注解。

例如。

import org.springframework.stereotype.Controller;

@Component
@ComponentScan("pack.model")
@Controller
public class ListController {

另外,我会推荐很棒的 Spring MVC 网站供您引用。希望它有所帮助。

https://www.mkyong.com/tutorials/spring-mvc-tutorials/

关于java - RequestMappingHandlerMapping 没有映射到这里有什么原因吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40012582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com