Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – implementing RESTful web services


We are going to add a shopping cart facility in two phases. Firstly, we will create a REST-style controller to handle all shopping-cart-related web requests. Secondly, we will add some JavaScript code to render the JSON data returned by the REST web service controller. First, let's implement some RESTful web services using Spring MVC controllers so that later we can add some JavaScript code to consume those web services.

  1. Create a domain class named CartItem under the package com.packt.webstore.domain in the source folder src/main/java; then, add the following code to it:

    package com.packt.webstore.domain;
    
    import java.math.BigDecimal;
    
    public class CartItem {
    
      private Product product;
      private int quantity;
      private BigDecimal totalPrice;
      
      public CartItem() {
        // TODO Auto-generated constructor stub
      }
      
      public CartItem(Product product) {
        super();
        this.product = product;
        this.quantity = 1;
        this.totalPrice =...