《web应用技术》第三次课后练习

本文介绍了如何通过SpringBoot创建入门程序,使用Postman进行参数练习,并详细展示了前端页面如何向后端发送数据,包括产品名称和价格的提交过程。
摘要由CSDN通过智能技术生成

实验目的:

1、springboot入门程序撰写并启动。(参考B站黑马视频Day04-10. Web入门-SpringBootWeb-快速入门_哔哩哔哩_bilibili

2、使用postman练习参数的获取。(参考B站黑马视频)

3、体会前端页面向后端发送数据的过程。并且自己尝试将之前的注册页面的信息发送到服务端。

(1)、product.html的操作代码,输入产品名称和价格,点击“增加商品”按钮,页面返回“ok”。服务台返回用户输入的值。相关页面如下:

注意,这里action的属性值需要根据情况变更不同的值

相关代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body style="font-size: 30px">
<form action="addProduct">

  产品名称 :<input type="text" name="name" value=""><br />
  产品价格: <input type="text" name="price" value=""><br />

  <input type="submit" value="增加商品">

  <br><br><br><br>test2,addProduct1 ,productResult.html
</form>
</body>
</html>
package edu.wust.pojo;

public class Product {

    private String name;
    private float price;


    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }



}
package edu.wust.controller;
import edu.wust.pojo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import edu.wust.pojo.Product;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ProductController {

    @RequestMapping("/addProduct1")
    public String simpleParam1(HttpServletRequest request) {
        String name = request.getParameter("name");
        String ageStr = request.getParameter("price");
        int price = Integer.parseInt(ageStr);
        System.out.println("addProduct1:"+name + "  :  " + price);
        return "OK";
    }

    @RequestMapping("/addProduct")
    public String simpleParam(String name , Integer price){
        System.out.println("您输入的信息是:"+name+"  :  "+price);
        return "OK";
    }

    @RequestMapping("/addProduct2")
    public String simpleParam2(Product product){
        System.out.println(product);
        return "OK";
    }

}

(2)、自己尝试将之前的注册页面的信息发送到服务端。

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值