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

Source: Internet
Author: User
Tags http request json

The @controller, @RestController, @RequestMapping annotations we used earlier. If you are unfamiliar with spring MVC and have not yet tried the QuickStart case, it is recommended to take a look at Springmvc's annotations first; @Controller: Modifier class, used to create an object to handle an HTTP request @RestController: Spring4 added after the note, the original in the @controller back JSON needs @responsebody to cooperate, 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

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

The RESTful API is specifically designed as follows:


User.java entity class definitions:

01 Package com.xiaojingg.domain;
02 /**
03 * @author into 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.