当前位置:   article > 正文

全栈开发笔记_cdn.d.waiwu.net

cdn.d.waiwu.net

开发笔记:

分页的笔记

导入三个坐标:

pom文件加这三个,缺一个都不行

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.5

com.github.pagehelper

pagehelper

5.0.3

com.github.pagehelper

pagehelper-spring-boot-autoconfigure

1.2.5

​ 网页分页的:

利用thymeleaf表达式分页

关于分页静态路径出错的解决方法:

文件上传

           第一步表单要加上这个属性:  enctype="multipart/form-data"
    <input name=”file” type=”file”>
  • 1
  • 2

写客户端接收的代码:

@RequestMapping("/blog/add")
 public void addBlog( MultipartFile file,Blog blog,HttpServletResponse response) throws IOException {
    // *首先校验图片格式
    // 获取文件名,带后缀
*    String originalFilename = file.getOriginalFilename();
    // *获取文件的后缀格式
*    String fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();

    // *只有当满足图片格式时才进来,重新赋图片名,防止出现名称重复的情况
*    String newFileName = UUID.randomUUID() + originalFilename;
    // 该方法返回的为当前项目的工作目录,即在哪个地方启动的java线程
*    String dirPath = System.getProperty("user.dir");
    String path = File.separator* + "src/main/resources/static/img/boximges" + File.*separator* + newFileName;
    File destFile = new File(dirPath + path);

    if (!destFile.getParentFile().exists()) {
      destFile.getParentFile().mkdirs();
    }
    try {
      file.transferTo(destFile);
      // *将相对路径返回给前端

*    } catch (IOException e) {

    }
   String imgpath= "../img/boximges/"+File.*separator* + newFileName;
    blog.setImgpath(imgpath);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

文件的下载:

/**
 * 下载文件
 * @param fileId 文件ID
 * @param session
 * @param request
 * @param response
 * @return 成功下载文件,失败返回0
 * @throws IOException
 */
@RequestMapping("/download.do")
public int downloadFile(Integer fileId, HttpSession session , HttpServletRequest request, HttpServletResponse response) throws IOException {
    String filePath="C:\\Users\\李庆\\Desktop\\help\\src\\main\\resources\\static\\s.docx";
        File file = new File(filePath);
        if(!file.exists()){
            System.out.println("Have no such file!");
            return 0;//文件不存在就退出方法
        }

        FileInputStream fileInputStream = new FileInputStream(file);
        //设置Http响应头告诉浏览器下载这个附件,下载的文件名也是在这里设置的
        response.setHeader("Content-Disposition", "attachment;Filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
        OutputStream outputStream = response.getOutputStream();
        byte[] bytes = new byte[2048];
        int len = 0;
        while ((len = fileInputStream.read(bytes))>0){
            outputStream.write(bytes,0,len);
        }
        fileInputStream.close();
        outputStream.close();


    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

拦截器的写法:

/*
** *拦截器
* **/
* @Configuration
public class LoginHandlerInterceptor implements HandlerInterceptor {
//目标方法执行之前
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object user = request.getSession().getAttribute(“user”);

 if (user == null) {
   //未登陆,返回登陆页面
  //request.setAttribute("msg", "没有权限请先登陆");
  response.sendRedirect("/admin");
   return false;
 } else {
   //已登陆,放行请求
   return true;
 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

}

​ 加入spring boot

@Configuration
public class Myconfig extends WebMvcConfigurerAdapter {

//所有的WebMvcConfigurerAdapter组件都会一起起作用
@Bean //将组件注册在容器
public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {

   //注册拦截器
   @Override
   public void addInterceptors(InterceptorRegistry registry) {
     //super.addInterceptors(registry);
     //静态资源; *.css , *.js
     //SpringBoot已经做好了静态资源映射
   registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/user/*","/title/*")
       .excludePathPatterns("/admin","/","/user/login");
   }
 };
 return adapter;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

}

}

利用thymeleaf表达式提取公共部分

 先在要截取的里面加入   th:fragment="heder" 
 如何直接引用    th:replace="user/comonm/hoerd::heder"
 
         user/comonm/hoerd: 这个是在那个包下的网页
 
              heder:这个就是我们要截取的
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

引用thymeleaf表达式

引用thymeleaf表达式转换时间对象的格式:

" ${#dates.format(对象,‘yyyy/MM/dd hh:mm’)}"

配置数据库源:在application文件

spring.datasource.url=jdbc:mysql://localhost:3306/bo

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.thymeleaf.cache=false

pagehelper.helperDialect=mysql

解决spring boot 上传图片不能立即显示的问题:

编写一个配置类

//所有的WebMvcConfigurerAdapter组件都会一起起作用
@Bean //将组件注册在容器

public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {

 //注册拦截器
 @Override
 public void addInterceptors(InterceptorRegistry registry) {
   //super.addInterceptors(registry);
   //静态资源; *.css , *.js
   //SpringBoot已经做好了静态资源映射
 registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/user/*","/title/*")
     .excludePathPatterns("/admin","/","/user/login");
 }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

};
return adapter;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String path = System.getProperty(“user.dir”)+"\src\main\resources\static\img\";
System.out.println(path);
// /images/是对应resource下工程目录
registry.addResourceHandler("/img/
").addResourceLocations(“file:”+path);
}

缓存

第一步 导入redis的缓存坐标:

org.springframework.boot spring-boot-starter-data-redis
  
  • 1

配置文件:

spring.datasource.url=jdbc:mysql://localhost:3306/spring_cache
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#驼峰命名规则
mybatis.configuration.map-underscore-to-camel-case=true

#配置redis
spring.redis.host=localhost

第二步:开启缓存注解:@EnableCaching  //开启缓存
  • 1

第三步:

实现简单的缓存技术

一般都是写在serivce层的

// 实现 缓存

@Cacheable(value = “address”,key = “‘R’”)
public Employee getEmployye(Integer id){
System.out.println(“查询员工”+id);
return employeMapper.getEmployeById(id);
}

实现缓存删除(就可以实时更新数据了):

//删除 同时删除缓存

//#id 根据id来删除
@CacheEvict(value = “address”,key = “‘R’”)
public void deleteEmp(Integer id){
employeMapper.deleteEmploye(id);
System.out.println(“删除员工”+id);

}

关于图片显示问题:

 写好映射配置类:

//新增加一个类用来添加虚拟路径映射
     //路径写在images下最好不然ta不起作用

 @Configuration
 public class MyPicConfig implements WebMvcConfigurer {
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
     String path = System.getProperty("user.dir")+"\src\main\resources\static\run\images\";
     //   /run /images/是对应resource下工程目录
     registry.addResourceHandler("/images/").addResourceLocations("file:"+path);
     String path1 = System.getProperty("user.dir")+"\src\main\resources\static\run\images\zf\";
     //    /images/是对应resource下工程目录
     registry.addResourceHandler("/zf/").addResourceLocations("file:"+path1);
   }
 }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

异步分页:

js

 //当页码加载完成后,调用load方法,发送ajax请求加载数据
 load(1,*sid*.value);
 var *a*=null;
 function load(cid ,rname){

 //发送ajax请求,请求route/pageQuery,传递cid
 $.post("/userfye",{page:cid,size:rname},function (pb) {
   /*
   *  private int pageNum;
     private int pageSize;
     private int size;
     private int startRow;
     private int endRow;
     private long total;
     private int pages;
                           *
   * */
   var lis = "";
   var fristPage = '<li style="background-color: white" οnclick="javascipt:load('+1+',\''+rname+'\')">首页</li>';

   //计算上一页的页码
   var beforeNum = pb.pageNum - 1;
   if(beforeNum <= 0){
     beforeNum = pb.pages;
   }

   var beforePage = '<li style="background-color: white" οnclick="javascipt:load('+beforeNum+''+',\''+rname+'\')" class="threeword">上一页</li>';

   lis += fristPage;
   lis += beforePage;
   //1.2 展示分页页码
   /*
     1.一共展示10个页码,能够达到前5后4的效果
     2.如果前边不够5个,后边补齐10个
     3.如果后边不足4个,前边补齐10个
     private int totalCount; //总记录数
     private int totalpace; //总页数
     private int cuurentpate; //当前页面
     private int paceSieze; //每一页的显示数

   */

   // 定义开始位置begin,结束位置 end
   var begin; // 开始位置
   var end ; // 结束位置

   //1.要显示10个页码
   if(pb.pages < 10){
     //总页码不够10页

     begin = 1;
     end = pb.pages;

   }else{
     //总页码超过10页

     begin = pb.pageNum - 5 ;
     end = pb.pageNum + 4 ;
     
     //2.如果前边不够5个,后边补齐10个
     if(begin < 1){
       begin = 1;
       end = begin + 9;
     }
     
     //3.如果后边不足4个,前边补齐10个
     if(end > pb.pages){
       end = pb.pages;
       begin = end - 9 ;
     }

   }

   for (var i = begin; i <= end ; i++) {
     var li;
     //判断当前页码是否等于i
     if(pb.pageNum == i){

       li = '<li class="curPage" οnclick="javascipt: load('+i+',\'' +rname+'\';)"><a href="javascript: void(0)">'+i+'</a></li>';
     
     }else{
       //创建页码的li
       li = '<li style="background-color: white" οnclick="javascipt: load('+i+',\''+rname+'\')"><a href="javascript: void(0)">'+i+'</a></li>';
     }
     //拼接字符串
     lis += li;

   }

   var a=pb.pageNum+1<=pb.pages?pb.pageNum+1:1;
   var pages=pb.pages;
   var lastPage = '<li style="background-color: white" class="threeword" οnclick="javascipt: load('+pages+',\''+rname+'\')">末页</li>';
   var nextPage = '<li style="background-color: white" class="threeword" οnclick="javascipt: load('+a+',\''+rname+'\')">下一页</li>';

   lis += nextPage;
   lis += lastPage;

   //将lis内容设置到 ul
   $("#pageNsum").html(lis);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100

Css:

Body:

    
  • 1
    <table id="add-row" class="display table table-striped table-hover" >
        <thead>
        <tr>
            <th>id</th>
            <th>Name</th>
            <th>电子邮箱</th>
            <th style="width: 10%">操作</th>
        </tr>
        </thead>
        <tfoot>
        <tr>
            <th>id</th>
            <th>Name</th>
            <th>电子邮箱</th>
            <th style="width: 10%">操作</th>
        </tr>
        </tfoot>
        <tbody id="trid">
        </tbody>
    </table>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

Mybatis的注解动态开发:

    @TableField(exist = false) // 注明非数据库字段属性
  • 1

​ @JsonInclude(JsonInclude.Include.NON_EMPTY) 当参数为空不返回

如何在插

@Update("<script>update user set" +
     "<if test='name!=null'>name=#{name}</if>" +
     "<if test='user_password!=null'>,user_password=#{user_password}</if>" +
     "<if test='sex!=null'>,sex=#{sex}</if>" +
     "<if test='email!=null'>,email=#{email}</if>" +
     "where id=#{id}</script>")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

入的数据过后获取id:

INSERT INTO ssm.application( name, size, platform, sort_id, status, versions, logo) VALUES ( ‘LOL’, 20, ‘安卓’, 1, 1, ‘v1.2’, ‘img/logo.png’) ; select @@IDENTITY;

Ssm搭建问题:

https://blog.csdn.net/fairytailrose/article/details/92827017

ssm搭建坐标:

<!-- 统一管理jar包版本 --> <properties>     <spring.version>5.0.2.RELEASE</spring.version>     <slf4j.version>1.6.6</slf4j.version>     <log4j.version>1.2.12</log4j.version>     <shiro.version>1.2.3</shiro.version>     <mysql.version>8.0.13</mysql.version>     <mybatis.version>3.4.5</mybatis.version>     <spring.security.version>5.0.1.RELEASE</spring.security.version> </properties>  <!-- 锁定jar包版本 --> <dependencyManagement>     <dependencies>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-context</artifactId>             <version>${spring.version}</version>         </dependency>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-web</artifactId>             <version>${spring.version}</version>         </dependency>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-webmvc</artifactId>             <version>${spring.version}</version>         </dependency>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-tx</artifactId>             <version>${spring.version}</version>         </dependency>         <dependency>             <groupId>org.springframework</groupId>             <artifactId>spring-test</artifactId>             <version>${spring.version}</version>         </dependency>         <dependency>             <groupId>org.mybatis</groupId>             <artifactId>mybatis</artifactId>             <version>${mybatis.version}</version>         </dependency>     </dependencies> </dependencyManagement>  <!-- 项目依赖jar包 --> <dependencies>     <!-- spring -->     <dependency>         <groupId>org.aspectj</groupId>         <artifactId>aspectjweaver</artifactId>         <version>1.6.8</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-aop</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-context</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-context-support</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-web</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-orm</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-beans</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-core</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-test</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-webmvc</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-tx</artifactId>         <version>${spring.version}</version>     </dependency>     <dependency>         <groupId>junit</groupId>         <artifactId>junit</artifactId>         <version>4.12</version>         <scope>test</scope>     </dependency>     <dependency>         <groupId>mysql</groupId>         <artifactId>mysql-connector-java</artifactId>         <version>${mysql.version}</version>     </dependency>     <dependency>         <groupId>javax.servlet</groupId>         <artifactId>javax.servlet-api</artifactId>         <version>3.1.0</version>         <scope>provided</scope>     </dependency>     <dependency>         <groupId>javax.servlet.jsp</groupId>         <artifactId>jsp-api</artifactId>         <version>2.0</version>         <scope>provided</scope>     </dependency>     <dependency>         <groupId>jstl</groupId>         <artifactId>jstl</artifactId>         <version>1.2</version>     </dependency>     <!-- log start -->     <dependency>         <groupId>log4j</groupId>         <artifactId>log4j</artifactId>         <version>${log4j.version}</version>     </dependency>     <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-api</artifactId>         <version>${slf4j.version}</version>     </dependency>     <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-log4j12</artifactId>         <version>${slf4j.version}</version>     </dependency>     <!-- log end -->     <dependency>         <groupId>org.mybatis</groupId>         <artifactId>mybatis</artifactId>         <version>${mybatis.version}</version>     </dependency>     <dependency>         <groupId>org.mybatis</groupId>         <artifactId>mybatis-spring</artifactId>         <version>1.3.0</version>     </dependency>     <dependency>         <groupId>c3p0</groupId>         <artifactId>c3p0</artifactId>         <version>0.9.1.2</version>         <type>jar</type>         <scope>compile</scope>     </dependency>     <dependency>         <groupId>com.github.pagehelper</groupId>         <artifactId>pagehelper</artifactId>         <version>5.1.2</version>     </dependency>     <dependency>         <groupId>com.alibaba</groupId>         <artifactId>druid</artifactId>         <version>1.0.9</version>     </dependency> </dependencies>
  • 1

Spring cloud:

写在实体类的class上 就不用写get和set方法了

import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;

 @Data
 @AllArgsConstructor
 @NoArgsConstructor

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

mybatis-plus的笔记

开发笔记:

分页的笔记

导入三个坐标:

pom文件加这三个,缺一个都不行

<dependency>

  <groupId>com.github.pagehelper</groupId>

  <artifactId>pagehelper-spring-boot-starter</artifactId>

  <version>1.2.5</version>

</dependency>

<dependency>

  <groupId>com.github.pagehelper</groupId>

  <artifactId>pagehelper</artifactId>

  <version>5.0.3</version>

</dependency>

<dependency>

  <groupId>com.github.pagehelper</groupId>

  <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>

  <version>1.2.5</version>

</dependency>  

 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

​ 网页分页的:

利用thymeleaf表达式分页

关于分页静态路径出错的解决方法:

文件上传

           第一步表单要加上这个属性:  enctype="multipart/form-data"
    <input name=”file” type=”file”>
  • 1
  • 2

写客户端接收的代码:

 @RequestMapping("/blog/add")
 public void addBlog( MultipartFile file,Blog blog,HttpServletResponse response) throws IOException {
    // *首先校验图片格式
    // 获取文件名,带后缀
*    String originalFilename = file.getOriginalFilename();
    // *获取文件的后缀格式
*                                 

    *//* *只有当满足图片格式时才进来,重新赋图片名,防止出现名称重复的情况

*    String newFileName = UUID.randomUUID() + originalFilename;
    // 该方法返回的为当前项目的工作目录,即在哪个地方启动的java线程
*    String dirPath = System.getProperty("user.dir");
    String path = File.separator* + "src/main/resources/static/img/boximges" + File.*separator* + newFileName;
    File destFile = new File(dirPath + path);

    if (!destFile.getParentFile().exists()) {
      destFile.getParentFile().mkdirs();
    }
    try {
      file.transferTo(destFile);
      *//* *将相对路径返回给前端

*    } catch (IOException e) {

    }

   String imgpath= "../img/boximges/"+File.*separator* + newFileName;
    blog.setImgpath(imgpath);

 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

拦截器的写法:

*/**
 **  *拦截器
* **/
* @Configuration
 public class LoginHandlerInterceptor implements HandlerInterceptor {
   //目标方法执行之前
   @Override
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
     Object user = request.getSession().getAttribute("user");

     if (user == null) {
       //未登陆,返回登陆页面
      //request.setAttribute("msg", "没有权限请先登陆");
      response.sendRedirect("/admin");
       return false;
     } else {
       //已登陆,放行请求
       return true;
     }

   }

     加入spring boot

 

 @Configuration
 public class Myconfig extends WebMvcConfigurerAdapter {

 

   //所有的WebMvcConfigurerAdapter组件都会一起起作用
   @Bean //将组件注册在容器
   public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
     WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {

       //注册拦截器
       @Override
       public void addInterceptors(InterceptorRegistry registry) {
         //super.addInterceptors(registry);
         //静态资源; *.css , *.js
         //SpringBoot已经做好了静态资源映射
       registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/user/*","/title/*")
           .excludePathPatterns("/admin","/","/user/login");
       }
     };
     return adapter;

   }

 

 }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

利用thymeleaf表达式提取公共部分

 先在要截取的里面加入   th:fragment="heder" 
 如何直接引用    th:replace="user/comonm/hoerd::heder"
 
         user/comonm/hoerd: 这个是在那个包下的网页
 
              heder:这个就是我们要截取的
              
                引用thymeleaf表达式

<html xmlns:th="http://www.thymeleaf.org">

引用thymeleaf表达式转换时间对象的格式:

 " ${#dates.format(对象,'yyyy/MM/dd hh:mm')}"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

配置数据库源:在application文件

spring.datasource.url=jdbc:mysql://localhost:3306/bo

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.thymeleaf.cache=false

pagehelper.helperDialect=mysql

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

解决spring boot 上传图片不能立即显示的问题:

编写一个配置类

//所有的WebMvcConfigurerAdapter组件都会一起起作用
 @Bean //将组件注册在容器

 public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
   WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {

     //注册拦截器
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
       //super.addInterceptors(registry);
       //静态资源; *.css , *.js
       //SpringBoot已经做好了静态资源映射
     registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/user/*","/title/*")
         .excludePathPatterns("/admin","/","/user/login");
     }

   };
   return adapter;
 }
 @Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
   String path = System.getProperty("user.dir")+"\src\main\resources\static\img\";
   System.out.println(path);
   //    /images/是对应resource下工程目录
   registry.addResourceHandler("/img/").addResourceLocations("file:"+path);
 }

   

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

缓存

第一步 导入redis的缓存坐标:

<!--导入redis的坐标-->

 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-redis</artifactId>
 </dependency>
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

配置文件:

spring.datasource.url=jdbc:mysql://localhost:3306/spring_cache
 spring.datasource.username=root
 spring.datasource.password=root
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver

 #驼峰命名规则
 mybatis.configuration.map-underscore-to-camel-case=true

 #配置redis
 spring.redis.host=localhost

 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
第二步:开启缓存注解:@EnableCaching  //开启缓存
  • 1
第三步:

实现简单的缓存技术

 一般都是写在serivce层的

// 实现 缓存

@Cacheable(value = "address",key = "'R'")
 public Employee getEmployye(Integer id){
   System.out.println("查询员工"+id);
 return employeMapper.getEmployeById(id);
 }

 

               

 实现缓存删除(就可以实时更新数据了):

//删除 同时删除缓存

//#id 根据id来删除
 @CacheEvict(value = "address",key = "'R'")
 public void deleteEmp(Integer id){
   employeMapper.deleteEmploye(id);
   System.out.println("删除员工"+id);

 }

 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

关于图片显示问题:

写好映射配置类:

//新增加一个类用来添加虚拟路径映射

 @Configuration
 public class MyPicConfig implements WebMvcConfigurer {
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
     String path = System.getProperty("user.dir")+"\src\main\resources\static\run\images\";
     //   /run /images/是对应resource下工程目录
     registry.addResourceHandler("/images/").addResourceLocations("file:"+path);
     String path1 = System.getProperty("user.dir")+"\src\main\resources\static\run\images\zf\";
     //    /images/是对应resource下工程目录
     registry.addResourceHandler("/zf/").addResourceLocations("file:"+path1);
   }
 }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

异步分页:

js

//当页码加载完成后,调用load方法,发送ajax请求加载数据
load(1,*sid*.value);
var *a*=null;
function load(cid ,rname){

//发送ajax请求,请求route/pageQuery,传递cid
$.post("/userfye",{page:cid,size:rname},function (pb) {
/*
* private int pageNum;
private int pageSize;
private int size;
private int startRow;
private int endRow;
private long total;
private int pages;
*
* */
var lis = “”;
var fristPage = ‘

  • 首页
  • ’;

    //计算上一页的页码
    var beforeNum = pb.pageNum - 1;
    if(beforeNum <= 0){
    beforeNum = pb.pages;
    }

    var beforePage = ‘

  • 上一页
  • ’;

    lis += fristPage;
    lis += beforePage;
    //1.2 展示分页页码
    /*
    1.一共展示10个页码,能够达到前5后4的效果
    2.如果前边不够5个,后边补齐10个
    3.如果后边不足4个,前边补齐10个
    private int totalCount; //总记录数
    private int totalpace; //总页数
    private int cuurentpate; //当前页面
    private int paceSieze; //每一页的显示数

    */

    // 定义开始位置begin,结束位置 end
    var begin; // 开始位置
    var end ; // 结束位置

    //1.要显示10个页码
    if(pb.pages < 10){
    //总页码不够10页

     begin = 1;
     end = pb.pages;
    
    • 1
    • 2

    }else{
    //总页码超过10页

     begin = pb.pageNum - 5 ;
     end = pb.pageNum + 4 ;
     
     //2.如果前边不够5个,后边补齐10个
     if(begin < 1){
       begin = 1;
       end = begin + 9;
     }
     
     //3.如果后边不足4个,前边补齐10个
     if(end > pb.pages){
       end = pb.pages;
       begin = end - 9 ;
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    }

    for (var i = begin; i <= end ; i++) {
    var li;
    //判断当前页码是否等于i
    if(pb.pageNum == i){

       li = '<li class="curPage" onclick="javascipt: load('+i+',\'' +rname+'\';)"><a href="javascript: void(0)">'+i+'</a></li>';
     
     }else{
       //创建页码的li
       li = '<li style="background-color: white" onclick="javascipt: load('+i+',\''+rname+'\')"><a href="javascript: void(0)">'+i+'</a></li>';
     }
     //拼接字符串
     lis += li;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    }

    var a=pb.pageNum+1<=pb.pages?pb.pageNum+1:1;
    var pages=pb.pages;
    var lastPage = ‘

  • 末页
  • ’;
    var nextPage = ‘
  • 下一页
  • ’;

    lis += nextPage;
    lis += lastPage;

    //将lis内容设置到 ul
    $("#pageNsum").html(lis);

    Css:

    Body:

        
    
    • 1
        <table id="add-row" class="display table table-striped table-hover" >
            <thead>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>电子邮箱</th>
                <th style="width: 10%">操作</th>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>电子邮箱</th>
                <th style="width: 10%">操作</th>
            </tr>
            </tfoot>
            <tbody id="trid">
            </tbody>
        </table>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    Mybatis的注解动态开发:

    @Update(“”)

    如何在插入的数据过后获取id:

    INSERT INTO ssm.application( name, size, platform, sort_id, status, versions, logo) VALUES ( ‘LOL’, 20, ‘安卓’, 1, 1, ‘v1.2’, ‘img/logo.png’) ; select @@IDENTITY;

    Ssm搭建问题:

    https://blog.csdn.net/fairytailrose/article/details/92827017

    ssm搭建坐标:

       

    Spring cloud:

    写在实体类的class上 就不用写get和set方法了

    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor

    mybatis-plus的笔记

    maven的坐标:

    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-generator</artifactId>
        <version>3.4.0</version>
    </dependency>
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.4.0</version>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TTtChEjI-1612766936846)(image-20210103085534422.png)]

    代码生成的器的代码:

    package com.mybatis_puls.demo;
    
    import com.baomidou.mybatisplus.annotation.DbType;
    import com.baomidou.mybatisplus.annotation.FieldFill;
    import com.baomidou.mybatisplus.annotation.IdType;
    import com.baomidou.mybatisplus.generator.AutoGenerator;
    import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
    import com.baomidou.mybatisplus.generator.config.GlobalConfig;
    import com.baomidou.mybatisplus.generator.config.PackageConfig;
    import com.baomidou.mybatisplus.generator.config.StrategyConfig;
    import com.baomidou.mybatisplus.generator.config.po.TableFill;
    import com.baomidou.mybatisplus.generator.config.rules.DateType;
    import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
    
    import java.io.FileFilter;
    import java.util.ArrayList;
    
    //代码自动生成器/**/
    public class Geenter {
        public static void main(String[] args) {
           //需要构建一个 代码自动生产器 对象
            AutoGenerator mpg = new AutoGenerator();
            //配置策略
    
            //1.全局配置
            GlobalConfig gc=new GlobalConfig();
            //获取系统的当前路径
            Object property = System.getProperty("user.dir");
            gc.setOutputDir(property+"/src/main/java");
            gc.setAuthor("小
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/258355
推荐阅读
相关标签