赞
踩
如果一个项目略大
发现在单一的controller中直接写class类十分混乱
这里来介绍如何写出简洁便用的controller层
这个包名就写上你的模块名(这里是admin模块)
如图
分别是管理员模块 有关管理员 的操作 (增删改查管理员)
管理员模块 有关产品 的操作(增删改查产品)
模块名加业务名
写成requsetmapping
然后具体的业务操作再往下写
package com.example.back.controller.admin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @ResponseBody @RequestMapping("/admin/Admin") public class adminAdminController { @GetMapping("/list") void list(){ System.out.println("list"); } @DeleteMapping("/del") void del(){ System.out.println("del"); } }
package com.example.back.controller.admin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @ResponseBody @RequestMapping("/admin/product") public class adminProductController { @GetMapping("/list") void hello(){ System.out.println("hello"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。