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()