1.一开始的数据库表信息已经创建完毕
数据库用的是Mysql 工具是navicat for mysql 12
2.springboot的项目创建
回顾了一下 有三种创建方法
1.直接idea创建 spring initial项目
2.去spring.io 官网 选择对应的包 和环境 把整个项目包下载下来 再用编译器打开
3.创建maven 项目 再去maven中央仓库去搜索对应的jar包导入Pom就可以了
—待补充。。
降级后出现的问题 :
从spring2.2.5降级到1.1.7
在Test环境下需要增加注解@RunWith(SpringRunner.class)
我只写了个Mapper接口 然后@Autowired 无法找到Bean 加上@RunWith(SpringRunner.class) 就OK了
数据库也成功连上 输出了数据
- 数据库的数据和POJO里的属性对不上怎么办?
发现了问题select * from mall_category
返回的结果中 有好几个为Null的
1.查找问题发生的所在 第一点就是判断Pojo里的属性有没有写对
从navicat中查找 发现了不一样的地方
数据库的字段是有下划线的 Pojo里没有 Java的规范就是驼峰命名法 不能改pojo里的名字
经过一番查找
在yml配置文件中
mybatis:
configuration:
map-underscore-to-camel-case: true
输入这段配置 就可以解决这个问题
- xml在properties中的配置问题
mybatis:
configuration:
map-underscore-to-camel-case: true
mapper-locations: classpath:mapper/*.xml
mapper-locations: classpath:mapper/*.xml
这段代码是让XML文件可以被读取到 尽量使用xml开发
- 报错 在配置完支付密钥后准备测试出现的错误
- java.lang.RuntimeException: 【微信统一支付】发起支付, returnCode != SUCCESS, returnMsg = 签名错误
- 当出现签名错误 可能是 商户ID错误 商户密钥错误 要逐一排查
- 如果日志报错出现不匹配 或者 appid不存在
- 那么对应的公众号ID错误
-[main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@74fe5c40] to prepare test instance [com.l.pay.service.Impl.PayServiceTest@4ca8dbfa]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.l.pay.service.Impl.PayServiceTest': Unsatisfied dependency expressed through field 'payService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.l.pay.service.Impl.PayService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
看报错是bean注册有问题 检查了一遍 发现PayService没有加@Service注解 加上去就解决了
运行又报错
org.simpleframework.xml.core.ElementException: Value for @org.simpleframework.xml.Element(name=notify_url, type=void, data=false, required=true) on field 'notifyUrl' private java.lang.String com.lly835.bestpay.model.wxpay.request.WxPayUnifiedorderRequest.notifyUrl is null in class com.lly835.bestpay.model.wxpay.request.WxPayUnifiedorderRequest
注意到notifyUrl is null
notifyUrl 是什么呢 答 :是接收平台异步通知的地址 按下面的配置先填写 即可
测试完成
- 在对插入功能测试的时候
[http-nio-8080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.l.pay.dao.PayInfoMapper.insertSelective] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.l.pay.dao.PayInfoMapper.insertSelective
报了个非法绑定的错误 我仔细检查了xml的 namespace
是正常的 也没有报错 以及路径名称 突然想起 支付和商城是分开的两个项目
这个支付项目中 application.yml没有配置mybatis
只连接了数据库 和 日志
马上配上:
mybatis:
configuration:
map-underscore-to-camel-case: true
mapper-locations: classpath:/mappers/*.xml
果然成功了
查看数据库
成功插入一条订单数据 二维码显示正常
- 今天在写前端Ajax时遇到的一个小问题 但是也值得记录
我要做的是 前端向后端发送一串订单号字符串(String) 出于精度考虑,转换为LONG类型 用到了
LONG.parselong()
将前端的字符串转为long再去数据库中索引对应的订单信息
然后返回一个 名为PAY的对象 给前端 让前端log出来 看看是否能正确把用户信息对象打出来
这个方法 可是前端却报错了 IDEA控制台也报错`java.lang.NumberFormatException: For input string ‘’
问题出在div id的命名多了个空格导致 dom无法找到对应的id中的值
才会为NULL
String类型的参数 通过pareType()这类方法的转换 都会留下一个空格在末尾
所以一开始都应该去掉
Long.parseLong(orderId.trim())
完美解决!