Jpa Cheat Sheet for annotations

Entity @Entity - marks class as the database entity @Entity public class Pokemon{} @Table - table name @Table(name = "Poke") public class Pokemon { } @Id - mark the primary key Annotate primary key @Id private int id; @GeneratedValue - the strategy for primary key GenerationType @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; GenerationType.IDENTITY The database is set AUTO_INCREMENT. Similar to SQL id NOT NULL AUTO_INCREMENT GenerationType.SQUENCE GenerationType.TABLE Use the TABLE in database to set the primary key for us, instead of the DBMS system....

January 15, 2023 · 16 min · Derry

Docker Cheat sheet, a general cheat sheet for all use case

Docker general Help - docker COMMAND --help This is for each command’s detail For example, docker run --help TL;DR docker run <image> - to initialize a new container docker start <container_name> start running the “stopped” container docker stop <container_name> docker run - Initialize a container Run a command in a new container Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Basic form to initialize a container, or to run a command...

January 8, 2023 · 9 min · Derry

Spring Boot Controller Service Repository

Spring RESTful service Laur Spilca Youtube Tutorial series spring docs Spring Restful service is a popular backend application. The architecture usually is made up with 3 layers: Controller, Service, and Repository. Configuration setup @SpringBootApplication - define the app root The start point of program It’s with @ComponentScan - tell spring to create beans in which the classes have been annotated with. Spring RESTful Service architecture Spring RESTful service usually has this architecture....

January 1, 2023 · 7 min · Derry

Curl cheat sheet, for web developement

HTTP Request Specify Method by -X Form: curl -X <METHOD> <URI> By default, it uses GET method curl https://www.google.com/ # same as curl -X GET https://www.google.com/ Use Post simply by: curl -X POST https://www.example.com/ GET Get entire document of the website in terminal curl https://www.google.com/ POST curl -X POST https://example.com/ More complex, pass data, -d and header -H to server. Below shows POST with json body curl -d '{"option": "value", "something": "anothervalue"}' \ -H "Content-Type: application/json" \ -X POST https://example....

December 18, 2022 · 1 min · Derry

Java Abstract Class and how to use it? When we combine it with interface?

Java abstract class An abstract class is like a structure of data. However, unlike interface, it can define methods and attribute. You can view it as an enforced blueprint for an object. You cannot initiate an object from it but from its sub-classes. An abstract class is: It cannot be instantiated It can contain constructor and object fields. Contains abstract method (0 to many), and concrete methods Its subclasses must override its abstract method An abstract class example:...

December 11, 2022 · 3 min · Derry