質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

0回答

2995閲覧

Vue.jsからCSVファイルを読み込み、SpringBootで受け取りたい

tennis

総合スコア19

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2020/06/19 22:30

編集2022/01/12 10:55

解決したいこと

Vue.jsからCSVを読み込み、SpringBoot側で受け取りたいです。

Vue

1<template> 2 <b-card 3 header="外部ファイルの読み込み" 4 > 5 <v-list two-line subheader dense> 6 <v-subheader>外部ファイルを読み込む</v-subheader> 7 <v-list-item> 8 <v-list-item-content> 9 <v-list-item-title> 10 <v-file-input 11 label="File input" 12 v-model="file" 13 name=file 14 placeholder="読み込みたいファイル" 15 ></v-file-input> 16 </v-list-item-title> 17 </v-list-item-content> 18 <v-list-item-action-text class="pl-4"> 19 <b-button 20 variant="outline-success" 21 :disabled="file === ''" 22 size="sm" 23 @click="uploadFile()" 24 >ファイルを読み込む 25 </b-button> 26 </v-list-item-action-text> 27 </v-list-item> 28 <v-divider></v-divider> 29 </v-list> 30 </b-card> 31</template> 32<script> 33export default { 34 data() { 35 return { 36 file: "", 37 }; 38 }, 39 methods: { 40 uploadFile() { 41 this.$axios.post('/user/impoertUser', this.file, { 42 headers: { 'Content-Type': 'multipart/form-data' } 43 }).then((res) => { 44 console.log(res.data) 45 }) 46 } 47 } 48}; 49</script> 50

Java

1package com.example.controller; 2 3import java.io.BufferedReader; 4import java.io.IOException; 5import java.io.InputStream; 6import java.io.InputStreamReader; 7import java.io.Reader; 8 9import org.springframework.beans.factory.annotation.Autowired; 10import org.springframework.web.bind.annotation.RequestMapping; 11import org.springframework.web.bind.annotation.RequestMethod; 12import org.springframework.web.bind.annotation.RequestParam; 13import org.springframework.web.bind.annotation.RestController; 14import org.springframework.web.multipart.MultipartFile; 15 16import com.example.form.RegisterUserForm; 17import com.example.service.RegisterUserService; 18 19@RestController 20@RequestMapping("/user") 21public class ImportCSVController { 22 23 @Autowired 24 private RegisterUserService registerUserService; 25 26 @RequestMapping(value = "/importUser", headers = "Content-Type= multipart/form-data", method = RequestMethod.POST) 27 public void importUser(@RequestParam("file") MultipartFile uploadFile) { 28 29 System.err.println(uploadFile); 30 31 String line = null; 32 33 try { 34 InputStream stream = uploadFile.getInputStream(); 35 Reader reader = new InputStreamReader(stream); 36 BufferedReader buf= new BufferedReader(reader); 37 38 line = buf.readLine(); 39 while((line = buf.readLine()) != null) { 40 41 String[] data = line.split(",", 0); 42 43 RegisterUserForm form = new RegisterUserForm(); 44 45 form.setUserName(data[0]); 46 form.setMailAddress(data[1]); 47 form.setPassword(data[2]); 48 registerUserService.registerUser(form); 49 50 } 51 52 } catch (IOException e) { 53 54 line = "Can't read contents."; 55 e.printStackTrace(); 56 57 } 58 59 } 60} 61

Spring側でうまく受け取れず、困っています。よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問