springmvc页面报404错误解决

最近开始学习使用springmvc, 第一个列子是配置了一个视图

controller代码如下:

package com.cotroller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import vo.Shop;

/**
 * Created by  on 2017/8/30.
 */
@Controller
@RequestMapping(value="/hello")
public class HelloController {
    @RequestMapping(value="/world",method= RequestMethod.GET)
    public String hello(Model model){
        model.addAttribute("msg", "你好spring mvc");
        return "index";
    }

    @ResponseBody
    @RequestMapping(value="/string",method= RequestMethod.GET,produces="text/html;charset=UTF-8")
    public String string(Model model){
        model.addAttribute("msg", "你好spring mvc");
        return "你好123333";
    }
    @ResponseBody
    @RequestMapping(value="/json/{name}", method = RequestMethod.GET,produces="application/json;charset=UTF-8")
    public
    Shop getShopInJSON(@PathVariable String name) {
        System.out.println("-----请求json数据--------");
        Shop shop = new Shop();
        JsonProcessingException e=null;
        shop.setName(name);
        shop.setStaffName(new String[]{"mkyong1", "mkyong2","fjjfjfj"});
        return shop;

    }
}
hello方法返回了视图的名称“index”,"index"的配置如下:
<!-- 视图层配置 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".html"/>
</bean>

    
    
    
    
    
    
    
    
    
    
    
    
    
        
     
     
        
     
     
    
    
    

然后,tomcat起来,请求链接http://localhost:8080/hello/world一直是404,看了很多网上其他小伙伴的解决办法都不行,后来发现是视图的配置出了问题。。。。。
springmvc不支持html的视图, 将配置改成 jsp的就好了,小问题埋大坑,花了大把时间找这个问题。。。。

现在的配置:
<!-- 视图层配置 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".jsp"/>
</bean>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值