1.访问方式
http://localhost:8080/huang/liu1?id=1
package com.hls;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.*;/** * Created by huangliusong on 2017/7/18. */@RestController@RequestMapping("/huang")public class HelloController { @Autowired private Boyproperties boyproperties; @RequestMapping(value={"/liu1","/liu2"},method = RequestMethod.GET) public String say (@RequestParam("id") Integer myid){ return "index.html?"+myid; }}
效果
2.访问方式http://localhost:8080/huang/liu1/1
package com.hls;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.*;/** * Created by huangliusong on 2017/7/18. */@RestController@RequestMapping("/huang")public class HelloController { @Autowired private Boyproperties boyproperties; @RequestMapping(value={"/liu1/{id}","/liu2"},method = RequestMethod.GET) public String say (@PathVariable("id") Integer id){ return "index.html?"+id; }}