新手注意的问题 package cn.ryq.web.controller; import cn.ryq.domain.company.Company;import cn.ryq.service.company.CompanyService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView; import java.util.Date;import java.util.List; @Controller@RequestMapping("/system/company")public class CompanyController { @Autowired public CompanyService companyService; @RequestMapping("/list.do") public ModelAndView list(){ List<Company> list = companyService.findAll(); ModelAndView mv= new ModelAndView(); mv.addObject("list",list ); mv.setViewName("company/company-list"); return mv; }}在确保ApplicationContext-service.xml,有扫包(可以通过右边的小叶子图标来查看是否有扫到包)CompanyController控制器中有@Controller,再检查web.xml的配置,一般情况下我们都是用多个模块去完成一个项目,那么web.xml下就如下配置,
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring/applicationContext-*.xml</param-value></context-param>加载配置文件的路径加*,让web可以扫到整个项目的配置文件!
原文地址:https://www.cnblogs.com/ryq1121/p/11067765.html
时间: 2024-11-05 04:08:06