A super beginner has completed the Spring introductory book, so I will summarize it in my own way

Introduction

Spring book completed !! URL of the book I will try to summarize it lightly in my own way. There are some parts where I am not good at Japanese and some parts I lack knowledge, but I would appreciate it if you could read it.

About the environment

OpenJDK14.0.2 STS4? Maven3.6? Also, I put Lombok in STS.

DI (Dependency Injection)

DI mainly does these two things. By doing DI (use?), You can save the trouble of creating an instance with new and putting it in a variable. You can also prevent forgetting to put null in the used variable.

About Autowired

If you add Autowired, it will automatically create an instance. (It seems that the class with the annotation that is the target of DI is automatically generated.) It seems to be a singleton, so I think it was easy for errors to occur. Please note that an error will occur if multiple beans of the same type are registered in the DI container. To avoid it, use @Qualifier to specify the name (file name).

GetMapping,PostMapping GetMapping-> Processing when the specified URL is accessed by GET request (get data) PostMapping-> Processing when the specified URL is accessed by POST request (register data)

@Data If you add Data annotation, getter and setter will be generated automatically. (Lombok function) When changing specifications, you can take flexible measures.

Validation

You can implement validation just by annotating each field of the form class. About validation ↑ There are various instructions on this site. Just add @validated to the argument of the model you want to validate and the validation will be done.

AOP (Aspect Oriented Programming)

Extract the processing common to each class. Manage all together. Advice (processing content), PointCut (execution location), JointPoint (execution timing) In the book I was using, I used it to send messages to the console, such as when running the controller. It will show you which controller you are running.

JDBC Mainly used when dealing with databases in Spring.

Register, update, delete-> update method Data count-> queryForObject method Select statement to get 1 case-> queryForMap method Select statement to get multiple records-> queryForList method

application

About the error

If you specify the key from Model, you can get the details of the error content.

Not only the common error page but also the template according to the error status can be applied.

About REST

A service that returns JSON etc. in response to HTTP requests. Create a controller for REST and add @RestContorller to the class With @RestController, the return value of the method of that class is returned to the caller. PUT method-> @PutMapping DELETE method-> @DeleteMapping

About JUnit (Spring Test)

A library that can automate tests with java Just add the test annotation and it becomes a test class.

@RunWith (SpringRunner.class)-> You can specify in which class the test will be run.

@SpringBootTest-> Starts SpringBoot and then starts the test.

@Sql-> Tested in the state after executing the specified SQL.

To test the controller, use a mock.

By using @WithMockUser, you can test the display of pages with only Admin privileges.

Finally

It's a little thin summary, but I would like to make an effort to deepen my understanding and improve it so that I can look back on it.

Thank you for reading.

If you find any typographical errors or omissions, please comment.

Recommended Posts

A super beginner has completed the Spring introductory book, so I will summarize it in my own way
I stumbled on the Java version in Android Studio, so I will summarize it
[Swift] I already have a lot of information, but I tried to summarize the cast (as, as !, as?) In my own way.
I tried to summarize object orientation in my own way.
Since the unit test of the PJ I was in charge of was a hell picture, I will publish my own guide (?)
I passed Ruby Silver (June 2020), so I will summarize it.
When I tried to run my own service, it failed, so I screwed it into the task scheduler
RSocket is supported in Spring Boot 2.2, so give it a try
I passed the Java test level 2 so I will leave a note
"RSpec doesn't work!" The cause was spring, so I investigated it.
We will build a Spring Framework development environment in the on-premises environment.