小编Edu*_*uBw的帖子

将上传的Excel保存在数据库中

我有一个代码,我的客户端将excel文件发送到服务器.服务器(SpringBoot)需要"转换" MultiplartFile为excel文件.从那时起,数据需要插入到数据库中.

但是,我从不需要生成excel,而是应该直接将电子表格中的数据插入到数据库中.

我第一次尝试:

@RequestMapping(value = "/insert", method = RequestMethod.POST, consumes = "multipart/form-data")
@ResponseBody
public MyMessage insertExcell(@RequestPart("typeFile") String typeFile,
        @RequestPart("uploadFile") MultipartFile multipart, @RequestPart("dataUser") DataUser dataUser) {

    BufferedReader br;
    List<String> result2 = new ArrayList<String>();

    try {
        String line;
        InputStream is = multipart.getInputStream();
        br = new BufferedReader(new InputStreamReader(is));
        while ((line = br.readLine()) != null) {
            result2.add(line);
        }
    } catch (Exception e) {

    }

    for (int i = 0; i < result2.size(); i++) {
        System.out.println("sentence" + result2.get(i));;
    }
Run Code Online (Sandbox Code Playgroud)

输出返回奇怪的符号.

然后我再试一次:

InputStream inputStream; …
Run Code Online (Sandbox Code Playgroud)

java excel spring-mvc spring-boot

9
推荐指数
1
解决办法
118
查看次数

使用 DynamoDb 回滚?

我有一个问题,如果我在 DynamoDb 中插入 5 o 6 个元素,但例如 6º 失败。如何在 dynamoDb 中进行回滚?

    MyMessage myMessage = new MyMessage(true, "ok");
    Article art;

    for (int i = 0; i < list.size(); i++) {
        art= (Article) list.get(i);
        try {
            this.artRepository.save(art);
        } catch (Exception e) {
            myMessage.setSuccess(false);
            myMessage.setMessage("Fail.");
        }
    }

    if(myMessage.isSuccess()) {
        artRepository.save..
    }else{
      Rollback.
    }
Run Code Online (Sandbox Code Playgroud)

amazon-dynamodb

3
推荐指数
1
解决办法
5574
查看次数

AgGrid中的行数

我想在AgGrid中显示行数,但是出现问题。

    ngOnInit() { 
      console.log(this.gridOptions.api.getDisplayedRowCount());
    }
Run Code Online (Sandbox Code Playgroud)

错误:

ERROR TypeError: Cannot read property 'getDisplayedRowCount' of undefined
    at ProjectListComponent.webpackJsonp../src/app/project-list/project-list.component.ts.ProjectListComponent.ngOnInit (project-list.component.ts:178)
    at checkAndUpdateDirectiveInline (core.js:12411)
    at checkAndUpdateNodeInline (core.js:13935)
    at checkAndUpdateNode (core.js:13878)
    at debugCheckAndUpdateNode (core.js:14771)
    at debugCheckDirectivesFn (core.js:14712)
    at Object.eval [as updateDirectives] (ProjectListComponent_Host.ngfactory.js? [sm]:1)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14697)
    at checkAndUpdateView (core.js:13844)
    at callViewAction (core.js:14195)
Run Code Online (Sandbox Code Playgroud)

Api AgGrid:

getDisplayedRowCount()  Returns the total number of displayed rows.
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会有这个问题...

ag-grid

2
推荐指数
1
解决办法
4797
查看次数

onCellClicked 仅第一个 Cell AgGrid

我只想获取第一列的数据,或者我知道索引列,AgGrid Angular2。

我正在使用

cellClicked
Run Code Online (Sandbox Code Playgroud)

html

(cellClicked)="onCellClicked(event)" 
Run Code Online (Sandbox Code Playgroud)

组件.ts

onCellClicked(event) {
    console.log('(event', event);
}
Run Code Online (Sandbox Code Playgroud)

问题是我可以在所有行中“单击”... 但我只想在第一列中单击或使用 if() 知道 indexCell 并且如果 It is cell == 0 ...

ag-grid angular

2
推荐指数
1
解决办法
3641
查看次数

router.navigateByUrl不发送值Angular

我正在尝试在组件Angular之间发送1值...但是当我到达组件时,我什么也没收到。

组件1:

onCellClicked(event) {
    if (event.colDef.field === 'dni') {
      console.log('dni en mi componente : ', event.value);
      this.router.navigateByUrl('probarborrar/', event.value);
    }
  }
Run Code Online (Sandbox Code Playgroud)

首先检查Cell是否为dni,然后显示"console.log(event.value)"是真的,我可以看到我的dni。最后,我讲第二部分。

路由。

     {
        path: 'probarborrar/:idUser',
        component: ProbandoBorrarComponent,
        data: {
          breadcrumb: 'probar'
        }
      }
Run Code Online (Sandbox Code Playgroud)

组件2。

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-probando-borrar',
  templateUrl: './probando-borrar.component.html',
  styleUrls: ['./probando-borrar.component.scss']
})
export class ProbandoBorrarComponent implements OnInit {
  public dni;

  constructor(private route: ActivatedRoute) {}

  ngOnInit() {
    this.dni= this.route.snapshot.paramMap.get('idUser');
    console.log('en probando es :', this.dni); -->nothing
  } …
Run Code Online (Sandbox Code Playgroud)

angular

1
推荐指数
1
解决办法
1887
查看次数

使用 Angular6 将 Excel Base 64 转换为 Excel

我有一个 Springboot 服务,可以将 base64 中的文件(Excel)发送到 Angular6。为了安全起见,我无法直接发送文件,因此,我首先将文件转换为 base64 ...

在我的 Angular 中,我可以收到 base64 :

 {
  "file" : "UEsDBBQACAAIAJOOOU/kSK2vGAEAADMDAAATAAAAW0NvbnRlbnRfVHlwZXNdLnht" 
 }  
Run Code Online (Sandbox Code Playgroud)

字符串文件比较长...

但是,当我尝试打开此文件时,在 LibreOffice 中出现错误“文件损坏”

this.data.getFile(endPoint).subscribe( 
          data => {          
                     const myfile= atob(data.file);
                     const blob = new Blob([myfile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
                     saveAs(blob, 'myfile.xlsx'); 
                  } );
Run Code Online (Sandbox Code Playgroud)

编辑:

这是“myfile”=> 的值

在此处输入图片说明

请,我需要帮助..

当我这样做时,Angular 不会出错,saveAs(blob, 'myfile.xlsx'); 但是如果我尝试打开文件,则会出错。

angular6

1
推荐指数
1
解决办法
2267
查看次数

cellClicked不要调用函数AgGrid Angular 2

我想在单元格中“单击”并显示console.log,但是此功能无法运行:

  headerName: 'Id',
  field: 'id',
  cellClicked: function() {
          console.log('asssaasas');
  }
Run Code Online (Sandbox Code Playgroud)

我确实在单元格中单击了AgGRID,但是在html5.console中我什么也没显示。

ag-grid angular

0
推荐指数
1
解决办法
2077
查看次数

我的数组是未定义的Angular2

我想在我的数组中放入10个数字,但我得到了未定义

public arrayDrag: number[];

ngOnInit() {
    this.arrayDrag = new Array(); //or   this.arrayDrag = new Array(10)
}

  rowDragEnd(event) {
    let max = 0;
    this.arrayDrag = new Array();  //or   this.arrayDrag = new Array(10)

    this.gridApi.forEachNodeAfterFilterAndSort(function(node) {
      if (max < 10) {
        this.arrayDrag.push(node.data.point);
        console.log('add', node.data.point);
        max += 1;
      }
    });
  }
Run Code Online (Sandbox Code Playgroud)

我用(0)或(10)向arrayDrag声明,当我的事件是调用(rowDragEnd)时,我得到错误"undefined" this.arrayDrag.push(

angular

0
推荐指数
1
解决办法
71
查看次数

extends WebSecurityConfigurerAdapter 无法解析

我正在使用 SpringBoot 我需要使用扩展 WebSecurityConfigurerAdapter 来使用“CORS”。

但是当我放置“extends WebSecurityConfigurerAdapter”时出现错误

Description Resource    Path    Location    Type
The type org.springframework.security.authentication.AuthenticationManager cannot be resolved. It is indirectly referenced from required .class files   ServiciosConfig.java    /tutorial/src/main/java/com/service/configure   line 1  Java Problem
Run Code Online (Sandbox Code Playgroud)

我更新了 pom.xml :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

与版本:

<version>1.5.14.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)

代码:

package com.service.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;


@Configuration
@EnableWebSecurity
@ComponentScan(basePackages = "com.service.services")
@PropertySource("file:${ruta_properties}")
public class ServiciosConfig  extends WebSecurityConfigurerAdapter { …
Run Code Online (Sandbox Code Playgroud)

spring-boot

0
推荐指数
1
解决办法
6011
查看次数

如何在打字稿中格式化日期?

当我在Angular2(打字稿)中执行新的Date()时,我得到-> DATEE Wed Jul 18 2018 09:13:40 GMT + 0200

问题是我已将Date发送给Java,但是Java不允许这种格式。

Java只允许,dd / mm / aaaa或aaaaa / mm / dd,但他不允许Wed Jul 18 2018 09:13:40 GMT + 0200。

我尝试在Angular中创建新格式,但始终获取String,但是我需要格式化Date,因为我在Java中的类获取Date。

let myDate: Date, myDay, myMonth, myYear;

myDate = new Date();
myDay  = myDate.setUTCFullYear;
console.log(myDay);
myDay  = myDate.toISOString;
console.log(myDay);
console.log(typeof(myDay));
console.log(new Date(myDay));
Run Code Online (Sandbox Code Playgroud)

我无法安装默认情况下没有角度的库,例如:“ moment”。泰

date typescript angular

0
推荐指数
2
解决办法
8629
查看次数

字段 uploadFile 超出

我正在尝试使用 SpringBoot 从客户端发送 Excel,但是当我获取 File 时出现错误。我在我的属性中添加了最大 10MB 或 300MB,但它不运行。

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException:字段 uploadFile 超出了其最大允许大小 1048576 字节。在 org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:630) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache .tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 位于 org.apache.tomcat.util.http。 fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 java.io.FilterInputStream.read(未知来源) ~[na:1.8。 0_171] 在 org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache. tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 位于 org.apache.tomcat.util.http.fileupload .FileUploadBase.parseRequest(FileUploadBase.java:293) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache.catalina.connector.Request.parseParts(Request.java:2869) ~[ tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache.catalina.connector.Request.parseParameters(Request.java:3216) ~[tomcat-embed-core-8.5.27.jar:8.5 .27] 在 org.apache.catalina.connector.Request.getParameter(Request.java:1137) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache.catalina.connector.RequestFacade .getParameter(RequestFacade.java:381) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:75) ~[spring- web-4.3.14.RELEASE.jar:4.3.14.RELEASE] 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar:4.3 .14.RELEASE] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.apache.catalina.core .ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27] 在 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[ spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE] 在 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar :4.3.14.RELEASE] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27] …

spring-boot

0
推荐指数
1
解决办法
2243
查看次数

在TypeScript中使用forEach返回boolean

我想检查我的数组,如果我得到3,我想破坏我的forEach,如果不正确,则返回true或false。

但是当我在html-中按3时,我变得不确定

 let errorSave: boolean = this.checkParams();

 console.log("errorSave" , errorSave); // UNDEFINED

 checkParams() {
        let errorSave = this.params.forEach(element => {
            if (element.origin === 3) {
               return true;
            }
        });
        return errorSave;
    }
Run Code Online (Sandbox Code Playgroud)

javascript typescript

0
推荐指数
1
解决办法
559
查看次数