Completed a working version of Bookmark service. Feeling great~~ ha! ha! Finding something to practice is an efficient way of learning. The project concept is redesigned from a MongoDB project. Weeks ago, I was learning MongoDB and NodeJS. Mixing everything together is my hobby. There might be conflictions, but putting all strengths together has higher potential to resolve difficult and complex problems. Elites getting together might sometimes not be easy, I mean technology, of course. Nice things deserve practice.
https://www.mongodb.com/blog/post/building-your-first-application-mongodb-creating-rest-api-using-mean-stack-part-1
After redesign…… is ….extremely simple…. But contains enough new topics for me to explore. I’m just a starter of Spring (and a veteran of OO and Cloud programming). Keep everything simple and fast.
I applied to cloud services (like AWS), online artist supporting platform (like Patreon), delivery service (like foodpanda), bioinformatics (so curious…), education (like D2L), etc. …. Don’t know why no further response…. Anyway, I focus on what I can do to prove myself. When I’m an IT, I probably would avoid IT topics. If my current part-time work depletes my strength, I may need to hide in a hospital (just kidding). An IT usually has habits of sharing. We grow up upon others sharing, and just do the same vice versa. (I'll change this when my status is different.)
Other than IT, my expertise are analyzing and learning. My sharing is usually not to show my skills, but to guide the progress. Since starting from C socket to Spring REST takes me 10 days, it’s no point to estimate my current capability or predict how far I can go in the next half year. Here shows how I started a topic and proceeded to working status. To be expert at any IT skill needs practice. And I constantly go astray and mix together all I know are my way of practice. Maybe I’m learning WordPress or Bootstrap. Maybe I’m learning NodeJS or MongoDB. Maybe I’m learning Flask or Python. Maybe… I like multiphase~
https://spring.io/guides/tutorials/rest/
Spring’s REST tutorial is a good reference for this bookmark project. I only read half to complete the working version. Of course with a lot of research. The previous MongoDB is too simple so I lost my previous concept of Spring MVC. Combined with Baeldung’s explain on annotation, path variables, and parameters, and endless debugging…… It’s really helpful.
https://www.baeldung.com/spring-request-param
Bookmark service was designed as 3 layers, but I would pause at 2 layers, because when I master the structure of the 1st layer, the second layer is almost copy-past….
Spring provides two types of database access. One is Database-client, the other is Repository. I already knew how to use databases, so I tried Repository. The default output looks pretty(previous MongoDB sample) and attractive. …..but when Spring hands out the data to me….. Understandable is good enough…..
https://docs.spring.io/spring-data/mongodb/docs/3.0.0.RELEASE/reference/html/#mongodb.repositories.queries
Bookmark service is using Page to handle a list of URL(string) as the first layer. And use Bookmark to collect Pages as the second layer. From MongoDB example, it shows how to use Spring provided CURD commands to directly access class properties.
What I need in Page is to access property as a list. @RequestBody analyses class structure. It’s convenient. Correctly writing the json list is a valid way to create class data.
https://github.com/atfuture7/awsrepo/tree/master/java/04_mongoBookmark/
To modify a list requires customized functionality. I don’t want to write the entire list each time when adding/deleting one string. Here came a terrible divorce (just kidding). Spring doesn’t introduce my extended interface. I have to write my own controllers and show not-pretty-at-all results.
If you don’t want anything mysterious to happen to you, follow the naming convention…
<class name>Repository (for repository interface)
<class name>Repository + Custom (for extended interface)
<class name>Repository + Impl (the implementation of extended interface…)
Spring keeps one instance in the factory (what visible is assigned to Controller), so the variable in Repository should be denoted as @Autowire for linking. If you forget @Autoware and declare the object somewhere else, service won’t start and it will probably be difficult to find where the problem is…. I fixed linking error on PageRepositoryImpl and lost my version due to Git revert while adding Bookmk layer. And the linking error then appeared at BookmkRepositoryImpl ….
This post is long enough for now. The progress of Page development is better as:
Page
-> PageRepository
-> PageController
-> PageRepositoryCustom
-> PageRepositoryImpl
(->PageNotFoundException
-> PageNotFoundAdvice ) (or ignore while can’t figure out how pageNotFoundHandler jumps out …. Naming convention? )
(to be continue…)
Comments
Post a Comment