package com.sandbox.spring.controller;

import com.sandbox.spring.model.CityResult;
import com.sandbox.spring.mybatis.pojo.City;
import com.sandbox.spring.service.CityService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Author: zhangxin
 * Date:   15-6-30
 */
@Controller
@RequestMapping(value = "city")
public class CityController {
    @Resource(name = "cityService")
    private CityService cityService;

    @RequestMapping(value = "message/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Object getCity(@PathVariable("id") Integer id) {
        return cityService.get(id);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Object getCity(@RequestParam(value = "name")String name) {
        return cityService.get(name);
    }

    @RequestMapping(value = "index", method = RequestMethod.GET)
    public Object freemarkerIndex() {
        return "city";
    }

    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    public Object freemarkerQuery(Model model, HttpServletRequest request, @PathVariable Integer id) {
//        int id = Integer.parseInt(request.getParameter("id"));
        CityResult result = (CityResult)cityService.get(id);
        model.addAttribute("city", result);
        return "city";
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Object freemarkerAdd(Model model, HttpServletRequest request) {
        String name = request.getParameter("name");
        int population = Integer.parseInt(request.getParameter("population"));
        String province = request.getParameter("province");
        City city = new City();
        city.setName(name);
        city.setPopulation(population);
        city.setProvince(province);
        cityService.insert(city);
        return "city";
    }
}

@@ -949,32 +949,326 @@
 t(name);%0A    %7D%0A%0A
+    @RequestMapping(value = %22empty%22, method = RequestMethod.POST)%0A    @ResponseBody%0A    public Object testEmptyStringParam(@RequestParam(value = %22param%22)Integer param) %7B%0A        if(param == null)%0A            return %22param is null.%22;%0A        else%0A            return %22param is not null.%22;%0A    %7D%0A%0A
     @RequestMapp

test empty string parameter