Day 02 Spring Boot Lab Guide
Day 02 Spring Boot Lab Guide
Lab Book
Every Project implemented in Spring Boot must have the below flow:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=admin123
server.port=8081
package net.codejava;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Product
{
private Integer id;
private String name;
private float price;
public Product()
{
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId()
{
return id;
}
@Override
public String toString()
{
return "Product [id=" + id + ", name=" + name + ", price=" + price + "]";
}
}
Step 2: Create a class for ProductController
package net.codejava;
import java.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
@RestController
public class ProductController
{
@Autowired
private ProductService service;
package net.codejava;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Transactional
public class ProductService
{
@Autowired
private ProductRepository repo;
package net.codejava;
import org.springframework.data.jpa.repository.JpaRepository;
Step 6: Install & Open POSTMAN Rest in Browser. Perform CRUD operations