Spring boot upload files with multiple parameter

How do i upload file with multiple parameter in spring boot in submit form Thanks in advance
17 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @1howard1.! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Ankit
Ankit6mo ago
u trying to create apis ryt ?
1howard1.
1howard1.OP6mo ago
Simple input form A lot of things in google doesnt work as expected
ayylmao123xdd
ayylmao123xdd6mo ago
multiple parameters as in file has multiple parameters or the request has multiple parameters
1howard1.
1howard1.OP6mo ago
Both multiple files with multiple parameter
ayylmao123xdd
ayylmao123xdd6mo ago
i mean you can just make a request param for files and make it MultipartFile[] as param type
1howard1.
1howard1.OP6mo ago
Several sources i saw nothing works
ayylmao123xdd
ayylmao123xdd6mo ago
show
1howard1.
1howard1.OP6mo ago
Imma send u 2 hours from now Im not infront of my laptop
Dexter
Dexter6mo ago
@PostMapping(value = "/Barang/submit", params = {"add"})
public String barangAdd(@ModelAttribute BarangEntity barInfo, Model model) {
List<BarangEntity> barList = barangService.getAllBar();
BarangEntity bar = barangService.addBar(barInfo);
model.addAttribute("barList", barangService.getAllBar());
model.addAttribute("barInfo", barInfo);

return "redirect:/Barang";
}
@PostMapping(value = "/Barang/submit", params = {"add"})
public String barangAdd(@ModelAttribute BarangEntity barInfo, Model model) {
List<BarangEntity> barList = barangService.getAllBar();
BarangEntity bar = barangService.addBar(barInfo);
model.addAttribute("barList", barangService.getAllBar());
model.addAttribute("barInfo", barInfo);

return "redirect:/Barang";
}
This message has been formatted automatically. You can disable this using /preferences.
Dexter
Dexter6mo ago
package com.example.demo.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import org.springframework.util.StringUtils; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Objects; import com.example.demo.Entity.BarangEntity; import com.example.demo.Repository.BarangRepo; @Service
public class BarangService {

@Autowired
private BarangRepo barangRepo;



public List<BarangEntity> getAllBar() {
return barangRepo.findAll();
}

public BarangEntity getBarById(int id) {
return barangRepo.findById(id).orElse(null);
}

public BarangEntity addBar(BarangEntity bar) {
return barangRepo.save(bar);
}



public void updateBar(int id, BarangEntity bar) {
bar.setIdBarang(id);
barangRepo.save(bar);
}


public void deleteBar(int id) {
BarangEntity bar = barangRepo.findById(id).orElse(null);
barangRepo.deleteById(id);
}
}
public class BarangService {

@Autowired
private BarangRepo barangRepo;



public List<BarangEntity> getAllBar() {
return barangRepo.findAll();
}

public BarangEntity getBarById(int id) {
return barangRepo.findById(id).orElse(null);
}

public BarangEntity addBar(BarangEntity bar) {
return barangRepo.save(bar);
}



public void updateBar(int id, BarangEntity bar) {
bar.setIdBarang(id);
barangRepo.save(bar);
}


public void deleteBar(int id) {
BarangEntity bar = barangRepo.findById(id).orElse(null);
barangRepo.deleteById(id);
}
}
this is service
This message has been formatted automatically. You can disable this using /preferences.
ayylmao123xdd
ayylmao123xdd6mo ago
those are not files at least from what i read
1howard1.
1howard1.OP6mo ago
here
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?