我在学习Spring MVC时试图理解我的项目代码.
在Spring中,@ RequestMapPing注释需要参数.例如,
@RequestMapPing(value="/something",method=RequestMethod.POST)@RequestMapPing(value="/index.HTML",method=RequestMethod.GET)@RequestMapPing("/index")@RequestMapPing(params="command=GETINFO")
我的项目使用注释,它不使用任何XML进行映射.我有一个以下的控制器结构.
@Controllerpublic class RuleStepController { private static final String ATTRIBUTE_BRANCH = "branch"; private static final String ATTRIBUTE_EDIT_FORM = "editForm"; ................. @autowired private RuleStepService ruleStepService; @autowired private PopulationDao populationDao; @RequestMapPing public voID ruleStepEntForm(Long populationID,ModelMap model) { ..... editForm.setStepEnt(stepDto); }@RequestMapPing public voID ruleStepOrgCount(RuleStepOrgSearchForm searchForm,ModelMap model){ .......model.addAttribute("searchForm",searchForm); }@RequestMapPing public String ruleStepMgrForm() { logger.deBUG(String.format("ruleStepMgrForm")); return "forward:/employee/employeeSearchForm.vIEw?relationshipID=0&roleID=0&formID=stepMgr"; }
我想了解@RequestMapPing在没有任何参数的情况下有什么意义?
@autoWired的用途是什么?
最佳答案>使用注释@RequestMapPing,您可以通过多种方式绑定请求参数:URI模板模式,使用注释@PathVariable
@RequestMapPing(value="/owners/{ownerID}",method=RequestMethod.GET)public String findOwner(@PathVariable String ownerID,Model model) { Owner owner = ownerService.findOwner(ownerID); model.addAttribute("owner",owner); return "displayOwner";}
请求参数和标头值
@Controller@RequestMapPing("/owners/{ownerID}")public class relativePathUriTemplateController { @RequestMapPing(value = "/pets/{petID}",method = RequestMethod.GET,params = "myParam=myValue") public voID findPet(@PathVariable String ownerID,@PathVariable String petID,Model model) { // implementation omitted }}
使用@RequestParam
@Controller@RequestMapPing("/pets")@SessionAttributes("pet")public class EditPetForm { @RequestMapPing(method = RequestMethod.GET) public String setupForm(@RequestParam("petID") int petID,ModelMap model) { Pet pet = this.clinic.loadPet(petID); model.addAttribute("pet",pet); return "petForm"; }}
使用@Requestbody注释映射请求正文
@RequestMapPing(value = "/something",method = RequestMethod.PUT)public voID handle(@Requestbody String body,Writer writer) throws IOException { writer.write(body);}
>自动装配
@autowiredprivate RuleStepService ruleStepService;
Spring Container之前创建了bean ruleStepService.如果你需要在你的类中使用这个bean,你只需要如上所述声明,容器会将bean注入你的类.你不需要声明像;
RuleStepService ruleStepService =new RuleStepService().
Container将找到bean名称ruleStepService或bean具有类型RuleStepService(基于配置中的策略) 总结
以上是内存溢出为你收集整理的java – 在Spring MVC中没有参数的@RequestMapping全部内容,希望文章能够帮你解决java – 在Spring MVC中没有参数的@RequestMapping所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)