springboot之jpa以及springboot+bootstrap窗体版CRUD和文件上传

1.springboot之jpa

jpa:直接写一个实体类就可以把数据库表创建好
创建一个springboot项目
在这里插入图片描述

导入pom依赖

		// mysql版本需要改为5.1.44
        <mysql.version>5.1.44</mysql.version>
       <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
            <scope>runtime</scope>
        </dependency>

     <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>
       // 上传的一个pom依赖,下面会用到
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

配置application.yml文件

server:
  port: 80
  servlet:
    context-path: /

spring:
  datasource:
    #1.JDBC
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/xm?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
    username: root
    password: 1234
    druid:
      initial-size: 5
      min-idle: 5
      max-active: 20
      max-wait: 60000
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 30000
      validation-query: SELECT 1 FROM DUAL
      test-while-idle: true
      test-on-borrow: true
      test-on-return: false
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      filter:
        stat:
          merge-sql: true
          slow-sql-millis: 5000
      web-stat-filter:
        enabled: true
        url-pattern: /*
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
        session-stat-enable: true
        session-stat-max-count: 100
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        login-username: admin
        login-password: admin
        allow: 127.0.0.1

  jpa:
    hibernate:
      ddl-auto: update     #当创好表之后如果要添加一个字段时,可直接在实体类添加一个字段,会自动加入数据库表中
    show-sql: true

创建一个实体类Student

package com.wr.springboot05.entity;

import lombok.Data;

import javax.persistence.*;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 13:47
 */
@Data                                    //这个注解包含着get,set方法,tostring方法
@Entity                                 //标明实体类
@Table(name = "t_springboot_student")   //表名
public class Student {
    @Id                   //标识为主键
    @GeneratedValue      //自增长
    private Integer sid;
    @Column(length = 100)              //标注为这个表中的字段
    private String sname;
    @Column
    private Integer sage;


}

然后运行
在这里插入图片描述
最后创建成功
在这里插入图片描述
给表格添加数据
在这里插入图片描述
下面用刚刚创好的实体类整一套增删改查
创建一个StudentDao类
只要继承JpaRepository,通常所有的增删改查的方法都会有
第一个参数:操作的实体类
第二个参数:实体类对应数据表的主键

package com.wr.springboot05.dao;

import com.wr.springboot05.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;

import java.awt.print.Book;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 14:30
 */
public interface StudentDao extends JpaRepository<Student , Integer> {
}

controller层
StudentController

package com.wr.springboot05.controller;

import com.wr.springboot05.dao.StudentDao;
import com.wr.springboot05.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sound.midi.Soundbank;
import java.util.List;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 14:31
 */
@RestController
public class StudentController {
    @Autowired
    private StudentDao studentDao;

    @RequestMapping("/add")
    public String add(Student student) {
        studentDao.save(student);
        return "success";
    }

    @RequestMapping("/del")
    public String del(Student student) {
        studentDao.delete(student);
        return "success";
    }

    @RequestMapping("/update")
    public String update(Student student) {
        studentDao.save(student);
        return "success";
    }

    @RequestMapping("/gOne")
    public Student gOne(Integer sid) {
        Student student = studentDao.findById(sid).get();
        return student;
    }

    @RequestMapping("/getAll")
    public List<Student> getAll() {
        return studentDao.findAll();
    }


}

添加方法
在这里插入图片描述
修改方法
在这里插入图片描述
查询所有
在这里插入图片描述
查询单个
在这里插入图片描述

2.springboot+bootstrap窗体版CRUD和文件上传

首先上面已经导入了pom依赖了
application.yml中还需配置


  thymeleaf:
    cache: false

    # 解决图片上传大小限制问题,也可采取配置类
  servlet:
    multipart:
      max-file-size: 20MB
      max-request-size: 60MB

Springboot05Application.java在这里插入图片描述
上传文件映射配置类MyWebAppConfigurer.java

 /**
 * 资源映射路径
 */
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/uploadImages/**").addResourceLocations("file:E:/temp/");
        super.addResourceHandlers(registry);
    }
}

StringUtils

package com.javaxl.springboot05.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class StringUtils {
	// 私有的构造方法,保护此类不能在外部实例化
	private StringUtils() {
	}

	/**
	 * 如果字符串等于null或去空格后等于"",则返回true,否则返回false
	 * 
	 * @param s
	 * @return
	 */
	public static boolean isBlank(String s) {
		boolean b = false;
		if (null == s || s.trim().equals("")) {
			b = true;
		}
		return b;
	}
	
	/**
	 * 如果字符串不等于null或去空格后不等于"",则返回true,否则返回false
	 * 
	 * @param s
	 * @return
	 */
	public static boolean isNotBlank(String s) {
		return !isBlank(s);
	}

	/**
	 * set集合转string
	 * @param hasPerms
	 * @return
	 */
	public static String SetToString(Set hasPerms){
		return  Arrays.toString(hasPerms.toArray()).replaceAll(" ", "").replace("[", "").replace("]", "");
	}

	/**
	 * 转换成模糊查询所需参数
	 * @param before
	 * @return
	 */
	public static String toLikeStr(String before){
		return isBlank(before) ? null : "%"+before+"%";
	}

	/**
	 *	将图片的服务器访问地址转换为真实存放地址
	 * @param imgpath	图片访问地址(http://localhost:8080/uploadImage/2019/01/26/20190126000000.jpg)
	 * @param serverDir	uploadImage
	 * @param realDir	E:/temp/
	 * @return
	 */
	public static String serverPath2realPath(String imgpath, String serverDir, String realDir) {
		imgpath = imgpath.substring(imgpath.indexOf(serverDir));
		return imgpath.replace(serverDir,realDir);
	}

	/**
	 * 过滤掉集合里的空格
	 * @param list
	 * @return
	 */
	public static List<String> filterWhite(List<String> list){
		List<String> resultList=new ArrayList<String>();
		for(String l:list){
			if(isNotBlank(l)){
				resultList.add(l);
			}
		}
		return resultList;
	}

	/**
	 * 从html中提取纯文本
	 * @param strHtml
	 * @return
	 */
	public static String html2Text(String strHtml) {
		String txtcontent = strHtml.replaceAll("</?[^>]+>", ""); //剔出<html>的标签
		txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");//去除字符串中的空格,回车,换行符,制表符
		return txtcontent;
	}

	public static void main(String[] args) {
	}
}

PageBean

package com.javaxl.springboot05.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 分页工具类
 */
public class PageBean {

	private int page = 1;// 页码

	private int rows = 3;// 页大小

	private int total = 0;// 总记录数

	private boolean pagination = true;// 是否分页
	
//	保存上次查询的参数
	private Map<String, String[]> paramMap;
//	保存上次查询的url
	private String url;
	
	public void setRequest(HttpServletRequest request) {
		String page = request.getParameter("page");
		String rows = request.getParameter("offset");
		String pagination = request.getParameter("pagination");
		this.setPage(page);
		this.setRows(rows);
		this.setPagination(pagination);
		this.setUrl(request.getRequestURL().toString());
		this.setParamMap(request.getParameterMap());
	}

	public PageBean() {
		super();
	}

	public Map<String, String[]> getParamMap() {
		return paramMap;
	}

	public void setParamMap(Map<String, String[]> paramMap) {
		this.paramMap = paramMap;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	public void setPage(String page) {
		if(StringUtils.isNotBlank(page)) {
			this.page = Integer.parseInt(page);
		}
	}

	public int getRows() {
		return rows;
	}

	public void setRows(String rows) {
		if(StringUtils.isNotBlank(rows)) {
			this.rows = Integer.parseInt(rows);
		}
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public void setTotal(String total) {
		if(StringUtils.isNotBlank(total)) {
			this.total = Integer.parseInt(total);
		}
	}

	public boolean isPagination() {
		return pagination;
	}

	public void setPagination(boolean pagination) {
		this.pagination = pagination;
	}
	
	public void setPagination(String pagination) {
		if(StringUtils.isNotBlank(pagination) && "false".equals(pagination)) {
			this.pagination = Boolean.parseBoolean(pagination);
		}
	}
	
	/**
	 * 最大页
	 * @return
	 */
	public int getMaxPage() {
		int max = this.total/this.rows;
		if(this.total % this.rows !=0) {
			max ++ ;
		}
		return max;
	}
	
	/**
	 * 下一页
	 * @return
	 */
	public int getNextPage() {
		int nextPage = this.page + 1;
		if(nextPage > this.getMaxPage()) {
			nextPage = this.getMaxPage();
		}
		return nextPage;
	}
	
	/**
	 * 上一页
	 * @return
	 */
	public int getPreviousPage() {
		int previousPage = this.page -1;
		if(previousPage < 1) {
			previousPage = 1;
		}
		return previousPage;
	}
		

	/**
	 * 获得起始记录的下标
	 * 
	 * @return
	 */
	public int getStartIndex() {
		return (this.page - 1) * this.rows;
	}

	@Override
	public String toString() {
		return "PageBean [page=" + page + ", rows=" + rows + ", total=" + total + ", pagination=" + pagination + "]";
	}
}

PageUtil

package com.javaxl.springboot05.utils;

import java.util.Map;
import java.util.Set;

/**
 * @author 小李飞刀
 * @site www.javaxl.com
 * @company
 * @create  2019-02-20 21:38
 *
 * 基于bootstrap3生成分页代码
 */
public class PageUtil {
    public static String createPageCode(PageBean pageBean) {
        StringBuffer sb = new StringBuffer();
        /*
         * 拼接向后台提交数据的form表单
         * 	注意:拼接的form表单中的page参数是变化的,所以不需要保留上一次请求的值
         */
        sb.append("<form id='pageBeanForm' action='"+pageBean.getUrl()+"' method='post'>");
        sb.append("<input type='hidden' name='page'>");
        Map<String, String[]> parameterMap = pageBean.getParamMap();
        if(parameterMap != null && parameterMap.size() > 0) {
            Set<Map.Entry<String, String[]>> entrySet = parameterMap.entrySet();
            for (Map.Entry<String, String[]> entry : entrySet) {
                if(!"page".equals(entry.getKey())) {
                    String[] values = entry.getValue();
                    for (String val : values) {
                        sb.append("<input type='hidden' name='"+entry.getKey()+"' value='"+val+"'>");
                    }
                }
            }
        }
        sb.append("</form>");

        if(pageBean.getTotal()==0){
            return "未查询到数据";
        }else{
            sb.append("<li><a href='javascript:gotoPage(1)'>首页</a></li>");
            if(pageBean.getPage()>1){
                sb.append("<li><a href='javascript:gotoPage("+pageBean.getPreviousPage()+")'>上一页</a></li>");
            }else{
                sb.append("<li class='disabled'><a href='javascript:gotoPage(1)'>上一页</a></li>");
            }
            for(int i=pageBean.getPage()-1;i<=pageBean.getPage()+1;i++){
                if(i<1||i>pageBean.getMaxPage()){
                    continue;
                }
                if(i==pageBean.getPage()){
                    sb.append("<li class='active'><a href='#'>"+i+"</a></li>");
                }else{
                    sb.append("<li><a href='javascript:gotoPage("+i+")'>"+i+"</a></li>");
                }
            }
            if(pageBean.getPage()<pageBean.getMaxPage()){
                sb.append("<li><a href='javascript:gotoPage("+pageBean.getNextPage()+")'>下一页</a></li>");
            }else{
                sb.append("<li class='disabled'><a href='javascript:gotoPage("+pageBean.getMaxPage()+")'>下一页</a></li>");
            }
            sb.append("<li><a href='javascript:gotoPage("+pageBean.getMaxPage()+")'>尾页</a></li>");
        }

        /*
         * 给分页条添加与后台交互的js代码
         */
        sb.append("<script type='text/javascript'>");
        sb.append("		function gotoPage(page) {");
        sb.append("			document.getElementById('pageBeanForm').page.value = page;");
        sb.append("			document.getElementById('pageBeanForm').submit();");
        sb.append("		}");
        sb.append("		function skipPage() {");
        sb.append("			var page = document.getElementById('skipPage').value;");
        sb.append("			if(!page || isNaN(page) || parseInt(page)<1 || parseInt(page)>"+pageBean.getMaxPage()+"){");
        sb.append("				alert('请输入1~N的数字');");
        sb.append("				return;");
        sb.append("			}");
        sb.append("			gotoPage(page);");
        sb.append("		}");
        sb.append("</script>");
        return sb.toString();
    }
}

实体类Students

package com.wr.springboot05.entity;

import lombok.Data;
import lombok.ToString;

import javax.persistence.*;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 15:29
 */

@ToString
@Entity
@Table(name = "t_spirngboot_student2")
public class Students {
    @Id
    @GeneratedValue
    private Integer tid;
    @Column(length =20)
    private String tname;
    @Column(length = 10)
    private String sex;
    @Column(length = 100)
    private String description;
    @Column(length = 200)
    private String imagePath;


    public Integer getTid() {
        return tid;
    }

    public void setTid(Integer tid) {
        this.tid = tid;
    }

    public String getTname() {
        return tname;
    }

    public void setTname(String tname) {
        this.tname = tname;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }
}

StudentsDao

package com.wr.springboot05.dao;

import com.wr.springboot05.entity.Students;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 15:33
 *  只要继承JpaRepository,通常所用的增删查改方法都有
 *  第一个参数:操作的实体类
 *  第二个参数:实体类对应数据表的主键
 *
 *  要使用高级查询必须继承
 * org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>接口
 */
public interface StudentsDao extends JpaRepository<Students,Integer>, JpaSpecificationExecutor<Students> {
}

StudentService

package com.wr.springboot05.service;

import com.wr.springboot05.entity.Students;
import com.wr.springboot05.utils.PageBean;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 15:36
 */
public interface StudentService {

    public void save(Students students);

    public void del(Integer tid);

    public Students getOne(Integer tid);

    public Page<Students> getAll(Students students, PageBean pageBean);

}

StudentServiceImpl

package com.wr.springboot05.service.imp;


import com.wr.springboot05.dao.StudentsDao;
import com.wr.springboot05.entity.Students;
import com.wr.springboot05.service.StudentService;
import com.wr.springboot05.utils.PageBean;
import com.wr.springboot05.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 15:39
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentsDao studentsDao;


    @Override
    public void save(Students students) {
        studentsDao.save(students);
    }

    @Override
    public void del(Integer tid) {
        studentsDao.deleteById(tid);
    }

    @Override
    public Students getOne(Integer tid) {
        return studentsDao.findById(tid).get();
    }

    @Override
    public Page<Students> getAll(Students students, PageBean pageBean) {
//        jpa的Pageable分页是从0页码开始
        Pageable pageable = PageRequest.of(pageBean.getPage() - 1, pageBean.getRows());

        return  studentsDao.findAll(new Specification<Students>() {
            @Override
            public Predicate toPredicate(Root<Students> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                Predicate predicate = criteriaBuilder.conjunction();
                if (students != null) {
                    if (StringUtils.isNotBlank(students.getTname())) {
                        predicate.getExpressions().add(criteriaBuilder.like(root.get("tname"), "%" + students.getTname() + "%"));
                    }
                }
                return predicate;
            }
        }, pageable);
    }
}

StudnentController

package com.wr.springboot05.controller;

import com.wr.springboot05.entity.Students;
import com.wr.springboot05.service.StudentService;
import com.wr.springboot05.utils.PageBean;
import com.wr.springboot05.utils.PageUtil;
import com.wr.springboot05.utils.StringUtils;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @author ruirui
 * @site www.haha.com
 * @company 哈哈公司
 * @create 2020-01-03 16:00
 */

@Controller
@RequestMapping("/student")
public class StudnentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/lists")
    public ModelAndView lists(Students student, HttpServletRequest request) {
        PageBean pageBean = new PageBean();
        pageBean.setRequest(request);

        ModelAndView modelAndView = new ModelAndView();

        Page<Students> students = studentService.getAll(student, pageBean);
        modelAndView.addObject("students", students.getContent());
        pageBean.setTotal(students.getTotalElements() + "");
        modelAndView.addObject("pageCode", PageUtil.createPageCode(pageBean));
        modelAndView.setViewName("list");
        return modelAndView;
    }

    @RequestMapping("/toEdit")
    public ModelAndView toEdit(Students students) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("edit");
        modelAndView.addObject("sexArr", new String[]{"男", "女"});
        if (!(students.getTid() == null) || "".equals(students.getTid())) {
            Students students1 = studentService.getOne(students.getTid());
            modelAndView.addObject("students", students1);
        }

        return modelAndView;

    }

    @RequestMapping("/add")
    public String add(Students students, MultipartFile image) {

        try {
            String diskPath = "E://temp/" + image.getOriginalFilename();
            String serverPath = "/uploadImages/" + image.getOriginalFilename();
            if (StringUtils.isNotBlank(image.getOriginalFilename())) {
                FileUtils.copyInputStreamToFile(image.getInputStream(), new File(diskPath));
                students.setImagePath(serverPath);
            }
            studentService.save(students);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "redirect:/student/lists";
    }


    @RequestMapping("/edit")
    public String edit(Students students, MultipartFile image) {

        try {
            String diskPath = "E://temp/" + image.getOriginalFilename();
            String serverPath = "/uploadImages/" + image.getOriginalFilename();
            if (StringUtils.isNotBlank(image.getOriginalFilename())) {
                FileUtils.copyInputStreamToFile(image.getInputStream(), new File(diskPath));
                students.setImagePath(serverPath);
            }
            studentService.save(students);
        } catch (IOException e) {
            e.printStackTrace();
        }


        return "redirect:/student/lists";

    }

    @RequestMapping("/del/{tid}")
    public String del(@PathVariable(value = "tid") Integer tid) {
        studentService.del(tid);
        return "redirect:/student/lists";
    }


}

list.html

<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>书籍列表</title>
    <script type="text/javascript" th:src="@{/static/js/xxx.js}"></script>
    <link rel="stylesheet" th:href="@{/static/js/bootstrap3/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/static/js/bootstrap3/css/bootstrap-theme.min.css}">
    <script type="text/javascript" th:src="@{/static/js/bootstrap3/js/jquery-1.11.2.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/js/bootstrap3/js/bootstrap.min.js}"></script>
</head>
<body>
<form th:action="@{/student/lists}" method="post">
    书籍名称: <input type="text" name="tname" />
    <input type="submit" value="提交"/>
</form>
<a th:href="@{/student/toEdit}">新增</a>
<table border="1px" width="600px">
    <thead>
    <tr>
        <td>ID</td>
        <td>头像</td>
        <td>姓名</td>
        <td>性别</td>
        <td>简介</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <tr th:each="student : ${students}">
        <td th:text="${student.tid}"></td>
        <td><img style="width: 60px;height: 60px;" id="imgshow" th:src="${student.imagePath}" th:alt="${student.tname}"/></td>
        <!--<td th:text="${teacher.imagePath}"></td>-->
        <td th:text="${student.tname}"></td>
        <td th:text="${student.sex}"></td>
        <td th:text="${student.description}"></td>
        <td>
            <a th:href="@{'/student/del/'+${student.tid}}">删除</a>
            <a th:href="@{'/student/toEdit?tid='+${student.tid}}">修改</a>
        </td>
    </tr>
    </tbody>
</table>


<nav>
    <ul class="pagination pagination-sm" th:utext="${pageCode}">
    </ul>

    <!--<ul class="pagination pagination-sm">-->
    <!--<form id='pageBeanForm' action='http://localhost:8080/springboot/teacher/listPager' method='post'><input type='hidden' name='page'></form>-->
    <!--<li><a href='javascript:gotoPage(1)'>首页</a></li>-->
    <!--<li class='disabled'><a href='javascript:gotoPage(1)'>上一页</a></li>-->
    <!--<li class='active'><a href='#'>1</a></li>-->
    <!--<li><a href='javascript:gotoPage(2)'>2</a></li>-->
    <!--<li><a href='javascript:gotoPage(2)'>下一页</a></li>-->
    <!--<li><a href='javascript:gotoPage(4)'>尾页</a></li>-->
    <!--<script type='text/javascript'>	function gotoPage(page) {	document.getElementById('pageBeanForm').page.value = page; document.getElementById('pageBeanForm').submit();	}	function skipPage() {	var page = document.getElementById('skipPage').value;	if(!page || isNaN(page) || parseInt(page)<1 || parseInt(page)>4){ alert('请输入1~N的数字');	return;	}	gotoPage(page);	}</script>-->
    <!--</ul>-->
</nav>
</body>
</html>

edit.html

<!DOCTYPE html>
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户编辑界面</title>

    <script type="text/javascript">
        function preShow() {

        }
    </script>
</head>
<body>

<form th:action="@{${students.tid} ? '/student/edit' : '/student/add'}" method="post" enctype="multipart/form-data">
<input type="hidden" name="tid" th:value="${students.tid}" />
    <input type="hidden" name="imagePath" th:value="${students.imagePath}" />
    <img id="imgshow" src="" alt=""/>
    <input type="file" name="image" onchange="preShow();"></br>
    教员名称: <input type="text" name="tname" th:value="${students.tname}" /></br>
    教员描述: <input type="text" name="description" th:value="${students.description}" /></br>
    单选回显
    <input type="radio" name="sex"
           th:each ="s:${sexArr}"
           th:value="${s}"
           th:text ="${s}"
           th:attr ="checked=${s == students.sex}">

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

</body>
</html>

最后页面效果图
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值