Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SkuciSe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tim 2 - 2022
SkuciSe
Commits
93589288
Commit
93589288
authored
Sep 11, 2022
by
Bogdan Andjelkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oglas procedure bogdan
parent
1f9a64b0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
44 deletions
+17
-44
SkuciSe/src/main/java/com/example/SkuciSe/controller/OglasController.java
+2
-2
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
+15
-42
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/controller/OglasController.java
View file @
93589288
...
...
@@ -71,7 +71,7 @@ public class OglasController
}
model
.
addAttribute
(
"oglasi"
,
listaOglasa
);
List
<
String
>
list
=
new
ArrayList
<
String
>();
for
(
Oglas
o:
oRepo
.
findAll
()
)
{
for
(
Oglas
o:
listaOglasa
)
{
list
.
add
(
kRepo
.
findCity
(
o
.
getLokacijaId
()));
}
model
.
addAttribute
(
"gradovi"
,
list
);
...
...
@@ -114,6 +114,6 @@ public class OglasController
list
.
add
(
kRepo
.
findCity
(
o
.
getLokacijaId
()));
}
model
.
addAttribute
(
"gradovi"
,
list
);
return
"
/
lista-oglasa"
;
return
"lista-oglasa"
;
}
}
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
View file @
93589288
...
...
@@ -59,30 +59,15 @@ public class OglasRepository
}
public
List
<
Oglas
>
findAll
(
)
{
List
<
Oglas
>
list
=
new
ArrayList
<
Oglas
>();
String
sql
=
"select * from oglas"
;
ResultSet
rs
=
null
;
try
{
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
Oglas
oglas
=
new
Oglas
(
rs
.
getInt
(
"oglasId"
),
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"naslov"
),
rs
.
getString
(
"opis"
),
rs
.
getInt
(
"lokacijaId"
),
rs
.
getDouble
(
"cena"
),
rs
.
getInt
(
"vrstaOglasaId"
),
rs
.
getDouble
(
"kvadratura"
),
rs
.
getInt
(
"brojSoba"
),
rs
.
getBoolean
(
"namesten"
),
rs
.
getBoolean
(
"grejanje"
),
rs
.
getBoolean
(
"lift"
),
rs
.
getString
(
"lokacija"
));
list
.
add
(
oglas
);
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
(
list
);
}
public
Oglas
findById
(
int
oglasId
)
{
String
sql
=
"select * from oglas where oglasid = "
+
oglasId
;
String
sql
=
"{ call findOglasbyId(?)}"
;
CallableStatement
stmt
=
null
;
ResultSet
rs
=
null
;
try
{
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
stmt
=
dataBase
.
connection
.
prepareCall
(
sql
);
stmt
.
setInt
(
1
,
oglasId
);
rs
=
stmt
.
executeQuery
();
while
(
rs
.
next
())
{
Oglas
oglas
=
new
Oglas
(
rs
.
getInt
(
"oglasId"
),
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"naslov"
),
rs
.
getString
(
"opis"
),
rs
.
getInt
(
"lokacijaId"
),
rs
.
getDouble
(
"cena"
),
rs
.
getInt
(
"vrstaOglasaId"
),
rs
.
getDouble
(
"kvadratura"
),
rs
.
getInt
(
"brojSoba"
),
rs
.
getBoolean
(
"namesten"
),
rs
.
getBoolean
(
"grejanje"
),
rs
.
getBoolean
(
"lift"
),
rs
.
getString
(
"lokacija"
));
...
...
@@ -94,30 +79,15 @@ public class OglasRepository
return
(
null
);
}
public
List
<
Oglas
>
findAllByKorisnikId
(
int
korisnikId
)
{
List
<
Oglas
>
list
=
new
ArrayList
<
Oglas
>();
String
sql
=
"select * from oglas where korisnikid = "
+
korisnikId
;
ResultSet
rs
=
null
;
try
{
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
while
(
rs
.
next
())
{
Oglas
oglas
=
new
Oglas
(
rs
.
getInt
(
"oglasId"
),
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"naslov"
),
rs
.
getString
(
"opis"
),
rs
.
getInt
(
"lokacijaId"
),
rs
.
getDouble
(
"cena"
),
rs
.
getInt
(
"vrstaOglasaId"
),
rs
.
getDouble
(
"kvadratura"
),
rs
.
getInt
(
"brojSoba"
),
rs
.
getBoolean
(
"namesten"
),
rs
.
getBoolean
(
"grejanje"
),
rs
.
getBoolean
(
"lift"
),
rs
.
getString
(
"lokacija"
));
list
.
add
(
oglas
);
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
(
list
);
}
public
void
deleteOglasi
(
Integer
id
)
{
String
sql
=
"select * from oglas where korisnikid = "
+
id
;
String
sql
=
"{call findAllByKorisnikId(?)}"
;
CallableStatement
stmt
=
null
;
ResultSet
rs
=
null
;
try
{
rs
=
dataBase
.
statement
.
executeQuery
(
sql
);
stmt
=
dataBase
.
connection
.
prepareCall
(
sql
);
stmt
.
setInt
(
1
,
id
);
rs
=
stmt
.
executeQuery
();
while
(
rs
.
next
())
{
int
oglasid
=
rs
.
getInt
(
"oglasid"
);
...
...
@@ -127,9 +97,12 @@ public class OglasRepository
throw
new
RuntimeException
(
e
);
}
sql
=
"delete from oglas where KorisnikId = "
+
id
;
sql
=
"{call deleteOglasiByKorisnikId(?)}"
;
CallableStatement
stmt1
=
null
;
try
{
dataBase
.
statement
.
execute
(
sql
);
stmt1
=
dataBase
.
connection
.
prepareCall
(
sql
);
stmt1
.
setInt
(
1
,
id
);
stmt1
.
execute
();
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment