Skip to content

Instantly share code, notes, and snippets.

@relax-more
Created September 26, 2012 10:31
Show Gist options
  • Save relax-more/3787243 to your computer and use it in GitHub Desktop.
Save relax-more/3787243 to your computer and use it in GitHub Desktop.
lombok model & spring framework sample
package my.snippet.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.NotEmpty;
@SuppressWarnings("serial")
@Data
public class Form {
@NotEmpty
private String table;
@NotEmpty
private String statsX;
@NotEmpty
private String statsY;
}
package my.snippet.controller;
import java.util.List;
import my.snippet.model.Form;
import my.snippet.service.MyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
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 extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(StatsController.class);
@Autowired
private MyService service;
@RequestMapping(value = "/api/sample")
@ResponseBody
public List<?>sample(@ModelAttribute("Form") final Form form) throws ApiException {
try {
LOGGER.debug("form input:{}", form.toString());
} catch (Exception e) {
e.printStackTrace();
throw new ApiException(ResultCode.INTERNAL_ERROR, e.getLocalizedMessage());
}
return service.getAnyList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment