在模糊查询时的500错误,java.lang.reflect.InvocationTargetException

作者在开发客户信息管理系统时遇到SQL语法错误,经过3小时排查,发现是由于忘记添加空格导致的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在写客户信息管理系统时报出了这个错误在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
就一个模糊查询,错误的位置是Dao包,运行时不报错。
debug后,更蒙了…
说sql语法有问题,就这几行啊。。
在这里插入图片描述
一脸楞逼。。。
3小时后。。。

在这里插入图片描述
忘了个空格。。。
在这里插入图片描述

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'appController' method com.kucun.controller.AppController#getAddEntity(String, Map) to { /app/add/{e}}: There is already 'appController' bean method com.kucun.controller.AppController#getAllDataWithChildIds(String) mapped. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.15.RELEASE.jar:5.2.15.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.15.RELEASE.jar:package com.kucun.controller; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.fasterxml.jackson.databind.ObjectMapper; import com.kucun.Service.AppService; import com.kucun.data.entity.*; import com.kucun.dataDo.*; @RestController @RequestMapping("/app") public class AppController { // 实体类型映射,将路径变量映射到具体的实体类 private static final Map<String, Class<?>> ENTITY_MAP = new HashMap<>(); static { ENTITY_MAP.put("user", User.class); // /entity/add/user 对应 User 类 ENTITY_MAP.put("banci", Bancai.class); // /entity/add/product 对应 Product 类 ENTITY_MAP.put("caizi", Caizhi.class); ENTITY_MAP.put("mupi", Mupi.class); ENTITY_MAP.put("dingdan", Dingdan.class); ENTITY_MAP.put("zujian", Zujian.class); ENTITY_MAP.put("chanpin", Chanpin.class); ENTITY_MAP.put("dingdan_chanpin", Dingdan_chanpin.class); ENTITY_MAP.put("dingdan_chanpin_zujian", Dingdan_chanpin_zujian.class); ENTITY_MAP.put("chnapin_zujian", Chanpin_zujian.class); ENTITY_MAP.put("jinhuo", Jinhuo.class); ENTITY_MAP.put("kucun", Kucun.class); //ENTITY_MAP.put("order", Caizhi.class); // /entity/add/order 对应 Order 类 // 添加更多实体映射... } @Autowired private ObjectMapper objectMapper; // Jackson JSON处理器 @Autowired public AppService appService; /** * 使用Jackson将Map转换为指定类型的实体对象 * @param dataMap 包含数据的Map * @param targetType 目标实体类 * @return 转换后的实体对象 */ private Object convertMapToEntity(Map<String, Object> dataMap, Class<?> targetType) { return objectMapper.convertValue(dataMap, targetType); } /** *1输出所有实体类 * @return */ @RequestMapping("/all") public Information getAllDataWithChildIds() { return appService.getAllDataWithChildIdse(); } @RequestMapping("/all/{e}") public Information getAllDataWithChildIds(@PathVariable String e) { return appService.getAllDataWithChildIdse(e); } @RequestMapping("/add/{e}") public Information getAddEntity( @PathVariable String e, @RequestBody Map<String, Object> requestBody) { // 1. 根据路径变量获取实体类 Class<?> entityClass = ENTITY_MAP.get(e.toLowerCase()); if (entityClass == null) { return Information.NewFail("不支持的类型: " + e); } try { // 2. 动态转换JSON为实体对象 Object entity = convertMapToEntity(requestBody, entityClass); // 4. 保存实体 return appService.getAddEntity(entity); } catch (Exception ex) { return Information.NewFail("创建失败: " + ex.getMessage()); } } @RequestMapping("/select/{e}") public Information getseletDataWithChildIds(@PathVariable String e, @RequestBody Map<String, Object> requestBody) { // 1. 根据路径变量获取实体类 Class<?> entityClass = ENTITY_MAP.get(e.toLowerCase()); if (entityClass == null) { return Information.NewFail("不支持的类型: " + e); } try { // 2. 动态转换JSON为实体对象 Object entity = convertMapToEntity(requestBody, entityClass); // 4. 保存实体 return appService.getSELECTEntity(entity); } catch (Exception ex) { return Information.NewFail("查询失败: " + ex.getMessage()); } } @RequestMapping("/delete/{e}") public Information getdeleteDataWithChildIds(@PathVariable String e, @RequestBody Map<String, Object> requestBody) { // 1. 根据路径变量获取实体类 Class<?> entityClass = ENTITY_MAP.get(e.toLowerCase()); if (entityClass == null) { return Information.NewFail("不支持的类型: " + e); } try { // 2. 动态转换JSON为实体对象 Object entity = convertMapToEntity(requestBody, entityClass); // 4. 保存实体 return appService.getSELECTEntity(entity); } catch (Exception ex) { return Information.NewFail("查询失败: " + ex.getMessage()); } } @RequestMapping("/update/{e}") public Information updateDataWithChildIds(@PathVariable String e, @RequestBody Map<String, Object> requestBody) { // 1. 根据路径变量获取实体类 Class<?> entityClass = ENTITY_MAP.get(e.toLowerCase()); if (entityClass == null) { return Information.NewFail("不支持的类型: " + e); } try { // 2. 动态转换JSON为实体对象 Object entity = convertMapToEntity(requestBody, entityClass); // 4. 保存实体 return appService.getupdateEntity(entity); } catch (Exception ex) { return Information.NewFail("查询失败: " + ex.getMessage()); } } }
最新发布
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王子健121

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值