今天解决一个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搞定

相关文章:

  • 2021-06-14
  • 2021-11-05
  • 2021-12-31
  • 2021-09-30
  • 2022-01-01
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-20
  • 2022-02-07
  • 2021-08-18
  • 2021-11-04
  • 2022-12-23
  • 2021-07-25
相关资源
相似解决方案