Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Jul 25 12:42:32 CST 2021
There was an unexpected error (type=Not Found, status=404).
在这里插入图片描述
当出现上图所示的困难时,注意看一下controller类当中的东西是否写对了,我查看了一下userController类当中的代码

package com.itany.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("/findAll")

    public List<Map<String, Object>> findAll(){
        List<Map<String,Object>> list=jdbcTemplate.queryForList("select * from t_user");
        return list;
    }
}

仔细看了好一会儿之后才发现,原来时在@RequestMapping(“findAll”)下面没有设置相应的body回应,即@ResponseBody
完整代码如下所示:

package com.itany.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("/findAll")
@ResponseBody
    public List<Map<String, Object>> findAll(){
        List<Map<String,Object>> list=jdbcTemplate.queryForList("select * from t_user");
        return list;
    }
}

然后重启tomcat之后结果如下所示:
在这里插入图片描述
好的,明怀我吃饭去啦,我们下次再见,最近我学完了springboot,正在做总结,所以要等几天才能出出来springboot的学习资料,拜拜~

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐