123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package com.lovecoding.springmvc;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.servlet.http.HttpSession;
- /**
- * RestFil 风格API接口
- * 一般我们设计 RESTFIL 风格接口, 会在类上 注解一个 请求路径
- * 然后在 方法上 设计 增删改查等操作, 使用不同的 Method 方法处理不同的业务
- *
- */
- @Controller
- @RequestMapping("/student")
- public class StudentController {
- /**
- * 新增操作
- * @param studentId
- * @return
- */
- @RequestMapping(
- value ="/{studentId}",
- method = RequestMethod.POST)
- public String add(@PathVariable(
- value = "studentId",
- required = true) Long studentId, HttpSession httpSession){
- System.out.println( "新增学员操作成功!!: " + studentId );
- httpSession.setAttribute("action", "添加成功 ID:" + studentId);
- return "/success.jsp";
- }
- /**
- * 删除操作
- * @param studentId
- * @return
- */
- @RequestMapping(
- value ="/{studentId}",
- method = RequestMethod.DELETE)
- @ResponseBody
- public String del(@PathVariable(
- value = "studentId",
- required = true) Long studentId, HttpSession httpSession){
- System.out.println( "删除学员操作成功!!: " + studentId );
- httpSession.setAttribute("action", "删除成功 ID:" + studentId);
- return "Delete Student Success!!: " + studentId;
- //return "/success.jsp";
- }
- /**
- * 修改操作
- * @param studentId
- * @return
- */
- @RequestMapping(
- value ="/{studentId}",
- method = RequestMethod.PUT)
- @ResponseBody
- public String update(@PathVariable(
- value = "studentId",
- required = true) Long studentId, HttpSession httpSession){
- System.out.println( "修改学员操作成功!!: " + studentId );
- httpSession.setAttribute("action", "修改成功 ID:" + studentId);
- return "Update Student Success!!: " + studentId;
- //return "/success.jsp";
- }
- /**
- * 查询操作
- * @param studentId
- * @return
- */
- @RequestMapping(
- value ="/{studentId}",
- method = RequestMethod.GET)
- public String get(@PathVariable(
- value = "studentId",
- required = true) Long studentId, HttpSession httpSession){
- System.out.println( "查询学员操作成功!!: " + studentId );
- httpSession.setAttribute("action", "查询成功 ID:" + studentId);
- return "/success.jsp";
- }
- }
|