SpringBoot+bootstrap3界面版本增删改查

  • Post author:
  • Post category:其他




一:前台注意事项



①:获取项目名格式

<input type="text" th:text="@{/}">

//访问某项目的文件
<link rel="stylesheet" th:href="@{/static/js/bootstrap3/css/bootstrap.min.css}">


②传值(字符串的拼接)

<a th:href="@{'/teacher/del/'+${teacher.tid}}">删除</a>

<a th:href="@{'/teacher/toEdit?tid='+${teacher.tid}}">修改</a>


③三元运算符的形式

<form th:action="@{${teacher.tid} ? '/teacher/edit' : '/teacher/add'}" method="post" enctype="multipart/form-data"></form>


④ utext 与text区别

//utext 当前标签追加上html的字符串 有样式
<ul class="pagination pagination-sm" th:utext="${pageCode}"></ul>


//直接打印出字符串
<ul class="pagination pagination-sm" th:text="${pageCode}"> </ul>
   

区别  前者 utext   后者 text


⑤:回显 thyemleaf

//默认选中第一个
<input type ="radio" name="repaymentType"
	th:each ="repaymentType,repaymentState:${repaymentTypeList}"
	th:value="${repaymentType.dictName}"
	th:text ="${repaymentType.dictName}"
	th:attr ="checked=${repaymentState.index==0?true:false}">

//单选回显
<input type="radio" name="repaymentType"
   th:each ="repaymentType:${repaymentTypeList}"
   th:value="${repaymentType.dictName}"
   th:text ="${repaymentType.dictName}"
   th:attr ="checked=${financeProductDO.repaymentType == repaymentType.dictName?true:false}">

//多选回显
<input type ="checkbox" name="companyRole"
	th:each ="role : ${companyRoleList}"
	th:value="${role.dictName}"
	th:text ="${role.dictName}"
	th:attr ="checked=${companyInformation.companyRole.contains(role.dictName)?true:false}">

//下拉选回显默认选中 前台接收到参数:user对象和businessList集合
<option th:selected="${user.businessId eq busi.businessId}"
		th:each="busi:${businessList}"
		th:value="${busi.businessId}"
		th:text="${busi.businessName}" >
</option>


二:后台注意事项

① 分页需要到一个 PageUtil

c标签 PageBean 基于jsp ,bootstrap 直接通过controller层调方法,传分页值去页面

②:从零也开始查起  所有要减1

③:  要获取总记录数 方法返回的值是Page

④:jpa有内置的分页接口

public Page<Teacher> listPager(Teacher teacher, PageBean pageBean) {

        //jpa的Pageable分页是从0页码开始
        //pageHelper.start("当前页","当前记录数",""总记录数),所以返回的Page
        Pageable pageable = PageRequest.of(pageBean.getPage()-1, pageBean.getRows());
        return teacherDao.findAll(new Specification<Teacher>() {
            @Override
            public Predicate toPredicate(Root<Teacher> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                Predicate predicate = criteriaBuilder.conjunction();
                if(teacher != null&&teacher.getTname()!=null &&!"".equals(teacher.getTname())){
                    if(StringUtils.isNotBlank(teacher.getTname())){
                        predicate.getExpressions().add(criteriaBuilder.like(root.get("tname"),"%"+teacher.getTname()+"%"));
                    }
                }
                return predicate;
            }
        },pageable);
    }

⑤:上传文件需要application.yml配置文件的大小 否则上传不成功  默认支持上传1MB

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

三:后台简易版的增删查改

导入pom.xml依赖

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.10</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.1</version>
</dependency>

application.yml配置

server:
  servlet:
    context-path: /springboot
spring:
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8
    username: mybatis_ssm
    password: xiaoli
    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: f



版权声明:本文为Kikyou994755原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。