spring mvc传值 html取值

Controller中:

@Controller

@RequestMapping(value="")

public class IndexController {

   @RequestMapping(value = "/trackStationInfo/{trackId}")
    public String getTrackStation(Model model, @PathVariable String trackId){
        model.addAttribute("trackId",trackId);
        return "trackStationInfo";

    }
}


或者

  @RequestMapping(value = "/trackStationInfo")
    public String getTrackStation(Model model, String trackId){
        model.addAttribute("trackId",trackId);
        return "trackStationInfo";
    }


页面中




   
    Insert title here









如果是第一种controller写法:

ajax中:

    url:"/api/station/getStationByStationName/"+stationName,


网页中打开:localhost:6999/trackStationInfo/{26}

其中26为trackId

  

如果是第二种controller写法:

ajax中:

   url: "/api/equipment/getEquipment/?trackId="+trackId,


网页中打开:localhost:6999/trackStationInfo?trackId=26

其中26为trackId


    


你可能感兴趣的:(HTML)