我已经在我的项目中使用Spring Data JPA存储库一段时间了,我知道以下几点:
findByCustomerNameAndPhone()(假设customerName和phone是域对象中的字段).我感兴趣的是如何对它进行编码,我已经查看了Spring JPA源代码和API,但我找不到以下问题的答案:
您能否帮助解决上述问题并提供任何支持的文档?
我正在使用Spring API JmsTemplate和MappingJackson2MessageConverter(version spring-jms-4.3.4.RELEASE.jar:)将消息发布到ActiveMQ主题,如下面的代码所示.
TopicPublisher类:
@Component
public class TopicPublisher {
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private MessageConverter messageConverter;
public void send() {
Product product = new Product();
product.setName("abcd");
product.setPrice(10);
jmsTemplate.setMessageConverter(messageConverter);
jmsTemplate.convertAndSend("product.topic", product);
}
}
Run Code Online (Sandbox Code Playgroud)
MappingJackson2MessageConverter类:
@Configuration
public class JMSTextMessageConverter {
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter mappingJackson2MessageConverter
= new MappingJackson2MessageConverter();
mappingJackson2MessageConverter.setTargetType(MessageType.TEXT);
mappingJackson2MessageConverter.setTypeIdPropertyName("_type");
return mappingJackson2MessageConverter;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想为发布到主题的JMS消息设置一些自定义标头.我用谷歌搜索,找不到任何这样做的例子.你能帮我吗 ?
我在intellij中有这个代码:
return collection.stream().anyMatch(annotation ->
method.isAnnotationPresent(annotation));
Run Code Online (Sandbox Code Playgroud)
并且编译器告诉我"method.isAnnotationPresent(annotation)"可以用方法引用替换,我无法弄清楚如何做,因为它有一个参数.
有谁知道怎么做?
我只是想返回boolean从Optional做在检查对象getProductType()上的ProductDetails对象,如下图所示:
public boolean isElectronicProduct(String productName) {
Optional<ProductDetails> optProductDetails = findProductDetails(productName);
if(optProductDetails.isPresent()) {
return optProductDetails.get().getProductType() == ProductType.ELECTRONICS;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
Intellij抱怨说上面的代码可以在功能样式中替换,有没有办法简化上面的Optional对象并返回一个boolean?
“内存分布式缓存”与“内存数据网格”有什么区别?
我们什么时候使用一个而不是另一个,即“内存数据网格”的实际用例是什么?
您能列举几个与 Java 应用程序兼容的流行的“内存数据网格”框架吗?
我有以下findProductBetweenPriceRange()方法抛出BadRequestException如下所示:
public Product findProductBetweenPriceRange(int price1, int price2) {
Optional<Product> product = productService.findProductBetween(price1, price2);
return product.orElseThrow(() -> {
String debugInfo = "price1="+price1+";price2="+price2;
throw new BadRequestException("No Product found for price range",debugInfo);
});
}
Run Code Online (Sandbox Code Playgroud)
BadRequestException类:
public final class BadRequestException extends RuntimeException {
public BadRequestException(String errorMessage, String debugInfo) {
this.errorMessage = errorMessage;
this.debugInfo = debugInfo;
}
//fields & getters
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,但是,我只是想将orElseThrow()块重构为不同的方法,如下所示.
我尝试创建throwBadRequestException()方法,throws BadRequestException 我正在调用它orElseThrow(),但我面临一个错误,如"没有类型变量的实例存在,因此void符合".
public Product findProductBetweenPriceRange(int price1, int price2) { …Run Code Online (Sandbox Code Playgroud) 我有一个简单的模型和存储库类,如下所示:
StudentModel 班级:
@Document(collection = "student")
public final class StudentModel {
@Id
private final String name;
private final LocalDateTime joiningDateTime;
public StudentModel(String name, LocalDateTime joiningDateTime) {
this.name = name;
this.joiningDateTime = joiningDateTime;
}
public String getName() {
return name;
}
public LocalDateTime getJoiningDateTime() {
return joiningDateTime;
}
@Override
public String toString() {
return "StudentModel{" +
"name='" + name + '\'' +
", joiningDateTime=" + joiningDateTime +
'}';
}
}
Run Code Online (Sandbox Code Playgroud)
StudentRepository 班级:
@Repository
public interface StudentRepository extends MongoRepository<StudentModel, String> {
} …Run Code Online (Sandbox Code Playgroud) 这是我在stackoverflow中的第一个查询,我想我提供了所有必要的输入:
我在下面提供了我的Java bean和数据库表详细信息:
******Java Bean类:***
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "BANK_MESSAGES")
public class messagesBean implements Serializable
{
@Id
@Column(name="msg_id")
private String msg_id;
@Column(name="msg_date")
Timestamp msgDateTime;
@Column(name="message")
private byte[] message;
@Column(name="msg_type")
private String msg_type;
//Getters and Setters for the above fields
}
Run Code Online (Sandbox Code Playgroud)
下面是我的数据库表(Oracle)的DDL:
create table BANK_MESSAGES
(msg_id varchar2(10),
msg_date timestamp,
message blob,
msg_type varchar2(5)) ;
Run Code Online (Sandbox Code Playgroud)
我试图理解hibernate中的默认继承策略是什么是映射到上面的数据库表的bean?
我无法从 Intellij IDEA 克隆存储库,并且失败并出现以下错误,如图所示。
但是,我可以从命令提示符成功克隆存储库,如下图所示。
请注意,我已成功将公钥文件添加到 Bitbucket 中。此外,下图还显示了“config”文件的内容。
正如评论中所建议的,我已经运行了该命令,它指向如下图所示的which git位置:/usr/local/bin/git
此外,IntelliJ 的“版本控制”> Git 设置也指向同一位置, /usr/local/bin/git如下图所示:
我还在下图中提供了Intellij 控制台选项卡错误详细信息:
所以我有一个Pet如下界面:
public interface Pet{
void Eat();
}
Run Code Online (Sandbox Code Playgroud)
这是由以下实现的:
public class Puppies implements Pet {
@Override
public void Eat() {
// Something gets eaten here, presumably
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class Kittens implements Pet {
@Override
public void Eat() {
// Everybody knows Kittens eats something different
}
}
Run Code Online (Sandbox Code Playgroud)
希望我接下来要做的就是创造一种ArrayList新的宠物:
public class PetList{
public PetList(){
ArrayList pets = new ArrayList<Pet>();
Puppies spot = new Puppies();
Puppies rex = new Puppies();
Kittens meowth = new Kittens();
pets.add(spot);
pets.add(rex); …Run Code Online (Sandbox Code Playgroud) java ×9
java-8 ×3
spring ×3
arraylist ×1
bitbucket ×1
caching ×1
git ×1
hibernate ×1
jms ×1
jpa ×1
mongodb ×1
optional ×1
reflection ×1
spring-boot ×1
spring-data ×1
spring-jms ×1
ssh ×1