程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了没有 GET 映射大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决没有 GET 映射?

开发过程中遇到没有 GET 映射的问题如何解决?下面主要结合日常开发的经验,给出你关于没有 GET 映射的解决方法建议,希望对你解决没有 GET 映射有所启发或帮助;

我通常使用 xml 配置,但现在只想继续使用 java 配置,但我的代码有问题,我不知道要更改什么,因为一切似乎都很好。

在玻璃鱼上运行 Spring 应用程序后出现此错误:

@H_801_7@[glassfish 5.0] [WARNING] [] [org.springframework.web.servlet.PageNotFound] [tID: _ThreadID=30 _Threadname=http-Listener-1(2)] [timeMillis: 1619543716623] [levelValue: 900] [[ No mapPing for get /spring_project-1.0-SNAPSHOT/home/showHome/]]

这是我的@H_801_7@controller:

@H_801_7@    @Controller
    @requestMapPing("/home")
    public class HomeController {
    
        @requestMapPing("/showHome")
        public String showHome() {
    
            return "home";
        }
    }
@H_874_17@

我的@H_801_7@vIEw resolver:

@H_801_7@@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.config")
public class AppConfig {

    @Bean
    public VIEwResolver vIEwResolver() {
        InternalresourceVIEwResolver vIEwResolver = new InternalresourceVIEwResolver();
        vIEwResolver.setVIEwClass(JstlVIEw.class);
        vIEwResolver.setPrefix("/WEB-INF/vIEw/");
        vIEwResolver.setSuffix(".Jsp");

        return vIEwResolver;
    }
@H_874_17@

}

还有@H_801_7@WebAppInitializer:

@H_801_7@    public class AppIntializer  implements WebApplicationInitializer {

    @OverrIDe
    public voID onStartup(ServletContext container) {
        // Create the 'root' Spring application context
        AnnotationConfigWebApplicationContext rootContext =
                new AnnotationConfigWebApplicationContext();
        rootContext.register(AppConfig.class);

        // Manage the lifecycle of the root application context
        container.addListener(new ContextLoaderListener(rootContext));

        // Create the dispatcher servlet's Spring application context
        AnnotationConfigWebApplicationContext dispatcherContext =
                new AnnotationConfigWebApplicationContext();
        dispatcherContext.register(AppConfig.class);

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher =
                container.addServlet("dispatcher",new dispatcherServlet(dispatcherContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapPing("/");
    }

}
@H_874_17@ 

解决方法

您需要在此行中指定 http 方法。

@H_801_7@@requestMapping("/showHome")
@H_874_17@

或者只是使用

@H_801_7@@GetMapping
@H_874_17@

另外,阅读下面的页面会很有用。

https://www.baeldung.com/spring-new-requestmapping-shortcuts

大佬总结

以上是大佬教程为你收集整理的没有 GET 映射全部内容,希望文章能够帮你解决没有 GET 映射所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:映射没有