Oi pessoal!
Fiz uma ferramenta de pesquisa com Criteria, mas só dá resultados colocando o valor mínimo e máximo em conjunto com outro campo para pesquisa, se pesquisar imóvel por bairro, cidade ou estado sem digitar os valores, não retorna nada.
Tentei assim:
public List<Imovel> busca(String bairro, String cidade, String estado, BigDecimal valorMin, BigDecimal valorMax) {
return session.createCriteria(Imovel.class)
.add(Restrictions.ilike("bairro", "%"+bairro+"%"))
.add(Restrictions.ilike("cidade", "%"+cidade+"%"))
.add(Restrictions.ilike("estado", "%"+estado+"%"))
.add(Restrictions.between("valor", valorMin, valorMax))
.list();
}
E assim:
public List<Imovel> busca(String bairro, String cidade, String estado, BigDecimal valorMin, BigDecimal valorMax) {
return session.createCriteria(Imovel.class)
.add(Restrictions.ilike("bairro", bairro, MatchMode.ANYWHERE))
.add(Restrictions.ilike("cidade", cidade, MatchMode.ANYWHERE))
.add(Restrictions.ilike("estado", estado, MatchMode.ANYWHERE))
.add(Restrictions.between("valor", valorMin, valorMax))
.list();
}
Esta é a stacktrace:
17:34:18,088 DEBUG [OgnlParametersProvider] Applying bairro with [tijuca]
17:34:18,088 DEBUG [OgnlParametersProvider] Applying cidade with []
17:34:18,089 DEBUG [OgnlParametersProvider] Applying estado with []
17:34:18,089 DEBUG [OgnlParametersProvider] Applying valorMax with []
17:34:18,090 DEBUG [OgnlParametersProvider] Applying valorMin with []
17:34:18,091 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for IndexController.busca(String, String, String, BigDecimal, BigDecimal) as [bairro, cidade, estado, valorMin, valorMax]
17:34:18,091 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: IndexController.buscaIndexController.busca(String, String, String, BigDecimal, BigDecimal)] are [tijuca, , , null, null]
17:34:18,103 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
17:34:18,104 DEBUG [ExecuteMethodInterceptor] Invoking IndexController.busca(String, String, String, BigDecimal, BigDecimal)
Hibernate:
select
this_.id_imovel as id1_11_0_,
this_.area as area11_0_,
this_.bairro as bairro11_0_,
this_.categoria as categoria11_0_,
this_.cep as cep11_0_,
this_.cidade as cidade11_0_,
this_.cod_imovel as cod7_11_0_,
this_.descricao as descricao11_0_,
this_.dt_inclusao as dt9_11_0_,
this_.endereco as endereco11_0_,
this_.estado as estado11_0_,
this_.medida as medida11_0_,
this_.pais as pais11_0_,
this_.status as status11_0_,
this_.titulo as titulo11_0_,
this_.valor as valor11_0_
from
Imovel this_
where
this_.bairro ilike ?
and this_.cidade ilike ?
and this_.estado ilike ?
and this_.valor between ? and ?
17:34:18,111 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor OutjectResult
17:34:18,111 DEBUG [OutjectResult ] outjecting imovelList=[]
17:34:18,115 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
17:34:18,115 DEBUG [ForwardToDefaultViewInterceptor] forwarding to the dafault page for this logic
17:34:18,121 DEBUG [DefaultPageResult ] forwarding to /WEB-INF/jsp/index/busca.jsp
17:34:18,121 DEBUG [DefaultStaticContentHandler] Deferring request to container: /imobiliaria/WEB-INF/jsp/index/busca.jsp
17:34:18,125 DEBUG [VRaptor ] VRaptor ended the request
17:34:18,207 DEBUG [VRaptor ] VRaptor received a new request
17:34:18,216 DEBUG [DefaultRequestExecution] executing stack DefaultRequestExecution
17:34:18,259 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
17:34:18,260 DEBUG [DefaultResourceTranslator] trying to access /imagens/aplication/menu_div.jpg
17:34:18,260 DEBUG [VRaptor ] VRaptor ended the request
Alguém sabe como poderia preencher apenas um dos campos e obter resultados?
Abraço!