我尝试从包含3个字段和类似谓词的表单执行搜索,并且y成为此错误:"请求处理失败;嵌套异常是java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0"。
这将是我的控制者:
package cl.cbrtemuco.autoconsultas.controller;
import java.util.List;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import cl.cbrtemuco.autoconsultas.entity.Titulos;
import cl.cbrtemuco.autoconsultas.service.TitulosService;
@Controller
@RequestMapping("/autoconsultas")
public class TitulosController {
@Autowired
private TitulosService titulosService;
private Logger logger = Logger.getLogger(getClass());
@GetMapping("/busqueda")
public String buscarTitulos(Model theModel) {
return "busqueda";
}
@GetMapping("/buscarTituloPorRsoc")
public String buscarTituloPorRsoc(@RequestParam("razonSocial") String rSocial,
Model theModel) {
List<Titulos> elTitulo = titulosService.searchTitulosByRazonSocial(rSocial);
theModel.addAttribute("titulosPorRazonSocial", elTitulo);
return "titulosPorRsoc";
}
@GetMapping("/tituloDetallesPorRSoc")
public String tituloDetallesRSoc(@RequestParam("titulosId") int idTit, Model theModel) {
//logger.info("showing form for update");
Titulos elTitulo = titulosService.getTituloRSoc(idTit);
theModel.addAttribute("titulo", elTitulo);
return "detallesTituloPorRSoc";
}
@GetMapping("/buscarTituloPorNombre")
public String buscarTituloPorNombre(@RequestParam("apellidoPaterno") String apPaterno,
@RequestParam("apellidoMaterno") String apMaterno,
@RequestParam("nombres") String nombres, Model theModel) {
List<Titulos> elTitulo = titulosService.searchTitulosByNombre(apPaterno, apMaterno, nombres);
theModel.addAttribute("titulosPorNombre", elTitulo);
return "titulosPorNombre";
}
@GetMapping("/tituloDetallesPorNombre")
public String tituloDetallesNombre(@RequestParam("titulosId") int idTit, Model theModel) {
//logger.info("showing form for update");
Titulos elTitulo = titulosService.getTituloNombre(idTit);
theModel.addAttribute("titulo", elTitulo);
return "detallesTituloPorNombre";
}
}
这将成为我的服务:
package cl.cbrtemuco.autoconsultas.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cl.cbrtemuco.autoconsultas.dao.TitulosDAO;
import cl.cbrtemuco.autoconsultas.entity.Titulos;
@Service
public class TitulosServiceImpl implements TitulosService {
@Autowired
private TitulosDAO titulosDAO;
@Override
@Transactional
public List<Titulos> searchTitulosByRazonSocial(String rSocial) {
return titulosDAO.searchTitulosByRazonSocial(rSocial);
}
@Override
@Transactional
public Titulos getTituloRSoc(int idTit) {
return titulosDAO.getTituloRSoc(idTit);
}
@Override
@Transactional
public List<Titulos> searchTitulosByNombre(String apPaterno, String apMaterno, String nombres) {
return titulosDAO.searchTitulosByNombre(apPaterno, apMaterno, nombres);
}
@Override
@Transactional
public Titulos getTituloNombre(int idTit) {
return titulosDAO.getTituloNombre(idTit);
}
}
最后这是我的DAO,我认为这是错误:
package cl.cbrtemuco.autoconsultas.dao;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import cl.cbrtemuco.autoconsultas.entity.Titulos;
@Repository
public class TitulosDAOImpl implements TitulosDAO {
@Autowired
SessionFactory sessionFactory;
@Override
public List<Titulos> searchTitulosByRazonSocial(String rSocial) {
Session currentSession = sessionFactory.getCurrentSession();
Query<Titulos> theQuery = currentSession.createQuery("from Titulos where RazonSocial like :rSocial",
Titulos.class);
theQuery.setParameter("rSocial", "%" + rSocial.toLowerCase() + "%");
List<Titulos> titulosEncontrados = theQuery.getResultList();
return titulosEncontrados;
}
@Override
public Titulos getTituloRSoc(int idTit) {
Session currentSession = sessionFactory.getCurrentSession();
Titulos datTituloRSoc = currentSession.get(Titulos.class, idTit);
return datTituloRSoc;
}
@Override
public Titulos getTituloNombre(int idTit) {
Session currentSession = sessionFactory.getCurrentSession();
Titulos datTituloNombre = currentSession.get(Titulos.class, idTit);
return datTituloNombre;
}
@Override
public List<Titulos> searchTitulosByNombre(String apPaterno, String apMaterno, String nombres) {
Session currentSession = sessionFactory.getCurrentSession();
Query<Titulos> theQuery = currentSession.createQuery(
"from Titulos where ApellidoPaterno like :apPaterno or ApellidoMaterno like :apMaterno or Nombres like :nombres", Titulos.class);
theQuery.setParameter("apPaterno", "%"+apPaterno.toLowerCase()+"%")
.setParameter("apMaterno", "%"+apMaterno.toLowerCase()+"%")
.setParameter("nombres", "%"+nombres.toLowerCase()+"%");
List<Titulos> titulosEncontradosNombre = theQuery.getResultList();
return titulosEncontradosNombre;
}
}
最后这里是stacktrace:
Hibernate: select titulos0_.idTitulos as idTitulo1_0_, titulos0_.AnoCancelacion as AnoCance2_0_, titulos0_.AnoTitulo as AnoTitul3_0_, titulos0_.ApellidoMaterno as Apellido4_0_, titulos0_.ApellidoPaterno as Apellido5_0_, titulos0_.CorrelativoTitulo as Correlat6_0_, titulos0_.FojasCancelacion as FojasCan7_0_, titulos0_.FojasTitulo as FojasTit8_0_, titulos0_.Nombres as Nombres9_0_, titulos0_.NumeroCancelacion as NumeroC10_0_, titulos0_.NumeroTitulo as NumeroT11_0_, titulos0_.RazonSocial as RazonSo12_0_, titulos0_.TipoRegistro as TipoReg13_0_, titulos0_.UbicacionPropiedad1 as Ubicaci14_0_, titulos0_.VueltaCancelacion as VueltaC15_0_, titulos0_.VueltaTitulo as VueltaT16_0_ from Titulos titulos0_ where ApellidoPaterno like ? or ApellidoMaterno like ? or Nombres like ?
feb 06, 2017 8:19:41 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: El Servlet.service() para el servlet [dispatcher] en el contexto con ruta [/AutoConsultas] lanzó la excepción [Request processing failed; nested exception is java.lang.StringIndexOutOfBoundsException: String index out of range: 0] con causa raíz
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:61)
at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:16)
at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$2.doExtract(VarcharTypeDescriptor.java:62)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:258)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:244)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:327)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2775)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1741)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1667)
at org.hibernate.loader.Loader.getRow(Loader.java:1556)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:740)
at org.hibernate.loader.Loader.processResultSet(Loader.java:985)
at org.hibernate.loader.Loader.doQuery(Loader.java:943)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
at org.hibernate.loader.Loader.doList(Loader.java:2615)
at org.hibernate.loader.Loader.doList(Loader.java:2598)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430)
at org.hibernate.loader.Loader.list(Loader.java:2425)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1458)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1426)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1398)
at org.hibernate.Query.getResultList(Query.java:417)
at cl.cbrtemuco.autoconsultas.dao.TitulosDAOImpl.searchTitulosByNombre(TitulosDAOImpl.java:51)
at cl.cbrtemuco.autoconsultas.service.TitulosServiceImpl.searchTitulosByNombre(TitulosServiceImpl.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy26.searchTitulosByNombre(Unknown Source)
at cl.cbrtemuco.autoconsultas.controller.TitulosController.buscarTituloPorNombre(TitulosController.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
最后我的jsp文件:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<title>Lista</title>
<link type="text/css" rel="stylesheet"
href="${pageContext.request.contextPath}/resources/css/style.css">
</head>
<body>
<div id="wrapper">
<div id="header">
<h2>Búsqueda de Títulos de dominio</h2>
</div>
</div>
<div id="container">
<div id="content">
<form action="buscarTituloPorNombre">
<table>
<td>
<th>Búsqueda por Nombre:</th>
</td>
<td>
<tr>
<input type="textbox" name="apellidoPaterno" />
</tr>
<tr>
<input type="textbox" name="apellidoMaterno" />
</tr>
<tr>
<input type="textbox" name="nombres" />
</tr>
<tr>
<input type="submit" value="Buscar" class="add-button" />
</tr>
</td>
</table>
</form>
<form action="buscarTituloPorRsoc">
<table>
<td>
<th>Búsqueda por Razón Social:</th>
</td>
<td>
<tr>
<input type="textbox" name="razonSocial" />
</tr>
<tr>
<input type="submit" value="Buscar" class="add-button" />
</tr>
</td>
</table>
</form>
</div>
</div>
</body>
</html>
提前致谢,请有最诚挚的问候。
费尔南多
答案 0 :(得分:0)
听起来你的三个参数都是空字符串。你也可以粘贴你的jsp吗?