1、基本

@Controller       控制层
@Service         业务层
@Component    组件
@Repository     dao

2、@RequestMapping url

三、restful 风格

与python的restful差不多

1、不用restful风格

访问链接

http://localhost:8090/add?a=1&b=3

控制层

package com.wt.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

// 控制注解
@Controller
public class HelloControl {
    @RequestMapping("/add")
    public String showHi(int a, int b, Model model){
        String result = "结果是:" + (a + b);
        model.addAttribute("msg", result);
        return "hi";
    }
}

2、使用restful风格

注意:注解 PathVariable

// 控制注解
@Controller
public class HelloControl {
    @RequestMapping("/add/{a}/{b}")
    public String showHi(@PathVariable int a, @PathVariable int b, Model model){
        String result = "结果是:" + (a + b);
        model.addAttribute("msg", result);
        return "hi";
    }
}

3、请求方式

GET POST PUT DELETE

// 控制注解
@Controller
public class HelloControl {
//    @RequestMapping(name="/add/{a}/{b}", method = RequestMethod.GET)
    @GetMapping("/add/{a}/{b}")
    public String showHi(@PathVariable int a, @PathVariable int b, Model model){
        String result = "结果是:" + (a + b);
        model.addAttribute("msg", result);
        return "hi";
    }
}
@PostMapping()
@PutMapping()
@DeleteMapping()

 

相关文章:

  • 2021-07-12
  • 2021-09-14
  • 2021-10-12
  • 2022-12-23
  • 2022-01-11
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-03
  • 2021-06-25
  • 2022-12-23
  • 2021-11-17
  • 2022-01-04
  • 2021-09-14
  • 2021-10-19
相关资源
相似解决方案