项目地址https://gitee.com/chenshiyun/wolfcode-web
学校实训让我们下载这个项目,然后添加一个appdemo页面
我使用项目中的代码生成器,按照如下步骤操作
然后访问appdemo页面,会显示404
但其他的页面都可以正常访问,如下图
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映射和页面路径。请检查以下内容是否正确配置:
如果配置文件中的URL映射和页面路径正确配置了,但仍然出现404错误,那可能是其他原因导致的。
步骤2:检查代码中的路径配置 根据提供的信息,日志显示当前访问接口为/demotest/list.html,但代码中的路径不同。这可能是导致404错误的原因之一。请根据以下步骤检查代码中的路径配置:
如果以上步骤都检查无误,但问题仍然存在,可能需要进一步检查其他可能原因。
步骤3:检查项目依赖 在一些情况下,404错误可能是由项目依赖不完整或错误的版本引起的。请确保以下内容:
如果以上步骤都没有解决问题,可能需要进一步检查项目的日志、运行时错误和调试信息,以确定更具体的原因。
总结:根据提供的信息,可以尝试通过检查项目配置文件、检查代码中的路径配置和检查项目依赖等步骤来解决该问题。如果以上步骤都没有解决问题,可能需要进一步分析日志、运行时错误和调试信息,以确定更具体的原因。