javaweb后台controller包中有的代码看不懂,哎,求教,谢谢! 20
@RequestMapping(value="dscCompany",method=RequestMethod.GET)publicStringindex(ModelMa...
@RequestMapping(value="dscCompany",method=RequestMethod.GET)
public String index(ModelMap modelMap,HttpServletRequest request){
return "dscCompany";
}
@RequestMapping(value="dscCompany/queryByPage")
@ResponseBody
public Object queryByPage(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap, HttpServletRequest request){
return dscCompanyService.queryByPage(dscCompany,request);
}
@RequestMapping(value="dscCompany/combo",method=RequestMethod.GET)
@ResponseBody
public Object combo(ModelMap modelMap, HttpServletRequest request){
return dscCompanyService.combo(request);
}
@RequestMapping(value="dscCompany/cud")
@ResponseBody
public Object cud(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap,HttpServletRequest request){
return dscCompanyService.cud(dscCompany, request);
}
@RequestMapping(value="dscCompany/tree",method=RequestMethod.GET)
@ResponseBody
public Object tree(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap,HttpServletRequest request){
return dscCompanyService.tree(dscCompany, request);
} 展开
public String index(ModelMap modelMap,HttpServletRequest request){
return "dscCompany";
}
@RequestMapping(value="dscCompany/queryByPage")
@ResponseBody
public Object queryByPage(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap, HttpServletRequest request){
return dscCompanyService.queryByPage(dscCompany,request);
}
@RequestMapping(value="dscCompany/combo",method=RequestMethod.GET)
@ResponseBody
public Object combo(ModelMap modelMap, HttpServletRequest request){
return dscCompanyService.combo(request);
}
@RequestMapping(value="dscCompany/cud")
@ResponseBody
public Object cud(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap,HttpServletRequest request){
return dscCompanyService.cud(dscCompany, request);
}
@RequestMapping(value="dscCompany/tree",method=RequestMethod.GET)
@ResponseBody
public Object tree(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap,HttpServletRequest request){
return dscCompanyService.tree(dscCompany, request);
} 展开
2个回答
展开全部
这是spring mvc的典型用法,要看懂这些代码,首先要弄懂spring mvc的工作机制。对于工作机制,这里不做重点描述,只大概说下:
spring mvc 您要关注的是几个配置文件:views配置,这个是用来配置view name和页面之间的映射,当您在代码中使用view name时,通过这个配置文件查找要渲染的页面;spring-mvc的配置,这里配置您页面跳默诵、返回结果转换、渲染框架(titles/volicty等等)……详情您可查阅相关资料。
这里只对代码做下简要的说明:
/**
* 注解表明,方法对应REST风格url的请求,
* http://……/(class 上的RequestMapping)/dscCompany
* @return 返回的是view name,也就是views.xml中这个名称对应的页面
*/
@RequestMapping(value="dscCompany",method=RequestMethod.GET)
public String index(ModelMap modelMap,HttpServletRequest request){
return "dscCompany";
}
/**
* 注解表明,方法对应REST风格url的请求,这是一个post请求
* http://……/(class 上的RequestMapping)/dscCompany/queryByPage
* ModelAttribute(value="dscCompany") 表示获取请求中的参数dscCompany
* @ResponseBody 这个注解表明返回的不是view,而是实际的数据结果,如果在
* spring-mvc.xml中配有json转换器的话,结果会转换为json返回到客户端,这种
* 形式一般用于ajax请求,局部动态将查询结果页面进行渲染。
* @return 返回的是的是查询结果
*/
@RequestMapping(value="dscCompany/queryByPage")
@ResponseBody
public Object queryByPage(@ModelAttribute(value="dscCompany") DscCompany dscCompany,ModelMap modelMap, HttpServletRequest request){
return dscCompanyService.queryByPage(dscCompany,request);
}
//……其他的几个方法同queryByPage访求类似,用于ajax请求,对页面局部进行动态渲染
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询