简体   繁体   中英

Spring boot + H2 database

Here is my project :

  • create react app on front.

  • Spring boot connected with H2.

everything works fine, I created an Entity class matchi the database :

package pfc.app;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class History {


@Id @GeneratedValue

private Long id;
private String winner;



public History(String wn){

this.winner=wn;

}

// getters and setter.

}

I would like to access and modify the HISTORY table on my H2 database from that controller :

@RequestMapping("/choice")
    public String choice() {

        //Access data
   return "Ok";

    }

I'll need to select some values, to add some values etc.. I have no problem with the SQL queries, I need to know how to access the database from there !

Hope it's clear.

Thanks ^^.

All you need is a Repository class( CrudRepository should be enough) to get access to the table.
Please follow this doc:
https://spring.io/guides/gs/accessing-data-jpa/

If you still have problem, please comment I can help you further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM