springmvc註解詳解
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<? xml version = "1.0" encoding = "UTF-8" ?>< beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:p = "http://www.springframework.org/schema/p" xmlns:context = "http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> < context:component-scan base-package = "org.springframework.samples.petclinic.web" /> <!-- ... --> </ beans > |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
@Controller @RequestMapping ( "/favsoft" ) public class AnnotationController { @RequestMapping (method=RequestMethod.GET) public String get(){ return "" ; } @RequestMapping (value= "/getName" , method = RequestMethod.GET) public String getName(String userName) { return userName; } @RequestMapping (value= "/{day}" , method=RequestMethod.GET) public String getDay(Date day){ DateFormat df = new SimpleDateFormat( "yyyy-MM-dd" ); return df.format(day); } @RequestMapping (value= "/addUser" , method=RequestMethod.GET) public String addFavUser( @Validated FavUser favUser,BindingResult result){ if (result.hasErrors()){ return "favUser" ; } //favUserService.addFavUser(favUser); return "redirect:/favlist" ; } @RequestMapping ( "/test" ) @ResponseBody public String test(){ return "aa" ; } } |
String findOwner( String , Model model) { FavUser favUser = favUserService.findFavUser(); model.addAttribute( ; } |
@RequestMapping(value="/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)public String findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { Owner owner = ownerService.findOwner(ownerId); Pet pet = owner.getPet(petId); model.addAttribute("pet", pet); return "displayPet"; }
@RequestMapping(value = "/something", method = RequestMethod.PUT)public void handle(@RequestBody String body, Writer writer) throws IOException { writer.write(body); }
@RequestMapping(value = "/something", method = RequestMethod.PUT)@ResponseBodypublic String helloWorld() { return "Hello World"; }
@RequestMapping("/something")public ResponseEntity<String> handle(HttpEntity<byte[]> requestEntity) throws UnsupportedEncodingException { String requestHeader = requestEntity.getHeaders().getFirst("MyRequestHeader")); byte[] requestBody = requestEntity.getBody(); // do something with request header and body HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("MyResponseHeader", "MyValue"); return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED); }
@ModelAttribute public Account addAccount(@RequestParam String number) { return accountManager.findAccount(number); } @ModelAttribute public void populateModel(@RequestParam String number, Model model) { model.addAttribute(accountManager.findAccount(number)); // add more ... }
相關文章
- SpringMVC--常用註解(詳解)SpringMVC
- springmvc常用註解標籤詳解SpringMVC
- SpringMVC註解講解(一)SpringMVC
- SpringMvc的常用註解SpringMVC
- SpringMvc筆記-註解SpringMVC筆記
- 【SpringMVC】@RequestMapping註解SpringMVCAPP
- Springmvc全註解開發SpringMVC
- Lombok 註解詳解Lombok
- Java註解詳解Java
- Java 註解詳解Java
- SpringMVC工作原理詳解SpringMVC
- SpringMVC詳解(補加)SpringMVC
- SpringMVC的@ResponseBody註解說明SpringMVC
- SpringMvc的常用註解介紹SpringMVC
- @FeignClient註解詳解client
- Java註解(Annotation)詳解Java
- Spring註解詳解Spring
- Java註解詳解「註解專案實戰」Java
- SpringMVC註解和非註解(xml)的方法的異同點SpringMVCXML
- springMVC請求流程詳解SpringMVC
- SpringMVC返回(return)方式詳解SpringMVC
- SpringMVC詳解(二)------詳細架構SpringMVC架構
- SpringMVC 解析(三) Controller 註解SpringMVCController
- SpringMVC:@ResponseBody註解與HttpServletResponse物件SpringMVCHTTPServlet物件
- Java ”框架 = 註解 + 反射 + 設計模式“ 之 註解詳解Java框架反射設計模式
- Java註解最全詳解(超級詳細)Java
- SwaggerAPI註解詳解,以及註解常用引數配置SwaggerAPI
- Spring IoC 公共註解詳解Spring
- Google-Gson註解使用詳解Go
- 胖哥學SpringMVC:Hello World 註解版SpringMVC
- Java註解處理器使用詳解Java
- SpringMVC入門學習---使用註解開發SpringMVC
- SpringMVC【開發Controller】詳解SpringMVCController
- [譯]SpringMVC自定義驗證註解(SpringMVC custom validation annotations)SpringMVC
- Java 執行時(RUNTIME)註解詳解Java
- springboot介面接參註解詳解Spring Boot
- 基於註解的 Spring MVC詳解SpringMVC
- SpringBoot註解最全詳解(整合超詳細版本)Spring Boot