Skip to content

Commit

Permalink
fix: #127
Browse files Browse the repository at this point in the history
  • Loading branch information
yulichang committed May 24, 2024
1 parent cace18d commit 5a29504
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public UpdateJoinWrapper(T entity, Class<T> entityClass, AtomicInteger paramName
@SuppressWarnings("DuplicatedCode")
private void getSqlByEntity(StringBuilder sb, boolean filterNull, List<Object> entityList) {
for (Object obj : entityList) {
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%>", obj.getClass().getSimpleName());
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%s>", obj.getClass().getSimpleName());
TableInfo tableInfo = TableHelper.getAssert(obj.getClass());
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
Expand All @@ -266,7 +266,7 @@ private void getSqlByEntity(StringBuilder sb, boolean filterNull, List<Object> e
continue;
}
sb.append(tableList.getPrefixByClass(obj.getClass())).append(Constants.DOT)
.append(fieldInfo.getColumn()).append(Constants.EQUALS).append(formatParam(null, val))
.append(fieldInfo.getColumn()).append(Constants.EQUALS).append(formatParam(fieldInfo.getMapping(), val))
.append(StringPool.COMMA);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.github.yulichang.test.join.m;

import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
import com.github.yulichang.test.join.entity.AddressDO;
import com.github.yulichang.test.join.entity.UserDO;
import com.github.yulichang.test.join.mapper.UserMapper;
import com.github.yulichang.test.util.Reset;
import com.github.yulichang.test.util.ThreadLocalUtils;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.UpdateJoinWrapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.BadSqlGrammarException;

import java.util.HashMap;
import java.util.List;

@SpringBootTest
public class UpdateIncTest {

@Autowired
private UserMapper userMapper;

@BeforeEach
void setUp() {
Reset.reset();
Expand Down Expand Up @@ -44,4 +55,28 @@ void updateInc1() {
JoinWrappers.lambda(UserDO.class).list().forEach(System.out::println);
}

@Test
void updateInc2() {
HashMap<String, String> map = new HashMap<>();
map.put("aaa", "bbb");

UserDO userDO = new UserDO();
userDO.setJson(map);

InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());

UpdateJoinWrapper<UserDO> wrapper = JoinWrappers.update(UserDO.class)
.setUpdateEntity(userDO);

userMapper.updateJoin(null, wrapper);

InterceptorIgnoreHelper.clearIgnoreStrategy();

List<UserDO> list = JoinWrappers.lambda(UserDO.class).list();
list.forEach(System.out::println);
list.forEach(c -> {
assert c.getJson().get("aaa").equals("bbb");
});
}

}

0 comments on commit 5a29504

Please sign in to comment.