0

I am trying to create a in memory database in spring boot... Still learning about spring boot and databases. How would I create an in memory database for this. I want to create an in memory database with 3 REST endpoints...

This is what I've done so far:

package com.jason.spring_boot;
/**
 * The representational that holds all the fields
 * and methods
 * @author Jason Truter
 *
 */
public class Employee {

    private final long id;
    private final String name;
    private final String surname;
    private final String gender;

    public Employee(long id, String name, String surname, String gender){
        this.id = id;
        this.name = name;
        this.surname = surname;
        this.gender = gender;
    }

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getSurname() {
        return surname;
    }

    public String getGender() {
        return gender;
    }


}




package com.jason.spring_boot;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * The resource controller handles requests
 * @author Jason Truter
 *
 */

@Controller
@RequestMapping("/employee")
public class EmployeeController {


    private final AtomicLong counter = new AtomicLong();


    /**
     * GET method will request and return the resource
     */
    @RequestMapping(method=RequestMethod.GET)
    public @ResponseBody Employee getEmployee(@RequestParam(value = "name", defaultValue = "Stranger") String name, 
            String surname, String gender){
        return new Employee(counter.getAndIncrement(), name, surname, gender);
    }


}




package com.jason.spring_boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
java4life
  • 1
  • 1
  • 3
    The sample project https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-rest has everything that you should need – Kartik Pandya Nov 03 '16 at 17:58
  • I'm still basically new to programming, and trying to learn as much as I can... havn't used Github before, can you explain where I should look? – java4life Nov 03 '16 at 18:54
  • I'm going to try work on this myself and learn as much as I can – java4life Nov 04 '16 at 01:02
  • What are you planning to use to access the database? Hibernate? Straight JDBC code? – Miner_Glitch Nov 04 '16 at 03:34
  • spring-boot provides much of easy understanding demo code and great explanations. You should read some of it and you will learn how to develop with spring-boot soon. – Patrick Nov 04 '16 at 07:18

0 Answers0