Spring MVCに@Controllerと @RequestMappingの基本使い方

1.@Controllerアノテーション
package com.example.controller;
import org.springframework.stereotype.Controller;
@Controller
public class ProductController {
}

コンテキスト
xmlns:context=http://www.springframework.org/schema/context

アノテーションドライバ
xmlns:mvc=http://www.springframework.org/schema/mvc

サンプルコード:
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package=""></context:component-scan>

2.@RequestMappingアノテーション
@Controller
public class ProductController {

@RequestMapping(value="/productInput")
public String inputProduct(){
//write some code
return “ProductForm";
}
}

3.POSTまたはPUTの場合、check()を呼び出す
@RequestMapping(value="/orderproc", method={RequestMethod.POST, RequestMethod.PUT})
public String check(){
//code
return “showpage";
}

4.RequestMappingの使い方
import org.springframework.stereotype.Controller;
@Controller
@RequestMapping(value="/customer")
public class CustomerController{
@RequestMapping(value="/delete", method={RequestMethod.POST, RequestMethod.PUT})
public String deleteCustomer(){
//write some code
return “showpage”;
}
}

Java

Posted by arkgame