2020-03-26

自行设计数据库、表结构,插入测试数据

package com.MyUser.controller;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.MyUser.domain.MyUser;

import com.MyUser.model.MyUserModel;

/**

 * Servlet implementation class MyUserServlet

 */

@WebServlet("/MyUserServlet")

public class MyUserServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

   try {

MyUserModel myuserModel = new MyUserModel();

   List list = myuserModel.findAll();

   request.setAttribute("list", list);

   request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

}

package com.MyUser.domain;

public class MyUser {

    private Integer gname;

    private String price;

    private String number;

    private Integer gdate;

 public Integer getGname() {

  return gname;

 }

 public void setGname(Integer gname) {

  this.gname = gname;

 }

 public String getPrice() {

  return price;

 }

 public void setPrice(String price) {

  this.price = price;

 }

 public String getNumber() {

  return number;

 }

 public void setNumber(String number) {

  this.number = number;

 }

 public Integer getGdate() {

  return gdate;

 }

 public void setGdate(Integer gdate) {

  this.gdate = gdate;

 }


}

package com.MyUser.model;

import java.sql.SQLException;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.MyUser.Utils.Utils;

import com.MyUser.domain.MyUser;

public class MyUserModel {

    public List findAll() throws SQLException{

     QueryRunner queryRunery = new QueryRunner(Utils.getDataSource());

     List list = queryRunery.query("select * from MyUser",new BeanListHandler(MyUser.class));

     return list;

    }

}

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

"UTF-8">

Insert title here

商品信息显示页面

"1" width="600">

  商品名称

  商品价钱

  商品总数量

  商品上架时间

 

 "MyUser" items="${ list }">

 

  ${ MyUser.gname }

  ${ MyUser.price }

  ${ MyUser.number }

  ${ MyUser.gdate}

 

 

 "test" var="name" scope="page">

 "${ status.count % 3 == 0 }">

 "transparent">${ test }

 

 "${ status.count % 3 != 0 }">

  ${ test }

  

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

"UTF-8">

Insert title here

      "a-span10">

        "a-link-normal" title="7% 的评论都有 2 颗星" href="https://www.amazon.cn/product-reviews/B07DGSQ6D3/ref=acr_search_hist_2?ie=UTF8&filterByStar=two_star&reviewerType=all_reviews#reviews-filter-bar">

          "a-meter" aria-label="7%">"a-meter-bar a-meter-filled" page="width: 7%;">

        

      

      "a-spacing-large a-divider-normal">"a-section a-spacing-base a-text-center">"a-size-base a-link-emphasis" href="https://www.amazon.cn/product-reviews/B07DGSQ6D3">查看全部28 条商品评论

"a-arrow-border" style="left: 177px;">"a-arrow">
"0" class="a-popover-end a-popover-a11y-offscreen">

      

你可能感兴趣的:(2020-03-26)