1 | mvn clean package -DskipTests=true |
1 | mvn clean install -DskipTests=true |
Run Spring boot application from command line
1 2 3 4 5 6 7 | //Using the Maven plugin mvn spring-boot:run //Passing environment mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=production" |
1 2 3 | //Running as a packaged application (You can use mvn clean install OR mvn clean package to generate jar file) java -jar your-project-folder/target/myproject-0.0.1-SNAPSHOT.jar |
ref: –spring-boot-docs
Option 1
1 2 3 4 5 6 7 8 9 10 | @RequestMapping(value = "/{customerId}/data/{startDate}/{endDate}", method = RequestMethod.GET) public void getUserData(@PathVariable("customerId") long customerId, @PathVariable("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate, @PathVariable("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate, HttpServletRequest request, HttpServletResponse response) throws Exception { //Your logic will be here :) } |
Option 2
1 2 3 4 | public void getmyData(@RequestParam("date") @DateTimeFormat(pattern = "dd-mm-yyyy") LocalDate date) { //Do stuff } |
Add packages
1 2 | import javax.servlet.http.HttpServletRequest; //optional import javax.servlet.http.HttpServletResponse; |
Add status with response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | @RequestMapping(value = "/{customerId}", method = RequestMethod.GET) public void getMydata(@PathVariable("customerId") int customerId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (is != null) { //-----Success part----- } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } } |