水果库存系统(整合)

整体结构

 

JavaWeb包

dao包

BaseServlet

package JavaWeb.dao;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author whlie(true){learn}
 */
public class BaseServlet extends HttpServlet {

    private TemplateEngine templateEngine;

    @Override
    public void init() throws ServletException {

        // 1.获取ServletContext对象
        ServletContext servletContext = this.getServletContext();

        // 2.创建Thymeleaf解析器对象
        ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(servletContext);

        // 3.给解析器对象设置参数
        // ①HTML是默认模式,明确设置是为了代码更容易理解
        templateResolver.setTemplateMode(TemplateMode.HTML);

        // ②设置前缀
        String viewPrefix = servletContext.getInitParameter("view-prefix");

        templateResolver.setPrefix(viewPrefix);

        // ③设置后缀
        String viewSuffix = servletContext.getInitParameter("view-suffix");

        templateResolver.setSuffix(viewSuffix);

        // ④设置缓存过期时间(毫秒)
        templateResolver.setCacheTTLMs(60000L);

        // ⑤设置是否缓存
        templateResolver.setCacheable(true);

        // ⑥设置服务器端编码方式
        templateResolver.setCharacterEncoding("utf-8");

        // 4.创建模板引擎对象
        templateEngine = new TemplateEngine();

        // 5.给模板引擎对象设置模板解析器
        templateEngine.setTemplateResolver(templateResolver);

    }

    protected void processTemplate(String templateName, HttpServletRequest req, HttpServletResponse resp) throws IOException, IOException {
        // 1.设置响应体内容类型和字符集
        resp.setContentType("text/html;charset=UTF-8");

        // 2.创建WebContext对象
        WebContext webContext = new WebContext(req, resp, getServletContext());

        // 3.处理模板数据
        templateEngine.process(templateName, webContext, resp.getWriter());
    }
}

BasicDAO

package JavaWeb.dao;

import JavaWeb.Tool.DruTool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author whlie(true){learn}
 */
public class BasicDAO<T> {
    /**
     * 封装常用的各种方法
     * @param <T>类型不确定
     */
    private QueryRunner qr = new QueryRunner();
        public int update(String sql,Object... parameters) throws SQLException {
            Connection connection =  DruTool.getConnection();
            int update = qr.update(connection, sql, parameters);
            DruTool.close(null,null,connection);
            return update;
        }

        /**
         * 返回多个对象(即查询的结果是多行), 针对任意表
         * @param sql sql 语句,可以有 ?
         * @param clazz  传入一个类的 Class 对象 比如 Actor.class
         * @param parameters 传入 ? 的具体的值,可以是多个
         * @return 根据 Actor.class 返回对应的 ArrayList 集合
         */
        public List<T> queryMulti(String sql, Class<T> clazz, Object... parameters) throws SQLException {
            Connection connection = DruTool.getConnection();
            List<T> list = qr.query(connection, sql, new BeanListHandler<T>(clazz), parameters);
            DruTool.close(null,null,connection);
            return list;
        }

        /**
         * 查询单行结果 的通用方法
         * @param sql
         * @param clazz
         * @param parameters
         * @return
         */
        public T querySingle(String sql, Class<T> clazz, Object... parameters) throws SQLException {
                Connection connection = DruTool.getConnection();
                T query = qr.query(connection, sql, new BeanHandler<T>(clazz), parameters);
                DruTool.close(null,null,connection);
                return query;
        }
        /**
         *返回单值的方法
         * @param sql
         * @param parameters
         * @return
         */
        public Object queryScalar(String sql, Object... parameters) throws SQLException {
            Connection connection = DruTool.getConnection();
            Object query = qr.query(connection, sql, new ScalarHandler(), parameters);
            DruTool.close(null,null,connection);
            return query;
        }
}

FruitDAO

package JavaWeb.dao;

import JavaWeb.daomain.Fruit;

import java.sql.SQLException;
import java.util.List;

/**
 * @author whlie(true){learn}
 */
public class FruitDAO extends BasicDAO<Fruit> {
    /**
     * 查询表中的所有数据
     */
    public List<Fruit> getFruit(String keyword,int no) throws SQLException {
        return super.queryMulti("select *from fruit where name like ? or remark like ?",Fruit.class,"%"+keyword+"%","%"+keyword+"%");
    }

    /**
     * 查询表中的所有数据(分页查询)
     */
    public List<Fruit> getFruitC(String keyword,int no) throws SQLException {
        return super.queryMulti("select *from fruit where name like ? or remark like ? limit ?,5"
                ,Fruit.class,"%"+keyword+"%","%"+keyword+"%",(no-1)*5);
    }

    /**
     * 根据id得到对应的水果
     */
    public Fruit getFruitId(int id) throws SQLException {
        return super.querySingle("select *from fruit where id=?",Fruit.class,id);
    }

    /**
     * 修改指定水果的信息
     */
    public void updateId(Fruit fruit){
        String sql="update fruit set name=?,price=?,count=?,remark=? where id=?";
        try {
            super.update(sql,fruit.getName(),fruit.getPrice(),fruit.getCount(),fruit.getRemark(),fruit.getId());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 删除指定id的水果
     */
    public void delId(int id) {
        try {
            super.update("delete from fruit where id=?",id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 添加水果库存
     */
    public void add(Fruit fruit){
        String sql="insert into fruit values(null,?,?,?,?)";
        try {
            super.update(sql,fruit.getName(),fruit.getPrice(),fruit.getCount(),fruit.getRemark());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

daomain包

Fruit

package JavaWeb.daomain;

/**
 * @author whlie(true){learn}
 */
public class Fruit {
    private Integer id;
    private String name;
    private Double price;
    private Integer count;
    private String remark;

    public Fruit() {
    }

    public Fruit(Integer id, String name, Double price, Integer count, String remark) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.count = count;
        this.remark = remark;
    }

    public Fruit(String name, Double price, Integer count, String remark) {
        this.name = name;
        this.price = price;
        this.count = count;
        this.remark = remark;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public String toString() {
        return "Fruit{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", count=" + count +
                ", remark='" + remark + '\'' +
                '}';
    }
}

Service包

FruitControl

package JavaWeb.Service;

import JavaWeb.Tool.Utils;
import JavaWeb.dao.BaseServlet;
import JavaWeb.dao.FruitDAO;
import JavaWeb.daomain.Fruit;

import javax.rmi.CORBA.Util;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.List;

/**
 * @author whlie(true){learn}
 */
@WebServlet("/fruit.do")
public class FruitControl extends BaseServlet {

    private FruitDAO fruitDAO = new FruitDAO();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        String operate = req.getParameter("operate");
        //默认跳转首页
        if (Utils.isNull(operate)){
            operate="index";
        }
        //获取当前类中所有的方法
        Method[] methods = this.getClass().getDeclaredMethods();
        for (Method m:methods){
            String name = m.getName();
            if (operate.equals(name)){
                try {
                    m.invoke(this,req,resp);
                    return;
                } catch (IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        throw new RuntimeException("operate异常");
    }
    private void index(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();
        int no=1;

        String oper = req.getParameter("oper");
        //如果oper!=null说明是通过表单的查询按钮点击过来的
        //如果oper是空的,说明不是通过表单的查询按钮点击过来的
        String keyword=null;
        if (!Utils.isNull(oper)&&"search".equals(oper)){
            no=1;
            keyword = req.getParameter("keyword");
            //设置默认第一次查询的情况
            if(Utils.isNull(keyword)){
                keyword = "" ;
            }
            session.setAttribute("keyword",keyword);
        }else {
            String pageNo = req.getParameter("pageNo");
            if (!Utils.isNull(pageNo)){
                no=Integer.parseInt(pageNo);
            }
            Object keyword1 = session.getAttribute("keyword");
            //设置默认第一次查询的情况
            if(keyword1!=null){
                keyword = (String)keyword1 ;
            }else{
                keyword = "" ;
            }
        }

        FruitDAO fruitDAO = new FruitDAO();
        List<Fruit> fruit1 = null;
        //获取水果总数
        try {
            //获取指定名字和备注的水果集合
            fruit1 = fruitDAO.getFruit(keyword,no);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //得到指定名字和备注的水果的数量
        int count = fruit1.size();
        //获取页数
        String pageNo = req.getParameter("pageNo");
        if (!Utils.isNull(pageNo)){
            no=Integer.parseInt(pageNo);
        }
        try {
            //分页查询
            List<Fruit> fruit = fruitDAO.getFruitC(keyword,no);
            //key:fruit,value:fruit
            session.setAttribute("fruit",fruit);
            //保存页数
            session.setAttribute("pageNo",no);
            //保存数量
            session.setAttribute("count",(count+4)/5);
            //设置跳转页面
            super.processTemplate("index",req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    private void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("fname");
        double price = Double.parseDouble(req.getParameter("price"));
        int count = Integer.parseInt(req.getParameter("count"));
        String remark = req.getParameter("remark");
        fruitDAO.add(new Fruit(name,price,count,remark));
        resp.sendRedirect("fruit.do");
    }
    private void del(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        if (!Utils.isNull(id)){
            int i = Integer.parseInt(id);
            fruitDAO.delId(i);
            resp.sendRedirect("fruit.do");
        }
    }
    private void edit(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        if (!Utils.isNull(id)){
            int i = Integer.parseInt(id);
            try {
                Fruit fruit = fruitDAO.getFruitId(i);
                req.setAttribute("fruit",fruit);
                super.processTemplate("edit",req,resp);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    private void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String fname = req.getParameter("fname");
        String price = req.getParameter("price");
        String count = req.getParameter("count");
        String remark = req.getParameter("remark");
        fruitDAO.updateId(new Fruit(Integer.parseInt(id),
                fname,Double.parseDouble(price),
                Integer.parseInt(count),remark));
        resp.sendRedirect("fruit.do");
    }
}

Tool包

DruTool

package JavaWeb.Tool;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author whlie(true){learn}
 */
public class DruTool {
    private static DataSource ds;
    private static String user;
    private static String password;
    private static String url;
    private static String driver;
    InputStream in=this.getClass().getResourceAsStream("JavaWeb\\druid.properties");

    static {
        Properties properties = new Properties();

        try {
            properties.load(new FileInputStream("E:\\day4\\src\\JavaWeb\\druid.properties"));
            user = properties.getProperty("user");
            password = properties.getProperty("password");
            url = properties.getProperty("url");
            driver = properties.getProperty("driver");
            ds = (DataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void close(ResultSet resultSet, Statement statement, Connection connection) throws SQLException {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static String getUser() {
        return user;
    }

    public static String getPassword() {
        return password;
    }

    public static String getUrl() {
        return url;
    }

    public static String getDriver() {
        return driver;
    }
}

Utils

package JavaWeb.Tool;

/**
 * @author whlie(true){learn}
 */
public class Utils {
    //判断字符串是否为空或""
    public static boolean isNull(String s){
        return s==null||s.equals("");
    }
}

配置文件

#key=value
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/wzg_db02?rewriteBatchedStatements=true
username=root
password=***
#initial connection Size
initialSize=10
#min idle connecton size
minIdle=5
#max active connection size
maxActive=20
#max wait time (5000 mil seconds)
maxWait=5000

Web包

css包

css.css

@CHARSET "UTF-8";
#total{
	width: 450px;
}

ul{
	list-style-type: none;
}

li{
	border-style: solid;
	border-width: 1px;
	padding: 5px;
	margin: 5px;
	background-color: #99ff99;
	float:left;
}

.inner{
	width:400px;
	border-style: solid;
	border-width: 1px;
	margin: 10px;
	padding: 10px;
	float: left;
}

edit.css

body{
    margin:0;
    padding:0;
    background-color:#808080;
}
div{
    position:relative;
    float:left;
}

#div_container{
    width:80%;
    height:100%;
    border:0px solid blue;
    margin-left:10%;
    float:left;
    background-color: honeydew;
    border-radius:8px;
}
#div_fruit_list{
    width:100%;
    height:750px;
    border:0px solid red;
}
#tbl_fruit{
    width:60%;
    line-height:28px;
    margin-top:16px;
    margin-left:20%;
}
#tbl_fruit , #tbl_fruit tr , #tbl_fruit th , #tbl_fruit td{
    border:1px solid gray;
    border-collapse:collapse;
    text-align:center;
    font-size:16px;
    font-family:"黑体";
    font-weight:lighter;
}
.w20{
    width:20%;
}
.delImg{
    width:24px;
    height:24px;
}
.btn{
    border:1px solid lightgray;
    width:80px;
    height:24px;
}
#add_fruit_div{
    border:0px solid red;
    width:40%;
    margin-left:30%;
}
#add_fruit_tbl {
    margin-top:32px;
    width:80%;
    margin-left:10%;
    border-collapse:collapse;
}
#add_fruit_tbl , #add_fruit_tbl tr , #add_fruit_tbl td{
    border:1px solid lightgray;
    text-align:center;
    line-height:28px;
}
.w30{
    width:30%;
}

.input{
    padding-left:4px;
    border:1px solid lightgray;
    width:90%;
}
.center{
    text-align: center;
    font-size: 30px;
}

index.css

html{
    height: 100%;
}
body{
    height: 100%;
    margin:0;
    padding:0;
    background-color:#808080;
}
a{
    text-decoration: none;
    color: #666666;
}

a:hover{
    text-decoration:none;
}
div{
    position:relative;
    float:left;
}

#div_container{
    overflow: hidden;
    width:80%;
    min-height: 100%;
    margin-left:10%;
    float:left;
    background-color: honeydew;
    border-radius:8px;
}
#div_fruit_list{
    overflow: hidden;
    width:100%;
    border:0px solid red;
}
#tbl_fruit{
    width:60%;
    line-height:28px;
    margin-top:16px;
    margin-left:20%;
}
#tbl_fruit , #tbl_fruit tr , #tbl_fruit th , #tbl_fruit td{
    border:1px solid gray;
    border-collapse:collapse;
    text-align:center;
    font-size:16px;
    font-family:"黑体";
    font-weight:lighter;

}
.w20{
    width:20%;
}
.delImg{
    width:24px;
    height:24px;
}
.btn{
    border:1px solid lightgray;
    width:80px;
    height:24px;
}
#add_fruit_div{
    border:0px solid red;
    width:40%;
    margin-left:30%;
}
#add_fruit_tbl {
    margin-top:32px;
    width:80%;
    margin-left:10%;
    border-collapse:collapse;
}
#add_fruit_tbl , #add_fruit_tbl tr , #add_fruit_tbl td{
    border:1px solid lightgray;
    text-align:center;
    line-height:28px;
}
.w30{
    width:30%;
}

.input{
    padding-left:4px;
    border:1px solid lightgray;
    width:90%;
}
.center{
    text-align: center;
    font-size: 30px;
}

style.css

@CHARSET "UTF-8";

body {
	overflow: hidden;
}

* {
	margin: 0;
	font-family:"Microsoft Yahei";
	color: #666;
}

div{
	margin: auto;
	margin-bottom: 10px;
	margin-top: 10px;
	
}

#header {
	height: 82px;
	width: 1200px;
}

#main {
	height: 460px;
	width: 1200px;
	border: 1px black solid;
	overflow: auto;
}

#bottom {
	height: 30px;
	width: 1200px;
	text-align: center;
}

#book{
	width: 100%;
	height: 90%;
	margin: auto;
	
}

.b_list{
	height:300px;
	width:250px;
	margin: 20px;
	float: left;
	margin-top:0px;
	margin-bottom:0px;
	border: 1px #e3e3e3 solid;
}

#page_nav{
	width: 100%;
	height: 10px;
	margin: auto;
	
	text-align: center;
}

#pn_input {
	width: 30px;
	text-align: center;
}

.img_div{
	height: 150px;
	text-align: center;
}

.book_img {
	height:150px;
	width:150px;
}

.book_info {
	
	text-align: center;
}

.book_info div{
	height: 10px;
	width: 300px;
	text-align: left;
}

.wel_word{
	font-size: 60px;
	float: left;
}

.logo_img{
	float: left;
}

#header div a {
	text-decoration: none;
	font-size: 20px;
}

#header div{
	float: right;
	margin-top: 55px;
}

.book_cond{
	margin-left: 500px;
}

.book_cond input{
	width: 50px;
	text-align: center;
}


/*登录页面CSS样式  */

#login_header{
	height: 82px;
	width: 1200px;
}

.login_banner{
	height:475px;
	background-color: #39987c;
}

.login_form{
	height:420px;
	width:406px;
	float: right;
	margin-right:50px;
	margin-top: 30px;
	background-color: #fff;
}

#content {
	height: 475px;
	width: 1200px;
}

.login_box{
	margin: 20px;
	height: 260px;
	width: 366px;
}

h1 {
	font-size: 20px;
}
.msg_cont{
	background: none repeat scroll 0 0 #fff6d2;
    border: 1px solid #ffe57d;
    color: #666;
    height: 18px;
    line-height: 18px;
    padding: 3px 10px 3px 40px;
    position: relative;
    border: none;
}

.msg_cont b {
	background: url("../img/pwd-icons-new.png") no-repeat scroll -104px -22px rgba(0, 0, 0, 0);
    display: block;
    height: 17px;
    left: 10px;
    margin-top: -8px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    width: 16px;
}

.form .itxt {
    border: 0 none;
    float: none;
    font-family: "宋体";
    font-size: 14px;
    height: 18px;
    line-height: 18px;
    overflow: hidden;
    padding: 10px 0 10px 10px;
    width: 220px;
    border: 1px #e3e3e3 solid;
}

#sub_btn{
	background-color: #39987c;
	border: none;
	color: #fff;
	width: 360px;
	height: 40px;
}

#l_content {
	float: left;
	margin-top: 150px;
	margin-left: 300px;
}

#l_content span {
	font-size: 60px;
	color: white;
}

.tit h1 {
	float: left;
	margin-top: 5px;
}

.tit a {
	float: right;
	margin-left: 10px;
	margin-top: 10px;
	color: red;
	text-decoration: none;
}

.tit .errorMsg {
	float: right;
	margin-left: 10px;
	margin-top: 10px;
	color: red;
}

.tit {
	height: 30px;
}
/*购物车*/
#main table{
	margin: auto;
	margin-top: 80px; 
	border-collapse: collapse;
}

#main table td{
	width: 120px;
	text-align:center;
	border-bottom: 1px #e3e3e3 solid;
	padding: 10px;
}

.cart_info{
	width: 700px;
	text-align: right;
}

.cart_span {
	margin-left: 20px;
}

.cart_span span{
	color: red;
	font-size: 20px;
	margin: 10px;
}

.cart_span a , td a{
	font-size: 20px;
	color: blue;
}

#header div span {
	margin: 10px;
}

#header div .um_span{
	color: red;
	font-size: 25px;
	margin: 10px;
}

#header div a {
	color: blue;
}

img包

js包 

index.js

function delFruit(id) {
    //弹窗确认
    if (confirm('是否确认删除?')){
        window.location.href='fruit.do?id='+id+'&operate=del';
    }
}
function page(no) {
    window.location.href="fruit.do?pageNo="+no;
}

jQuery文件太大

add.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/edit.css">
</head>
<body>
<div id="div_container" >
    <div id="div_fruit_list">
        <p class="center f30">新增库存信息</p>
        <form action="fruit.do" method="post">
            <input type="hidden" name="operate" value="add">
            <table id="tbl_fruit">
                <tr>
                    <th class="w20">名称:</th>
                    <td><input type="text" name="fname" /></td>
                </tr>
                <tr>
                    <th class="w20">单价:</th>
                    <td><input type="text" name="price" /></td>
                </tr>
                <tr>
                    <th class="w20">库存:</th>
                    <td><input type="text" name="count" /></td>
                </tr>
                <tr>
                    <th class="w20">备注:</th>
                    <td><input type="text" name="remark" /></td>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="submit" value="添加"/>
                    </th>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>

edit.html

​
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/edit.css">
</head>
<body>
<div id="div_container" >
    <div id="div_fruit_list">
        <p class="center f30">编辑库存信息</p>
        <form th:action="@{/fruit.do}" method="post" th:object="${fruit}">
            <input type="hidden" name="operate" th:value="update">
            <!--隐藏域:功能类似于文本框,它的值会随表单的发送也发送给服务器,但界面上不显示-->
            <input type="hidden" name="id" th:value="*{id}" />
            <table id="tbl_fruit">
                <tr>
                    <th class="w20">名称:</th>
                    <td><input type="text" name="fname" th:value="*{name}"/></td>
                </tr>
                <tr>
                    <th class="w20">单价:</th>
                    <td><input type="text" name="price" th:value="*{price}"/></td>
                </tr>
                <tr>
                    <th class="w20">库存:</th>
                    <td><input type="text" name="count" th:value="*{count}"/></td>
                </tr>
                <tr>
                    <th class="w20">备注:</th>
                    <td><input type="text" name="remark" th:value="*{remark}"/></td>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="submit" value="修改"/>
                    </th>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>

​

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/index.css">
    <script language="JavaScript" src="js/index.js"></script>
</head>
<body>
<div id="div_container" th:method="get">
    <div id="div_fruit_list">
        <p class="center">欢迎使用水果库存系统</p>
        <div style="width: 60%;margin-left: 20%;text-align: right;">
            <form th:action="@{/fruit.do}" method="post" style="float: left;">
                <input type="hidden" name="oper" value="search"/>
                请输入查询关键字:<input type="text" name="keyword" th:value="${session.keywork}"/>
                <input type="submit" value="查询" class="btn"/>
            </form>
            <a th:href="@{/add.html}" style="margin-bottom: 4px">添加库存记录</a>
        </div>
        <table id="tbl_fruit">
            <tr>
                <th class="w20">名称</th>
                <th class="w20">单价</th>
                <th class="w20">库存</th>
                <th>操作</th>
            </tr>
            <!--thy判断session作用域是否为空-->
            <tr th:if="${#lists.isEmpty(session.fruit)}">
                <td colspan="4">对不起,库存为空!</td>
            </tr>
            <!--不为空,则循环取出作用域中的数据-->
            <tr th:if="${not#lists.isEmpty(session.fruit)}" th:each="f:${session.fruit}">
                <!--设置文本框内容为session作用域中水果的名字代替原来的内容-->
                <!--根据水果的id设置超链接的跳转目标页面-->
                <td><a none th:text="${f.name}"  th:href="@{/fruit.do(id=${f.id},operate='edit')}">苹果</a></td>
                <td th:text="${f.price}">5</td>
                <td th:text="${f.count}">20</td>
                <!--点击图片响应删除操作|xxxx|用于拼接||内的字符串如果遇到$()则会执行$()语句-->
                <td><img src="imgs/del.jpg" class="delImg" th:onclick="|delFruit(${f.id})|" /></td>
            </tr>
        </table>
        <div style="width: 60%;margin-left: 20%;padding-top: 5px;" class="center">
            <input type="button" value="首  页" class="btn" th:onclick="|page(1)|" th:disabled="${session.pageNo==1}"/>
            <input type="button" value="上一页" class="btn" th:onclick="|page(${session.pageNo-1})|" th:disabled="${session.pageNo==1}"/>
            <input type="button" value="下一页" class="btn" th:onclick="|page(${session.pageNo+1})|" th:disabled="${session.pageNo==session.count}"/>
            <input type="button" value="尾  页" class="btn" th:onclick="|page(${session.count})|" th:disabled="${session.pageNo==session.count}"/>
        </div>
    </div>
</div>
</body>
</html>

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1while(true){learn}

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值