试了很多方法,还是不行之后突发奇想是不是注解的问题
后来查了@RestController和@Controller
以下是我的代码访问老是404。
@RequestMapping(value = "/getConfig")
JSONObject getConfig (){
//未做登录
log.error("查询配置页面");
JSONObject config = new JSONObject();
JSONObject indexConfig = new JSONObject();
indexConfig.put("title","首页");
indexConfig.put("href","/pages/layuimini/page/welcome-1.html?t=1");
config.put("homeInfo",indexConfig);
JSONObject titleConfig = new JSONObject();
titleConfig.put("title","xxxx");
titleConfig.put("image","/pages/layuimini/images/logo.png");
titleConfig.put("href","");
config.put("logoInfo",titleConfig);
return config;
}
这是我Controller的头改成这样就可以了
@RestController
@RequestMapping(value = "/company")
public class CompanyCtl extends BaseCtl {
传送门
概括一下这个门的重点
你加上的是RestController,那么返回的内容是你return中的内容,如果是return “Hello World”,页面显示的就是Hello World。但是如果你加上Controller,返回的是return中对应的页面,比如return “hello”,页面的名称是hello,此时如果你的项目中没有hello这个页面,那么必然会出现404的错误,当然,你也可以在返回类型旁边加上responsebody注解。