Skip to content

Instantly share code, notes, and snippets.

class Singleton {
private volatile static Singleton object;
private Singleton() {}
public static Singleton getInstance() {
if (object == null) {
synchronized (Singleton.class) {
if (object == null)
object = new Singleton();
class Singleton {
// Creating an Instance
private static Singleton object = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return object;
}
class Singleton {
//static field
private static Singleton object;
//private Construtor
private Singleton() {}
//static method
public static synchronized Singleton getInstance()
class Singleton {
//static field
private static Singleton object;
//private Construtor
private Singleton() {}
//static method
public static Singleton getInstance()
import com.knoldus.wallet.model.StudentInfo;
import com.knoldus.wallet.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface StudentRepository extends JpaRepository<StudentInfo, String> {
//We can add our derivable query also.
}
spring.datasource.url=jdbc:mysql://localhost:3306/database_name
spring.datasource.username=root
spring.datasource.password=root
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
<!-- jpa,repository -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
// find the document by Id and mapped to the corresponding POJO
Employee emp = couchbaseTemplate.findById("id", Employee.class);