zoukankan      html  css  js  c++  java
  • springmvc和http404错误

    今天解决一个java中的springmvc的问题,所有配置都是对的,主页面也能打得开,唯独Controller层的方法打不开,一直报http404错误

    package com.gold.controller;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    @RequestMapping("/")
    public class PersonController {
        
    //    @Autowired
    //    Idepart departservice;
        
    //    @RequestMapping("getDeparts")
    //    public Object getDeparts(){
    //        
    //        //获取所有的部门
    //        List<depart> departs=departservice.getAll();
    //        
    //        
    //    }
        
        @RequestMapping("test")  
        @ResponseBody
        public Map<String,Object> test(){  
            Map<String,Object> map = new HashMap<String,Object>();  
            map.put("code", true);  
            return map;  
        }
        
    }

    打入网址:http://localhost:8080/GoldMailList/test就一直报http404错误

    后来在一同事提醒下,检查了web.xml

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

    所以应该打入http://localhost:8080/GoldMailList/test.do

    OK搞定

  • 相关阅读:
    Codeforces_739_B
    Codeforces_732_D
    D
    C
    E
    商汤AI园区的n个路口(中等)
    D. The Fair Nut and the Best Path
    HDU6446
    分解质因数(线性筛)
    D. Extra Element
  • 原文地址:https://www.cnblogs.com/Anders888/p/6008522.html
Copyright © 2011-2022 走看看