Spring Java

java -jar spring-tool-suite-4-4.5.1.RELEASE-e4.14.0-win32.win32.x86_64.self-extracting.jar
-vm
C:\Program Files\Java\jdk1.8.0_211\bin\javaw.exe

File → New → Spring Starter Project → Next → Check the following to use web features and hot deploy

  1. Developer Tools→Spring Boot DevTools
  2. Web→Spring Web → Finish

new.png

pom.xml


<dependencies>
・ ・ ・
 <!-- web -->
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <!--Hot deploy-->
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <scope>runtime</scope>
  <optional>true</optional>
 </dependency>
・ ・ ・
</dependencies>

IndexController.java




package com.example.demo;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
	private static final Logger log = LoggerFactory.getLogger( IndexController.class );

    @RequestMapping("/")
    private String index() {
        return "index";
    }

    @RequestMapping(value="/", method=RequestMethod.GET)
    private Map<String, Object> index( @RequestParam("id") Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        return map;
    }

    @RequestMapping(value="/items/{id}", method=RequestMethod.GET)
    private Item get(@PathVariable int id) {
    	return new Item(id);
    }

    @RequestMapping(value="/items", method=RequestMethod.POST)
    private void post(@RequestBody String body) {
    	log.info("post, " + body);
    }

    @RequestMapping(value="/items/{id}", method=RequestMethod.PUT)
    private void put(@PathVariable int id, @RequestBody String body) {
    	log.info("put, " + id + ", " + body);
    }

    @RequestMapping(value="/items/{id}", method=RequestMethod.DELETE)
    private void delete(@PathVariable("id") int id) {
    	log.info("delete, " + id);
    }

    public static class Item {
        private int id;

    	Item (int id) {
    		this.setId(id);
    	}

    	public int getId() {
    		return id;
    	}

    	public void setId(int id) {
    		this.id = id;
    	}
    }
}

Recommended Posts

Spring Java
[Java] Spring DI ③
Java
Java
Java Config with Spring MVC
Spring + Gradle + Java Quick Start
[Java] Thymeleaf Basic (Spring Boot)
[Java] Spring AOP execution order
CICS-Run Java application-(4) Spring Boot application
Using Mapper with Java (Spring)
Java tips --Spring execution Summary
[Java] How Spring DI works
[Java] [Spring] Spring Boot 1.4-> 1.2 Downgrade Note
Spring Boot + Java + GitHub authentication login
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
spring × docker
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Java Spring environment in vs Code
Studying Java ―― 4
java shellsort
[Java] compareTo
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
About Spring ③
[Java] Polymorphism
Java review
java framework
Java features
Elastic Beanstalk (Java) + Spring Boot + https
[Java] Inheritance
FastScanner Java
Java --Jersey Framework vs Spring Boot
Java features
java beginner 3
Java memo