我有一个关于XPath != 和not()XP 之间的区别的问题.
例如,这是我的XML数据库:
<Books>
<Book title="one">
book1
</Book >
<Book title="one">
book2
</Book >
<Book >
book3
</Book >
</Books>
Run Code Online (Sandbox Code Playgroud)
这两个XPath查询之间的区别是什么:
//book[@title!='one']//book[not(@title)]所以,如果我问:我从第一个请求获得了多少书,以及我将从第二个请求获得多少书.
在上面带有2个请求的示例中,我是否会获得最后一本书"book3"元素?
谢谢.
我仍在深入学习spring依赖注入。
我的第一个类是配置类,在这里我向容器声明以加载和管理在带注释的方法中声明的bean。
package ioc.question_004;
import ioc.commun.Person;
import ioc.commun.Profession;
import org.springframework.context.annotation.*;
@Configuration
public class MyConfiguration {
@Bean
public Profession profession(){
return Profession.builder()
.name("professor")
.description("professor in the university")
.build();
}
@Bean
public Person person(){
return Person.builder()
.name("Bagna")
.age(52)
.profession(profession())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我的第二个类是daoRepository,它看起来像:
package ioc.question_008.dao;
import ioc.commun.Person;
import lombok.*;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
@Builder
@Setter
@Getter
@EqualsAndHashCode
@ToString
public class MyDaoRepository implements dao {
List<Person> personList = new ArrayList<>();
@Override
public boolean save( Person person ){
return this.personList.add(person);
} …Run Code Online (Sandbox Code Playgroud) 我的用户实体
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String username;
@Column(nullable = false)
private String password;
@ElementCollection
private List<String> roles = new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
每个用户可以有多个角色。给定一个角色(以字符串数据类型表示),我想获取具有该角色的所有用户。
例如
用户 1 的角色:“admin”
User2 角色:“user”
User3 角色:“admin”
对于角色“admin”,我想得到 User1 和 User2 的结果。
我对 Spring Data Jpa 的尝试:
public interface UserRepository extends JpaRepository<User, Integer> {
public List<User> findByRoles( String role);
}
Run Code Online (Sandbox Code Playgroud)
但我得到了例外
org.hibernate.LazyInitializationException:无法延迟初始化角色集合:com.spring.certificatie.securityconfig.User.roles,无法初始化代理 - 无会话
我正在尝试学习如何(使用)C程序中的指针; 我的例子如下:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int * tab = (int*)malloc(sizeof(int)*5);
int a =10;
int *p;
p = &a;
printf("the adress of a is%d \n",&a);
printf("the adress of a using the pointer is%p \n",p);
printf("the adress of tab is%d \n",tab);
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试打印地址a,开头p的第一个字节的地址和位置tab.
我在使用时可以获得十六进制值"%p",但我愿意使用地址的十进制值.
我正在学习Java中的异常,我在这个例子中遇到了编译错误:
public class FinallyExceptionExample {
public static void main (String[] args) throws Exception {
try {
System.out.println("1");
throw new Exception();
} finally{
System.out.println("3");
}
System.out.println("4");
}
}
Run Code Online (Sandbox Code Playgroud)
该行的例外情况是"无法访问的声明":
System.out.println("4");
Run Code Online (Sandbox Code Playgroud)
我想知道为什么我得到这个错误,通常在我们最后继续执行代码之后?
我正在尝试与 Spring 应用程序上下文隔离来测试我的控制器。
这是我的控制器
@RestController
public class AddressesController {
@Autowired
service service;
@GetMapping("/addresses/{id}")
public Address getAddress( @PathVariable Integer id ) {
return service.getAddressById(id);
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务界面
public interface service {
Address getAddressById(Integer id);
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试课
@ExtendWith(SpringExtension.class)
@WebMvcTest
public class AddressControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
service myService;
@Test
public void getAddressTest() throws Exception {
Mockito.doReturn(new Address()).when(myService).getAddressById(1);
mockMvc.perform(MockMvcRequestBuilders.get("/addresses/1"))
.andExpect(status().isOk());
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的异常:
org.mockito.exceptions.misusing.NullInsteadOfMockException:传递给when()的参数为空!正确存根的示例: doThrow(new RuntimeException()).when(mock).someMethod(); 另外,如果你使用 @Mock 注解,不要错过 initMocks()
就像服务从未被创建一样。我该如何解决这个问题?
@RunWith(SpringRunner.class)我们可以通过使用代替来解决这个问题@ExtendWith(SpringExtension.class)。有人可以解释为什么它有效吗?通常第一个注释适用于 junit4,第二个注释适用于 junit5。