0% found this document useful (0 votes)
2 views

Spring_curd

The document outlines a Spring Boot application named 'spring_curd' that connects to a MySQL database. It includes an entity class 'Subjects', a repository interface 'SubRep', a service class 'SubService', and a controller 'SubjectController' for managing subject data. The application is configured to show SQL queries and automatically update the database schema.

Uploaded by

Vivek Rohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Spring_curd

The document outlines a Spring Boot application named 'spring_curd' that connects to a MySQL database. It includes an entity class 'Subjects', a repository interface 'SubRep', a service class 'SubService', and a controller 'SubjectController' for managing subject data. The application is configured to show SQL queries and automatically update the database schema.

Uploaded by

Vivek Rohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring_curd:

Application.property:
spring.application.name=spring_curd
spring.datasource.url=jdbc:mysql://localhost:3306/bca
spring.datasource.username=root
spring.datasource.password=Vivek@123
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.database=mysql

Entity: Subjects.java
package com.sample.spring_curd.entity;

import jakarta.persistence.Entity;

import jakarta.persistence.GeneratedValue;

import jakarta.persistence.GenerationType;

import jakarta.persistence.Id;

@Entity

public class Subjects {

@Id

@GeneratedValue(strategy = GenerationType.AUTO)

private Long id;

private String dep;

private String dep_code;

public Subjects() {
super();

public Subjects(Long id, String dep, String dep_code) {

super();

this.id = id;

this.dep = dep;

this.dep_code = dep_code;

public Long getId() {

return id;

public void setId(Long id) {

this.id = id;

public String getDep() {

return dep;

public void setDep(String dep) {

this.dep = dep;

public String getDep_code() {

return dep_code;

public void setDep_code(String dep_code) {

this.dep_code = dep_code;

Repository: SubRep.java [I]


package com.sample.spring_curd.rep;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.stereotype.Repository;

import com.sample.spring_curd.entity.Subjects;

@Repository

public interface SubRep extends JpaRepository<Subjects, Long> {

Service: SubService.java
package com.sample.spring_curd.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sample.spring_curd.entity.Subjects;
import com.sample.spring_curd.rep.SubRep;
@Service
public class SubService {
@Autowired
private SubRep dep;
public List<Subjects> dep_view() {
return dep.findAll();
} }

Controller: SubjectController.java
package com.sample.spring_curd.controller;
import java.util.List;
mport org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sample.spring_curd.entity.Subjects;
import com.sample.spring_curd.service.SubService;
@RestController
@RequestMapping
public class SubjectController {
@Autowired
private SubService ds;
@GetMapping("/view")
public List<Subjects> view(){
return ds.dep_view();
} }

You might also like