Một số Annotation trong Java Spring thường sử dụng

Written by IT Phú Trần on 04/07/2017 in HỌC SPRING CORE and LẬP TRÌNH SPRING MVC with 179 comments.

Trong quá trình lập trình sử dụng Spring Framework, đặc biệt là lập trình Spring MVC để xây dựng một ứng dụng web thì việc thường xuyên sử dụng các Annotation trong spring là điều khó tránh khỏi.

Annotation hay còn được gọi là chú thích, được sử dụng để cung cấp thông tin dữ liệu cho mã Java của bạn. Trong bài viết này, tôi sẽ hướng dẫn và đưa ra một số Annotation trong Java Spring thường được sử dụng nhất.

Dưới đây là một số Annotation trong Spring thường dùng đi kèm với các ví dụ cụ thể

@Autowired

@Autowired: Annotation này trong spring giúp tự động liên kết các Bean lại với nhau, đây là một trong những đặc điểm nỗi bật của Spring để thể hiện tính chất DI và IOC (Dependency Injection và Inversion of Control).

Ví dụ về annotation @Autowired:


@Scope

@Scope: đây là môt Annotation mặc định trong Spring, hầu hết scope phổ biến cho các autodetected components là singleton (singleton: Với mỗi bean container chỉ tao duy nhất một đối tượng), để thay đổi phạm vi ta sử dụng @Scope.

Ví dụ về annotation @Scope:


@Component

@Component: dùng để scan các components.

Ví dụ về annotation @Component:


@Repository

@Repository:  dùng để scan các components để đánh dấu các lớp DAO/Repository của Spring.

Ví dụ về annotation @Repository:


@Service

@Service: dùng để scan các components để đánh dấu các Service của lớp business.

Ví dụ về annotation @Service:


@Transactional

@Transactional: Annotation này trong spring giúp đánh dấu các class có sử dụng đến Transaction do Spring quản lý.

Ví dụ về annotation @Transactional:


@Controller

@Controller: đây là môt Annotation trong spring mvc dùng để đánh dấu đây là lớp có chức năng là Controller.

Ví dụ về annotation @Controller:


@RequestMapping

@RequestMapping: đây là môt Annotation trong spring mvc dùng để cấu hình URL tương ứng với @WebServlet và mapping trong file xml với JSP/servlet.

Ví dụ về annotation @RequestMapping:


@RequestParam

@RequestParam: đây là môt Annotation trong spring mvc dùng để gán một request parameter vào một parameter của phương thức.Thường dùng để lấy dữ liệu từ form và các biến tham số trên URL.
Ví dụ về annotation @RequestParam:

Java-Annotations trong spring

@InitBinder

@InitBinder: đây là môt Annotation trong spring mvc dùng để đánh dấu một phương thức có tùy biến các ràng buộc dữ liệu.
Ví dụ về annotation @InitBinder:

@SessionAttribute

@SessionAttribute: đây là môt Annotation trong spring mvc dùng để chỉ định một modelAttribute sẽ được lưu trong session.
Ví dụ về annotation @SessionAttribute:

@Valid

@Valid: đây là môt Annotation trong spring mvc dùng để ràng buộc đối tượng hay các Param bị ràng buộc để thực hiện kiểm tra tính hợp lệ cho form.
Ví dụ về annotation @Valid:


@ModelAttribute

@ModelAttribute: đây là môt Annotation trong spring mvc dùng để lấy các tham số và trả về một đối tượng (Object).

Ví dụ về annotation @ModelAttribute:


Trên là một số annotation trong spring framework thường dùng, tất nhiên vẫn còn rất nhiều annotation khác, tuy nhiên tôi không nhắc đến trong bài viết này. Hy vọng với một số annotation mà tôi đưa ra ở trên sẽ giúp các bạn giải đáp một số thắc mắc và áp dụng vào thực tế ứng dụng web.

179 Responses to “Một số Annotation trong Java Spring thường sử dụng

  1. Dear Phú,
    Mi có thể giải thích kỹ hơn phần này được không.
    Cảm ơn.
    Bạn cùng lớp với mi
    Hoàng

  2. Hey, I think your blog might be having browser compatibility issues.
    When I look at your blog site in Ie, it looks fine
    but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other
    then that, excellent blog!

  3. Just desire to say your article is as amazing. The clarity in your post
    is simply nice and i could assume you are an expert
    on this subject. Well with your permission let
    me to grab your feed to keep up to date with forthcoming post.
    Thanks a million and please carry on the enjoyable work.

  4. This piece of writing is in fact a nice one it helps new net users,
    who are wishing for blogging.

  5. Thank you for the auspicious writeup. It in fact was a amusement
    account it. Look advanced to far added agreeable from you!
    By the way, how can we communicate?

  6. When someone writes an post he/she retains the idea of a user in his/her brain that how a user can be aware
    of it. So that’s why this post is great. Thanks!

  7. It’s perfect time to make a few plans for the long run and it
    is time to be happy. I’ve read this submit and if I could I wish to recommend you some interesting things or advice.
    Perhaps you can write subsequent articles referring to this article.
    I wish to read even more things about it!

  8. It’s perfect time to make some plans for the future and it’s time to be happy.

    I’ve read this post and if I could I want to suggest you some interesting
    things or tips. Maybe you can write next articles referring to this article.
    I desire to read more things about it!

  9. Google

    Here are some hyperlinks to web sites that we link to simply because we assume they are really worth visiting.

  10. Google

    Please take a look at the websites we stick to, like this a single, because it represents our picks from the web.

  11. spolorm hund behandling

    […]although internet sites we backlink to beneath are considerably not connected to ours, we really feel they’re truly really worth a go as a result of, so possess a look[…]

  12. Healthy salty snacks

    […]that may be the end of this post. Here you’ll come across some sites that we assume you will appreciate, just click the hyperlinks over[…]

  13. Al-Zaytoonah Elibrary

    Explore electronic resources for free, thousands of eBooks, accounting eBooks, business eBooks, Marketing eBooks, Accounting eBooks, Banking eBooks, Design eBooks, Customers eBooks, Travel and Tourism eBooks… and more

  14. bdsm toy

    […]just beneath, are various totally not associated web sites to ours, nevertheless, they may be surely really worth going over[…]

  15. adam and eve sex toy shop

    […]we like to honor many other world wide web web sites on the internet, even though they aren’t linked to us, by linking to them. Underneath are some webpages worth checking out[…]

  16. sex hd جديد

    […]Wonderful story, reckoned we could combine several unrelated information, nonetheless actually worth taking a search, whoa did a single study about Mid East has got additional problerms too […]

  17. top 5 sex toys

    […]Wonderful story, reckoned we could combine a number of unrelated data, nonetheless definitely worth taking a search, whoa did one particular study about Mid East has got much more problerms at the same time […]

  18. best lube for sex

    […]although internet websites we backlink to below are considerably not associated to ours, we feel they’re truly really worth a go through, so possess a look[…]

  19. best blow job tips

    […]we like to honor many other world-wide-web internet sites on the web, even though they aren’t linked to us, by linking to them. Beneath are some webpages worth checking out[…]

  20. Make massive income

    […]although websites we backlink to beneath are considerably not connected to ours, we feel they’re really worth a go by means of, so have a look[…]

  21. penis rings

    […]we prefer to honor several other world wide web websites around the net, even when they aren’t linked to us, by linking to them. Underneath are some webpages really worth checking out[…]

  22. daftar sbobet

    […]we prefer to honor many other online websites on the web, even when they aren’t linked to us, by linking to them. Under are some webpages worth checking out[…]

  23. free robux

    […]the time to read or pay a visit to the content material or internet sites we have linked to beneath the[…]

  24. best cbd oil for pain

    […]check below, are some completely unrelated internet websites to ours, having said that, they’re most trustworthy sources that we use[…]

  25. Gizmoist.com

    […]please take a look at the internet sites we stick to, including this one, as it represents our picks from the web[…]

  26. realistic dong

    […]very couple of internet websites that transpire to be detailed below, from our point of view are undoubtedly very well worth checking out[…]

  27. جولف سيتي العبور

    […]we prefer to honor a lot of other online sites on the web, even if they aren’t linked to us, by linking to them. Underneath are some webpages really worth checking out[…]

  28. XXX VIDEO

    […]Every once in a when we opt for blogs that we study. Listed below are the newest web pages that we decide on […]

  29. ETORRENT PORN

    […]here are some hyperlinks to sites that we link to for the reason that we consider they may be really worth visiting[…]

  30. gamesfriv

    […]here are some hyperlinks to web-sites that we link to since we consider they are really worth visiting[…]

  31. ViaGrA

    […]Every the moment inside a when we pick out blogs that we read. Listed below would be the most up-to-date internet sites that we decide on […]

  32. cbd oil for anxiety

    […]very couple of internet websites that transpire to become in depth below, from our point of view are undoubtedly effectively really worth checking out[…]

  33. cbd for insomnia

    […]that is the end of this post. Here you will find some sites that we consider you’ll enjoy, just click the hyperlinks over[…]

  34. best CBD oil

    […]Every when inside a while we choose blogs that we study. Listed beneath are the latest internet sites that we select […]

  35. I simply want to tell you that I am newbie to blogging and site-building and honestly loved you’re web blog. Probably I’m want to bookmark your blog . You amazingly come with impressive article content. Kudos for sharing your website.

  36. An fascinating discussion is worth comment. I think that it’s best to write more on this topic, it won’t be a taboo topic however usually individuals are not enough to speak on such topics. To the next. Cheers

  37. One more issue is that video gaming became one of the all-time main forms of recreation for people spanning various ages. Kids participate in video games, and also adults do, too. Your XBox 360 is one of the favorite games systems for folks who love to have a lot of video games available to them, and who like to experiment with live with some others all over the world. Many thanks for sharing your opinions.

  38. Spot on with this write-up, I seriously feel this web site needs a great deal more attention. I’ll probably be returning to read more, thanks for the info!

  39. I blog quite often and I seriously appreciate your information. This great article has truly peaked my interest. I am going to book mark your website and keep checking for new details about once per week. I opted in for your Feed as well.

  40. I’m amazed, I must say. Rarely do I come across a blog that’s both educative and engaging, and without a doubt, you’ve hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. I’m very happy that I came across this during my search for something regarding this.

  41. May I simply say what a relief to discover somebody that really knows what they’re talking about over the internet. You definitely understand how to bring a problem to light and make it important. More and more people should check this out and understand this side of your story. It’s surprising you’re not more popular since you certainly have the gift.

  42. I blog often and I really thank you for your content. Your article has really peaked my interest. I’m going to bookmark your blog and keep checking for new information about once per week. I opted in for your RSS feed as well.

  43. I’m extremely pleased to find this page. I wanted to thank you for your time just for this wonderful read!! I definitely really liked every little bit of it and I have you book marked to see new stuff on your web site.

  44. When I initially left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get four emails with the same comment. Is there a means you can remove me from that service? Kudos.

  45. I’m impressed, I must say. Rarely do I encounter a blog that’s both equally educative and amusing, and without a doubt, you have hit the nail on the head. The problem is something that not enough folks are speaking intelligently about. I’m very happy I found this during my search for something regarding this.

  46. I blog frequently and I truly thank you for your content. The article has really peaked my interest. I am going to take a note of your blog and keep checking for new details about once per week. I subscribed to your RSS feed too.

  47. It’s hard to come by well-informed people in this particular subject, but you sound like you know what you’re talking about! Thanks

  48. Right here is the right site for anyone who wishes to find out about this topic. You realize so much its almost tough to argue with you (not that I personally will need to…HaHa). You certainly put a fresh spin on a topic which has been written about for years. Great stuff, just wonderful.

  49. Your style is very unique compared to other people I have read stuff from. Thanks for posting when you have the opportunity, Guess I’ll just bookmark this blog.

  50. When I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve four emails with the same comment. There has to be a way you can remove me from that service? Cheers.

  51. Hi there! I could have sworn I’ve been to
    this blog before but after looking at many of the articles I realized it’s new to
    me. Anyways, I’m definitely delighted I stumbled
    upon it and I’ll be bookmarking it and checking back often!

  52. I’m amazed, I must say. Rarely do I come across a blog that’s both equally educative and amusing, and let me tell you, you have hit the nail on the head. The issue is an issue that too few men and women are speaking intelligently about. I am very happy that I stumbled across this during my hunt for something concerning this.

  53. It can be mostly impossible to see well-advised individuals on this theme, still you seem like you be aware of what you’re preaching about! Excellent

  54. Thanks a bunch for sharing this with all folks you really realize what you are speaking about!

    Bookmarked. Please additionally talk over with
    my site =). We could have a hyperlink change arrangement among us

  55. I have to thank you for the efforts you have put in writing this website. I’m hoping to see the same high-grade content by you in the future as well. In fact, your creative writing abilities has encouraged me to get my own website now 😉

  56. I just desire to share it with you that I am new to posting and utterly liked your information. More than likely I am going to remember your blog post . You truly have fantastic article materials. Admire it for discussing with us your favorite internet document

  57. My brother recommended I may like this website. He was entirely right.
    This submit truly made my day. You cann’t consider just how much
    time I had spent for this information! Thanks!

  58. I truly love your site.. Excellent colors & theme. Did you build this website yourself? Please reply back as I’m trying to create my very own blog and want to find out where you got this from or what the theme is named. Thank you!

  59. I just intend to inform you that I am new to blog posting and clearly enjoyed your page. Most likely I am likely to store your blog post . You absolutely have excellent article materials. Appreciate it for expressing with us your very own internet post

  60. Having read this I believed it was extremely enlightening. I appreciate you taking the time and energy to put this short article together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worth it.

  61. Good site you have here.. It’s difficult to find excellent writing like yours nowadays. I honestly appreciate individuals like you! Take care!!

  62. May I just say what a relief to find somebody who truly knows what they’re talking about on the web. You definitely realize how to bring a problem to light and make it important. More people really need to look at this and understand this side of the story. It’s surprising you aren’t more popular given that you definitely possess the gift.

  63. Oh my goodness! Amazing article dude! Thank you, However I am experiencing problems with your RSS. I don’t understand the reason why I cannot subscribe to it. Is there anybody getting identical RSS issues? Anybody who knows the answer will you kindly respond? Thanx!!

  64. That is a really good tip especially to those fresh to the blogosphere. Brief but very precise information… Thank you for sharing this one. A must read article.

  65. Right here is the perfect web site for everyone who would like to find out about this topic. You know so much its almost hard to argue with you (not that I actually will need to…HaHa). You certainly put a new spin on a topic that’s been discussed for many years. Excellent stuff, just wonderful.

  66. I was more than happy to uncover this web site. I wanted to thank you for ones time due to this wonderful read!! I definitely really liked every part of it and I have you book marked to look at new things on your website.

  67. I’m very pleased to find this great site. I need to to thank you for your time just for this wonderful read!! I definitely enjoyed every little bit of it and i also have you saved to fav to check out new things on your web site.

  68. This is the perfect webpage for everyone who wants to find out about this topic. You realize a whole lot its almost hard to argue with you (not that I really will need to…HaHa). You certainly put a new spin on a subject which has been written about for ages. Wonderful stuff, just wonderful.

  69. You’ve made some good points there. I checked on the net to find out more about the issue and found most individuals will go along with your views on this site.

  70. This web site definitely has all of the information and facts I wanted concerning this subject and didn’t know who to ask.

  71. MetroClick specializes in building completely interactive products like Photo Booth for rental or sale, Touch Screen Kiosks, Large Touch Screen Displays , Monitors, Digital Signages and experiences. With our own hardware production facility and in-house software development teams, we are able to achieve the highest level of customization and versatility for Photo Booths, Touch Screen Kiosks, Touch Screen Monitors and Digital Signage. Visit MetroClick in NYC at http://www.metroclick.com/ or , 121 Varick St, New York, NY 10013, +1 646-843-0888.

  72. This is a good tip especially to those new to the blogosphere. Short but very precise info… Appreciate your sharing this one. A must read post.

  73. An outstanding share! I’ve just forwarded this onto a friend who has been conducting a little research on this. And he actually bought me breakfast simply because I stumbled upon it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending the time to talk about this issue here on your blog.

  74. This is the perfect webpage for anyone who really wants to find out about this topic. You know a whole lot its almost tough to argue with you (not that I really would want to…HaHa). You certainly put a fresh spin on a topic which has been written about for many years. Excellent stuff, just great.

  75. Can I simply just say what a relief to discover a person that actually understands what they’re talking about on the web. You definitely realize how to bring an issue to light and make it important. More and more people must check this out and understand this side of the story. It’s surprising you are not more popular because you surely possess the gift.

  76. Excellent site you have got here.. It’s difficult to find quality writing like yours nowadays. I truly appreciate individuals like you! Take care!!

  77. Oh my goodness! Incredible article dude! Thanks, However I am encountering difficulties with your RSS. I don’t know why I can’t subscribe to it. Is there anybody else getting similar RSS issues? Anybody who knows the answer can you kindly respond? Thanx!

  78. Howdy! This post could not be written much better! Looking at this post reminds me of my previous roommate! He continually kept preaching about this. I will forward this article to him. Fairly certain he will have a very good read. Thank you for sharing!

  79. Nice post. I learn something totally new and challenging on sites I stumbleupon everyday. It’s always exciting to read content from other writers and use something from their websites.

  80. The very next time I read a blog, Hopefully it does not disappoint me as much as this one. After all, I know it was my choice to read, however I genuinely thought you would have something useful to say. All I hear is a bunch of complaining about something you could possibly fix if you weren’t too busy searching for attention.

  81. Great web site you’ve got here.. It’s difficult to find high quality writing like yours nowadays. I really appreciate individuals like you! Take care!!

  82. Hey, you used to write fantastic, but the last few posts have been kinda boring… I miss your tremendous writings. Past several posts are just a little out of track! come on!

  83. Everything is very open with a clear clarification of the challenges. It was definitely informative. Your site is extremely helpful. Many thanks for sharing.

  84. After looking into a handful of the blog articles on your web site, I really like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Please visit my website too and let me know your opinion.

  85. Aw, this was an incredibly nice post. Taking a few minutes and actual effort to create a superb article… but what can I say… I put things off a lot and don’t seem to get nearly anything done.

  86. Hello there! I simply would like to offer you a huge thumbs up for the excellent information you have right here on this post. I’ll be coming back to your web site for more soon.

  87. Spot on with this write-up, I truly believe this website needs much more attention. I’ll probably be back again to see more, thanks for the info.

  88. An intriguing discussion is worth comment. There’s no doubt that that you ought to write more about this subject, it may not be a taboo subject but typically people don’t speak about these issues. To the next! Best wishes.

  89. Oh my goodness! Impressive article dude! Thank you so much, However I am going through troubles with your RSS. I don’t understand why I can’t join it. Is there anybody having identical RSS issues? Anyone that knows the answer will you kindly respond? Thanx!

  90. You are so awesome! I do not suppose I’ve truly read something like this before. So great to discover another person with original thoughts on this subject. Really.. thanks for starting this up. This site is one thing that is required on the internet, someone with a bit of originality.

  91. The next time I read a blog, I hope that it does not disappoint me just as much as this one. I mean, I know it was my choice to read through, nonetheless I truly thought you’d have something interesting to say. All I hear is a bunch of moaning about something that you can fix if you were not too busy seeking attention.

  92. May I simply just say what a relief to discover a person that truly understands what they’re talking about on the web. You certainly realize how to bring an issue to light and make it important. A lot more people need to look at this and understand this side of your story. I was surprised you are not more popular since you definitely have the gift.

  93. Hello there! This post couldn’t be written much better! Reading through this article reminds me of my previous roommate! He constantly kept talking about this. I’ll forward this post to him. Pretty sure he’s going to have a good read. I appreciate you for sharing!

  94. Greetings! Very helpful advice in this particular post! It is the little changes that will make the most significant changes. Thanks a lot for sharing!

  95. I needed to thank you for this good read!! I definitely loved every little bit of it. I have got you book-marked to check out new stuff you post…

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *