我正在尝试使用内存数据库编写测试。我写了一个 sql 来清理数据并将数据存储到 DB。但我有一个例外:
Caused by: org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character: "e7485042-b46b-11e9-986a-b74e614de0b0"; SQL statement:
insert into users (user_id, name, created_on, modified_on) values ('e7485042-b46b-11e9-986a-b74e614de0b0', 'Ann', null, null) -- ('e7485042-b46b-11e9-986a-b74e614de0b0', 'Ann', NULL, NULL) [90004-199]
Run Code Online (Sandbox Code Playgroud)
我的sql:
insert into users (user_id, name, created_on, modified_on) values ('e7485042-b46b-11e9-986a-b74e614de0b0', 'Ann', null, null);
insert into product(product_id, name, created_on, modified_on) VALUES ('f3a775de-b46b-11e9-95e4-af440b6044e6', 'product1', '2019-08-01 17:51:51.000000', '2019-08-01 17:51:51.000000');
insert into products_users(user_id, product_id) VALUES ('e7485042-b46b-11e9-986a-b74e614de0b0', 'f3a775de-b46b-11e9-95e4-af440b6044e6');
Run Code Online (Sandbox Code Playgroud)
我的 application.properties:
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud) 我正在测试一个 API 并从数据库获取所有数据。我将响应另存为
MvcResult result = mockMvc.perform(..some code..).andReturn();
Run Code Online (Sandbox Code Playgroud)
我收到一个 json 作为响应。我想获取json数组的长度。因此,如果数据库中有 2 行,我想得到 2 行结果。
或者是否有另一种方法来计算数据库中存在的行数。
我现在开始学习Spring Security,但遇到了麻烦。我编写了配置类,从数据库获取数据等,但在我的网页中,我在登录后看到消息“用户帐户已锁定”和 url 中的错误参数。
MessengerApplication.java
@SpringBootApplication
public class MessengerApplication {
public static void main(String[] args) {
SpringApplication.run(MessengerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
MainPageController.java
@RestController
public class MainPageController {
@RequestMapping("/")
public ModelAndView greeting() {
Map<String, Object> model = new HashMap<>();
model.put("data", "world");
return new ModelAndView("main_page", model);
}
}
Run Code Online (Sandbox Code Playgroud)
安全配置.java
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserServiceImpl userService;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider
= new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userService);
authProvider.setPasswordEncoder(encoder());
return …Run Code Online (Sandbox Code Playgroud)