SpringBoot
// Класс контроллера
@RestController
@RequestMapping("/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/all")
public List<Employee> getAllEmplpyee() {
logger.info("get All Employeee");
return employeeService.getAllEmployeeService();
}
}
// ServiceImpl
@Service
public class EmployeeService {
private static final Logger logger = LoggerFactory.getLogger(EmployeeService.class);
@Autowired
private EmployeeRepository employeeRepository;
public List<Employee> getAllEmployeeService() {
logger.info(getClass().getName()," invked getAllEmployee");
List<Employee> empBo = employeeRepository.findAll();
return copyPropertiesValues(empBo);
}
}
// DAO
@Component
public interface EmployeeRepository extends JpaRepository<Employee, String>{
}
// Модель
@Entity
@Table(name = "employees")
public class Employee {
@Id
@Column(name = "employeeNumber",nullable=false)
private String employeeNumber;
@Column(nullable=false)
private String lastName;
@Column(nullable=false)
private String firstName;
@Column(nullable=false)
private String extension;
@Column(nullable=false)
private String email;
@Column( nullable=false)
private String officeCode;
@Column(nullable=false)
private String reportsTo;
@Column(nullable=false)
private String jobTitle;
//GETTER SETTER
}
// application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=****