我有将JSON传递给RestController的问题.它似乎没有消耗它.
控制器:
@PostMapping(path = "Users/{UserId}/Transactions",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public CompletableFuture<ResponseEntity<?>> startGameRound(@RequestBody TransactionRequest request,
@RequestParam("PartnerUserSessionKey") String sessionId,
@PathVariable("UserId") String playerUUID) throws ExecutionException, InterruptedException { // Logic }
Run Code Online (Sandbox Code Playgroud)
TransactionRequest 对象模型:
public class TransactionRequest {
@JsonProperty("TransactionType")
private TransactionType transactionType;
@JsonProperty("TransactionId")
private String transactionId;
@JsonProperty("TransactionCreationDate")
private LocalDateTime transactionCreationDate;
@JsonProperty("Amount")
private Long amount;
@JsonProperty("Rake")
private BigDecimal rake;
@JsonProperty("CurrencyCode")
private String currencyCode;
@JsonProperty("EntityReferences")
private List<EntityReference> entityReferences;
@JsonProperty("Game")
private Game game;
public TransactionRequest() {
}
//getters & setters & hashEquals & toString
}
Run Code Online (Sandbox Code Playgroud)
这是试图发布到控制器的 …
我在将整数数组插入 Postgresql 表时遇到问题,我该如何解决?
String sql = "INSERT INTO draw_result (id, ball_numbers, balls_with_mega_ball, draw_dates, mega_plier) VALUES(?, ?, ?, ?, ?)";
Object[] params = {randomNumbers, ballNumbers, ballNumbersMegaBall, drawDates, megaPlier};
jdbcTemplate.update(sql, params);
Run Code Online (Sandbox Code Playgroud)
其中 ballNumbers 和 ballNumbersMegaBall 是 ArrayList。填充2位数字。
这是 PostgreSQL 表:
CREATE TABLE public.draw_result
(
id bigint NOT NULL,
draw_dates date,
ball_numbers bigint[],
balls_with_mega_ball bigint[],
mega_plier bigint,
CONSTRAINT draw_result_pkey PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)
这是来自 Springboot 的错误:
出现意外错误(类型=内部服务器错误,状态=500)。PreparedStatementCallback; 错误的 SQL 语法 [INSERT INTO draw_result (id, >ball_numbers, balls_with_mega_ball, draw_dates, mega_plier) VALUES(?, ?, ?, ?, >?)]; …
我需要正确地遵循SQL脚本语法.在postgres中,你不能真正将"alter sequence"与"select max(id)"链接起来.那么以PostgreSQL接受它的方式编写脚本的正确方法是什么?
这是脚本,所以你可以知道我需要什么:
alter SEQUENCE notification_settings_seq START with (select max(id) from game_user)
Run Code Online (Sandbox Code Playgroud) 我想将合适的对象传入验证方法,而不仅仅是 any()。
有没有办法做到这一点?
我不能只是采用和复制 Lambda 方法并将结果传递给验证。这不起作用,因为无法直接测试 Lambda。
我的单元测试显然还没有接近测试任何东西:
@Test
public void testRunTrigger() {
campaignTrigger.updateCampaignStatus();
verify(jdbcTemplate).update(any(PreparedStatementCreator.class));
assertEquals("UPDATE campaign SET state = 'FINISHED' WHERE state IN ('PAUSED','CREATED','RUNNING') AND campaign_end < ? ", campaignTrigger.UPDATE_CAMPAIGN_SQL);
}
Run Code Online (Sandbox Code Playgroud)
这是我正在测试的课程:
@Component
@Slf4j
public class CampaignTrigger {
final String UPDATE_CAMPAIGN_SQL = String.format("UPDATE campaign SET state = '%s' " +
" WHERE state IN (%s) AND campaign_end < ? ", FINISHED,
Stream.of(PAUSED, CREATED, RUNNING)
.map(CampaignState::name)
.collect(Collectors.joining("','", "'", "'")));
@Autowired
private JdbcTemplate jdbcTemplate;
@Scheduled(cron = "${lotto.triggers.campaign}")
@Timed
void updateCampaignStatus() { …Run Code Online (Sandbox Code Playgroud) java ×3
postgresql ×2
spring ×2
jdbc ×1
json ×1
junit ×1
mocking ×1
mockito ×1
rest ×1
spring-boot ×1
spring-mvc ×1
sql ×1
unit-testing ×1