Spring Boot Learning (iii) Building restful APIs and unit tests

Source: Internet
Author: User
Tags class definition json

The @controller, @RestController, @RequestMapping annotations we used before. If you are unfamiliar with spring MVC and have not tried a QuickStart case, it is advisable to look at the SPRINGMVC annotation first; @Controller: Modifier class, which is used to create an object that handles HTTP requests @RestController: Annotations added after Spring4, the original return of JSON in @controller requires @responsebody to match, If you replace @controller directly with @restcontroller, you do not need to configure @responsebody, which returns the JSON format by default. @RequestMapping: Configuring URL Mappings

Here we try to use spring MVC to implement a set of restful APIs to manipulate the user object, with annotations detailing how HTTP requests are mapped in spring MVC, how to pass parameters, and how to write unit tests.

The RESTful API is specifically designed as follows:


User.java entity class definition:

01 Package com.xiaojingg.domain;
02 /**
03 * @author Xiao in GG
04 */
05 public class User {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.