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.
OpenJDK14.0.2 STS4? Maven3.6? Also, I put Lombok in STS.
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.
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.
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.
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
RowMapper Inherit and implement RowMapper. Use it when you have a lot of similar SELECT statements to improve the readability of your code. In the process of Mapper class, the result of SELECT statement is set in the instance and returned as a return value.
BeanRowMapper Can be implemented without preparing RowMapper. Functionally the same as above Automatic mapping is possible. But you have to do the following:
Column name-> user_id (separated by underscore) (Snake case)
Field name-> userId (capitalize from second word) (camel case)
ResultSetExtractor
Implemented by inheriting ResultSetExtractor <List
RowCallbackHandler Callback processing. A process is requested, and after the process is completed, the result is received and the next process starts. It is used when you want to use the data for the next processing after acquiring the data. For example ... Output CSV from the user list screen. (Since the user list data is required to output CSV, acquire it before proceeding to the next process.)
NamedParameterJdbcTemplate Arguments are passed to the SQL statement using?, But in NamedParameterJdbcTemplate, it is specified by: key name. To set the parameters to be included in the SQL statement, use the SqlParameterSource class and set the key and value in the addValue () method.
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.
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
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.
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.