@PathVariable

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

@Controller
@RequestMapping("/learnMVC")
public class LearnMVCController {
     //子索引由 ex+參數+參數 組成
    @RequestMapping("/ex/{type}/{articleId}")
    public String learnMVC(@PathVariable(value = "type") String typeGot,
            @PathVariable(value = "articleId") Integer articleIdGot, Model model) {
        String str = "URL後面所傳輸的參數為:" + typeGot + "/" + articleIdGot;
        model.addAttribute("msgGot", str);
        return "learnMVC.ftl";
    }
}

@PathVariable實現原理和@RequestParam相似 , 可以取得URL傳回來的值

results matching ""

    No results matching ""