Critere de recherche
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import fr.eni.enchere.controllers.AccueilController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@@ -51,6 +53,24 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> searchArticle(SearchArticleCritere critere) {
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM ARTICLES_VENDUS WHERE 1 = 1");
|
||||
|
||||
List<Object> params = new ArrayList<>();
|
||||
|
||||
if (critere.getNoCategorie() != null) {
|
||||
sql.append(" AND no_categorie = ?");
|
||||
params.add(critere.getNoCategorie());
|
||||
}
|
||||
if (critere.getTitle() != null && !critere.getTitle().isEmpty()) {
|
||||
sql.append(" AND nom_article LIKE ?");
|
||||
params.add( '%' + critere.getTitle() + "%");
|
||||
}
|
||||
|
||||
return jdbcTemplate.query(sql.toString(), new ArticleRowMapper(), params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Article findArticleById(int id) {
|
||||
return null;
|
||||
@@ -58,8 +78,8 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
|
||||
@Override
|
||||
public List<Article> findArticleByTitle(String title) {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE '?'";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), title);
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE ?";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), "%" + title + "%");
|
||||
return articles;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user