使用spring boot+JPA实现增、删、查、改和上传图片的小demo,把它记录下来,防止以后忘记了

本文记录了一个使用Spring Boot结合JPA实现的增删查改功能的简单示例,包括前端页面(list.jsp、userAdd.jsp、userEdit.jsp)和后台实现。实体类User、DAO层(集成在Controller层)以及配置文件均有涉及。项目存在一个问题:图片上传至静态资源目录后,需手动刷新才能显示。作者期待改进意见和指导如何将图片上传至服务器。
摘要由CSDN通过智能技术生成

我的工程目录

一、前端的页面

list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
 <link rel="stylesheet" href="/css/bootstrap.css"></link>
</head>

<body>
<div class="with:80%">
    <table class="table table-hover">
        <thead>
        <tr align="center">
        	<td colspan="9">
        	<form action="/listall" method="post">
        		<label>查询条件:</label>
        		<input type="text" name="userName"  id="userName" placeholder="输入姓名">
        		<input type="submit"  value="查询" class="btn btn-info" />
        	</form>
        	</td>
        </tr>
        <tr>
            <th>编号</th>
            <th>用户名</th>
            <th>密码</th>
            <th>邮箱</th>
            <th>头像</th>
            <th>编辑</th>
            <th>删除</th>
        </tr>
        </thead>
        <tbody>
        <c:set var="index" value="0" /> 
        <c:forEach var="i" items="${list}" >
        <c:set var="index" value="${index+1}" /> 
         <tr>
            <th >${index}</th>
            <td >${i.userName}</td>
            <td >${i.passWord}</td>
            <td >${i.email}</td>
             <td ><img  src="/upload/${i.filepath }" width="100" height="100"></td>
            <td><a href="/toEdit?id=${i.id }" class="btn btn-info">edit</a></td>
            <td><a  href="javascript:void(0)" οnclick="del(${i.id })" class="btn btn-info">delete</a></td>
        </tr>
        </c:forEach>
       
        </tbody>
    </table>
    <script type="text/javascript">
    function del(id){
    	if(confirm("确认删除id="+id))
    		location.href="/del?id="+id;
    }
    </script>
</div>
<div class="form-group">
    <div class="col-sm-2 control-label">
        <a href="userAdd.jsp" class="btn btn-info">添加</a>
    </div>
</div>

</body>
</html>
userAdd.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
 <link rel="stylesheet" href="/css/bootstrap.css"></link>
</head>

<body class="container">
<br/>
<h1>用户添加</h1>
<br/><br/>
<div class="with:80%">
    <form class="form-horizontal"  action="/add"  method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="userName" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-10">
                <i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值