第三次web作业

作业1 运行springboot

package com.example.demo.demos.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class controller {
    @RequestMapping("/hello0")
    public String hello(){
        System.out.println("hello world");
        return "hello world";
    }
}

作业2 参数

1.

@RequestMapping("/simpleParam")
public String simpleParam(String name, Integer age){
   System.out.println(name+ ":" + age);
   return "OK";
}
@RequestMapping("/simpleParam")
public String simpleParam(@RequestParam(name = "name", required = false) String username, Integer age){
   System.out.println(username+ ":" + age);
   return "OK";
}
 2.
package com.zy

public class User {
    private String name;
    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

package com.zy;

import java.security.PrivateKey;

public class Address {
    private String province;
    private String city;

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        return "Address{" +
                "province='" + province + '\'' +
                ", city='" + city + '\'' +
                '}';
    }
}

 

作业3 产品添加

1.

package com.zy.springboot;

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;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Product</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 com.zy.springboot;
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 com.zy.springboot.*;

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. 

 

package com.zy.springboot;

public class input {
    private String username;
    private String password;
    private String gender;
    private String city;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
package com.zy.springboot;
import com.zy.springboot.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class inputcontroller {
    @RequestMapping("/output")
    public String simpleParam(input input,String[] hobby){
        System.out.println(input);
        System.out.println("爱好为:"+Arrays.toString(hobby));
        return "OK";
    }
}
"text" name="username" id="sss"><br>

  <label for="ccc">密码:</label>
  <input type="password" name="password" id="ccc"><br>

  性别:
  <input type="radio" name="gender" value="男" id="male">
  <label for="male">男</label>
  <input type="radio" name="gender" value="女" id="female">
  <label for="female">女</label>
  <br>

  爱好:
  <input type="checkbox" name="hobby" value="旅游">旅游
  <input type="checkbox" name="hobby" value="电影">电影
  <input type="checkbox" name="hobby" value="游戏">游戏
  <input type="checkbox" name="hobby" value="音乐">音乐
  <br>

  城市:
  <select name="city">
    <option value="北京">北京</option>
    <option value="上海">上海</option>
    <option value="广州">广州</option>
    <option value="武汉">武汉</option>
  </select>
  <br>

  <br>
  <input type="submit" value="提交">
</form>

</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值