Commit 0bb77fbc by Mihailo Sebek

insert komentar

parent e9e445d1
......@@ -17,8 +17,7 @@ public class KomentarController
KomentarRepository komentarRepo;
@PostMapping("/profile/moji-zahtevi/sacuvaj-komentar")
public String postSacuvajKomentar(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @ModelAttribute("komentar") Komentar komentar)
{
public String postSacuvajKomentar(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @ModelAttribute("komentar") Komentar komentar) throws Exception {
komentarRepo.insert( loggedUser.getKorisnik().getKorisnikId(), komentar);
return ("redirect:/profile/moji-zahtevi");
}
......
package com.example.SkuciSe.repository;
import com.example.SkuciSe.model.komentar.Komentar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Base64;
import java.util.concurrent.Callable;
@Component
public class KomentarRepository {
public void insert(int korisnikId, Komentar komentar)
@Autowired
DataBase dataBase;
public void insert(int korisnikId, Komentar komentar) throws Exception
{
komentar.setKorisnikId( korisnikId);
CallableStatement stmt = null;
ResultSet rs = null;
try {
String sql = "{call insertKomentar(?,?,?,?)}";
stmt = dataBase.connection.prepareCall(sql);
stmt.setInt(1, komentar.getKorisnikId());
stmt.setInt(2,komentar.getOglasId());
stmt.setString(3,komentar.getKomentar());
stmt.setInt(4,komentar.getOcena());
stmt.execute();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment