Create Project: entity_application (add Spring Boot Starters from the table)
Create Package: entities (inside main package)
– Create Class: PersonEntity.java (inside package entities)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
PersonEntity.java
package com.ivoronline.entity_application.entities;
public class PersonEntity {
public Long id;
public String name;
public Integer age;
}
MyController.java
package com.ivoronline.entity_application.controllers;
import com.ivoronline.entity_application.entities.PersonEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
PersonEntity personEntity = new PersonEntity();
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
personEntity.name = "John";
String name = personEntity.name;
return "Hello " + name;
}
}