大四实训项目添加新页面404

项目地址https://gitee.com/chenshiyun/wolfcode-web
学校实训让我们下载这个项目,然后添加一个appdemo页面
我使用项目中的代码生成器,按照如下步骤操作

img

然后访问appdemo页面,会显示404

img

但其他的页面都可以正常访问,如下图

img

mysql8.0版本,redis,都有在服务里面启动,操作系统是win11

以下是运行后登录,并访问appdemo页面后输出的日志
输出日志
在日志中显示,当前访问接口:/demotest/list.html
和代码中的路径不一样

package cn.wolfcode.web.modules.appdemo.controller;

import cn.wolfcode.web.commons.entity.LayuiPage;
import cn.wolfcode.web.commons.utils.LayuiTools;
import cn.wolfcode.web.commons.utils.SystemCheckUtils;
import cn.wolfcode.web.modules.BaseController;
import cn.wolfcode.web.modules.appdemo.entity.AppDemo;
import cn.wolfcode.web.modules.appdemo.service.IAppDemoService;
import cn.wolfcode.web.modules.log.LogModules;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import link.ahsj.core.annotations.AddGroup;
import link.ahsj.core.annotations.SameUrlData;
import link.ahsj.core.annotations.SysLog;
import link.ahsj.core.annotations.UpdateGroup;
import link.ahsj.core.entitys.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author mm
 * @since 2023-09-13
 */
@Controller
@RequestMapping("appdemo")
public class AppDemoController extends BaseController {

    @Autowired
    private IAppDemoService entityService;

    private static final String LogModule = "AppDemo";

    @GetMapping("/list.html")
    public String list() {
        return "app/appdemo/list";
    }

    @RequestMapping("/add.html")
    @PreAuthorize("hasAuthority('app:appdemo:add')")
    public ModelAndView toAdd(ModelAndView mv) {
        mv.setViewName("app/appdemo/add");
        return mv;
    }

    @GetMapping("/{id}.html")
    @PreAuthorize("hasAuthority('app:appdemo:update')")
    public ModelAndView toUpdate(@PathVariable("id") String id, ModelAndView mv) {
        mv.setViewName("app/appdemo/update");
        mv.addObject("obj", entityService.getById(id));
        mv.addObject("id", id);
        return mv;
    }

    @RequestMapping("list")
    @PreAuthorize("hasAuthority('app:appdemo:list')")
    public ResponseEntity page(LayuiPage layuiPage) {
        SystemCheckUtils.getInstance().checkMaxPage(layuiPage);
        IPage page = new Page<>(layuiPage.getPage(), layuiPage.getLimit());
        return ResponseEntity.ok(LayuiTools.toLayuiTableModel(entityService.page(page)));
    }

    @SameUrlData
    @PostMapping("save")
    @SysLog(value = LogModules.SAVE, module =LogModule)
    @PreAuthorize("hasAuthority('app:appdemo:add')")
    public ResponseEntity<ApiModel> save(@Validated({AddGroup.class}) @RequestBody AppDemo entity) {
        entityService.save(entity);
        return ResponseEntity.ok(ApiModel.ok());
    }

    @SameUrlData
    @SysLog(value = LogModules.UPDATE, module = LogModule)
    @PutMapping("update")
    @PreAuthorize("hasAuthority('app:appdemo:update')")
    public ResponseEntity<ApiModel> update(@Validated({UpdateGroup.class}) @RequestBody AppDemo entity) {
        entityService.updateById(entity);
        return ResponseEntity.ok(ApiModel.ok());
    }

    @SysLog(value = LogModules.DELETE, module = LogModule)
    @DeleteMapping("delete/{id}")
    @PreAuthorize("hasAuthority('app:appdemo:delete')")
    public ResponseEntity<ApiModel> delete(@PathVariable("id") String id) {
        entityService.removeById(id);
        return ResponseEntity.ok(ApiModel.ok());
    }

}


求一个解决页面404的方法

你都知道是路由/demotest的问题了,还找不到吗,不是在源码里就是在数据库里,改了不就完事了

【以下回答由 GPT 生成】

根据提供的信息,我将尝试提供解决该问题的步骤和建议。

步骤1:检查项目配置文件 首先,我们需要检查项目配置文件,确保配置了正确的URL映射和页面路径。在Spring框架中,一般通过配置文件(比如application.properties或application.yml)来配置URL映射和页面路径。请检查以下内容是否正确配置:

  1. 打开项目代码中的配置文件(一般位于src/main/resources目录下),查找URL映射和页面路径配置。
  2. 确保在配置文件中有一个URL映射的路径,对应于你添加的新页面appdemo。
  3. 检查该URL映射的处理器或控制器是否正确指向了appdemo页面的路径。

如果配置文件中的URL映射和页面路径正确配置了,但仍然出现404错误,那可能是其他原因导致的。

步骤2:检查代码中的路径配置 根据提供的信息,日志显示当前访问接口为/demotest/list.html,但代码中的路径不同。这可能是导致404错误的原因之一。请根据以下步骤检查代码中的路径配置:

  1. 打开项目代码中的处理器或控制器类(一般位于src/main/java目录下),找到处理/demotest/list.html接口的方法。
  2. 检查方法中是否正确指定了返回页面的路径。可以使用相对路径或绝对路径。
  3. 如果是使用相对路径,确保路径的层次结构与项目目录结构对应。比如,如果页面位于templates文件夹下的appdemo文件夹中,路径应该是"appdemo/list"。
  4. 如果是使用绝对路径,确保路径的写法正确,如"/appdemo/list"。

如果以上步骤都检查无误,但问题仍然存在,可能需要进一步检查其他可能原因。

步骤3:检查项目依赖 在一些情况下,404错误可能是由项目依赖不完整或错误的版本引起的。请确保以下内容:

  1. 检查项目的依赖管理文件(如pom.xml)中是否包含正确的依赖项,并且版本号正确。
  2. 检查依赖项的配置是否正确,特别是与URL映射和页面路径相关的依赖项(如Spring MVC)。

如果以上步骤都没有解决问题,可能需要进一步检查项目的日志、运行时错误和调试信息,以确定更具体的原因。

总结:根据提供的信息,可以尝试通过检查项目配置文件、检查代码中的路径配置和检查项目依赖等步骤来解决该问题。如果以上步骤都没有解决问题,可能需要进一步分析日志、运行时错误和调试信息,以确定更具体的原因。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^