springmvc

代码:

@ResponseBody
    @RequestMapping("/hello3/{hello}")
    public String hello3(@PathVariable String hello) {
        return hello;
    }

 代码:

package com.logan.SpringBootDemo01.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MyController {
    
    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
    
    @ResponseBody
    @RequestMapping("/hello1")
    public String hello1() {
        return "hello1";
        
    }
    
    @ResponseBody
    @RequestMapping("/hello2")
    public String hello2() {
        return "hello2";
    }
    
    @ResponseBody
    @RequestMapping("/hello3/{hello}")
    public String hello3(@PathVariable String hello) {
        return hello;
    }
    
    @ResponseBody
    @RequestMapping("/hello4")
    //可以这样访问http://localhost:8080/hello4?type1=2&type=3
    public int hello4(@RequestParam int type) {
        return type;
    }
    

}
原文地址:https://www.cnblogs.com/LoganChen/p/13208741.html