A detailed introduction to annotations in the SpringMVC framework

Table of contents

foreword

1. @Controller annotation (used on the class)

2. @RequestMapping (used on the class)

3. @RequestMapping (used on the method)

4. @ResponseBody annotation (used on the method)


foreword

The SpringMVC framework is specially used for web development. The reason why it has been loved by programmers since its birth is not only because it belongs to the Spring family, but also because of its concise and efficient annotation mechanism, and Simple and easy to understand features. Then we will specifically introduce the detailed usage of annotations in the SpringMVC framework today.

1. @Controller annotation (used on the class)

By using this annotation, you can almost judge whether your project uses the SpringMVC framework. As shown below

 The use of the @Controller annotation is very simple. We only need to remember that this annotation is used on the class to indicate that the current class is similar to the Servlet class.

2. @RequestMapping (used on classes)

When we see the @RequestMapping annotation on a class, it indicates that all methods in this class must be accessed by adding this path when they are accessed. As shown below

 Note: When the @RequestMapping annotation is used above the class, the method in the class can continue to use the @RequestMapping annotation, and there is no restriction between the two.

3. @RequestMapping (used on methods)

 4. @ResponseBody annotation (used on the method)

This annotation does not have any attributes, and the @ResponseBody annotation will only be used when the return value type of the method in the class where @Controller is located is data (such as: return entity class, List<>, String string,,,). As shown below



! ! Notice! !

The following content is an ancient poem that I recite every day. If you don’t believe it, I don’t believe it either. If you don't like it, you don't have to read a word.

Yueyang Tower

In the spring of the fourth year of Qingli, Teng Zijing was relegated to Baling County. In the next year, the government will be smooth and the people will be harmonious, and the waste will be prosperous. The Yueyang Tower will be rebuilt, its old system will be added, and poems by Tang sages and modern people will be engraved on it.

Yuguanfu Baling Shengzhang is in a lake in Dongting. Holding the distant mountains, swallowing the Yangtze River, the vastness of the soup, the horizon is endless, the sun shines in the morning and the shadows in the evening, and the atmosphere is myriad. This is the grand view of Yueyang Tower, which is well described by the predecessors. However, Wu Gorge in the north, Xiaoxiang in the Antarctic, and tourists and poets often come here, and the feeling of looking at things is the same?

If the husband is obscene and rainy, the moon never opens, the wind howls, the turbid waves empty, the sun and stars hide, the mountains hide, business travel is impossible, masts are tilted and boats are destroyed, dusk is dark, tigers roar and monkeys cry. When going to Silou, there are those who go to the country and cherish their hometown, worry about slander, fear ridicule, look sad, feel extremely sad.

As far as Ruochun and Jingming, the waves are calm, the sky is light up and down, a vast expanse of blue, sand gulls flying, golden scales swimming, shore Zhitinglan, lush and green. And maybe the long smoke is gone, the bright moon is thousands of miles away, the floating light jumps into gold, the still shadow sinks into the jade, and the fisherman's songs answer each other. What a joy! Ascending Silou, there are those who feel relaxed and happy, forget favors and disgraces together, and enjoy the wine with the wind.

Husband! I have tried to seek the heart of ancient benevolent people, or the difference between the two, why? Don't be happy with things, don't be sad with yourself, if you live high in the temple, you will worry about your people; if you live far away in the rivers and lakes, you will worry about your king. It is also worrying about advancing, and worrying about retreating. So when will you be happy? It must be said, "worry about the world's worries first, and enjoy the world's joy later"! Alas! Micro man, who I go?

It was September 15th, six years.

 

Guess you like

Origin blog.csdn.net/weixin_44362089/article/details/127463313