小编Ana*_*ary的帖子

在Laravel中导入Excel工作表并在UI中显示提取的数据

我在我的前端使用Angular 4,在后端使用Laravel 5.2.我想从UI导入Excel工作表,将值存储在DB中,检索值并使用Angular在UI中显示它们.

我在laravel中使用Maatwebsite/Excel包.我的excel表具有以下结构.

图片链接

名字| 细节| 价格
expertphp | 在线教程| 100
你好| 代码| 200

我的laravel代码如下:这里myFile是具有文件路径和名称作为其值的键.

    $File = $request->file('myFile');
    $path = $request->file('myFile')->getRealPath();
    $real_name = $File->getClientOriginalName();
    $data = Excel::load($path)->get();

    if($data->count()){
        foreach($data as $key => $value){
            $arr[] = ['name' => $value->name, 'details' => $value->details, 'price' => $value->price];
        }
    }

    return response()->success($data);
Run Code Online (Sandbox Code Playgroud)

我收到如下响应:

     {
        "errors":false,
        "data":[
                {
                   "namedetailsprice":"expertphp\tOnline tutorials\t100"
                },
                {
                   "namedetailsprice":"hello\tfirst code\t2000"
                }
               ]
      }
Run Code Online (Sandbox Code Playgroud)

我不明白为什么标题会成为一个字段.感谢任何帮助.

谢谢.

laravel csvtoarray angular

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

Spring Boot 中的 API 调用出现 404 错误

我正在开发一个 Spring Boot 应用程序。我在点击我配置的 URL 路径时收到404 错误。我哪里错了?

主控制器.java

package com.example.homes;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("/add")
public class HomeController {

    @GetMapping("/hello")
    public String add() {
        return "Hello";
    }

}
Run Code Online (Sandbox Code Playgroud)

主页应用程序.java

package com.example.homes;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class HomeApplication {

    public static void main(String[] args) {
        SpringApplication.run(HomeApplication.class, args);
        System.out.println("Inside main");
    }

}
Run Code Online (Sandbox Code Playgroud)

java spring http-status-code-404 spring-boot

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