New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mybatis对于使用了 useGeneratedKeys="true" keyProperty="id"属性的insert sql无法mock。 #14
Comments
该问题是"及时序列化"引入的问题;为了保证能够录制到原始的入参和返回值,避免被后续流程篡改导致的回放问题; 对于这种问题;可以自己实现MockInterceptor来适配,把response或者特定的参数填充到请求中 |
如果通过MockInterceptor来实现,怎么样能够获取到这个特定参数呢? <insert id="insertProject" parameterType="com.xx.xx" useGeneratedKeys="true" keyProperty="id"> |
对于mybatis这种情况,如果MockInterceptor不能解决; 可以给插件新增一个能力,选择序列化时机,比如:默认在before事件序列化,mybatis这种可以选择在return进行序列化,就能解掉这个问题 |
但是采取这个 方式的话,在ParameterMatchMockStrategy中就会因为参数与入参不匹配而导致回放失败了呀。 |
回归版本:755806a |
yeap... 拦截器的代码没写,现在找到不到子调用的是预期内的; 因为录制的时候有ID,回放的时候没有 |
问题描述
useGeneratedKeys 取值范围true、false 默认值是:false。 含义:设置是否使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中
keyProperty 取id的key值
使用了这类两个属性的insert sql会对传入的对象进行修改,将插入完成后的id设回给传入的参数。
然后调用了这个方法后,大家可以直接拿执行插入操作的对象中的id进行后面的操作。
如:
由于录制时只关注mybatis的execute方法的入参和返回,没有关注传入参数的改变,导致在上面代码的场景中会出现回放失败的情况。
The text was updated successfully, but these errors were encountered: