我的 Postgres 数据库中有一个表,其中有一个时间戳列。我希望每次更新行时都会自动插入它。我写了一个数据库触发器:
CREATE FUNCTION update_last_edit_date() RETURNS trigger AS $update_last_edit_date$
BEGIN
NEW.last_edit_date := localtimestamp(0);
RETURN NEW;
END;
$update_last_edit_date$ LANGUAGE plpgsql;
CREATE TRIGGER update_last_edit_date BEFORE UPDATE ON employee
FOR EACH ROW
WHEN (OLD.* IS DISTINCT FROM NEW.*)
EXECUTE PROCEDURE update_last_edit_date();
Run Code Online (Sandbox Code Playgroud)
效果很好,但我想知道是否有一种更简单的方法可以使用 jpa/hibernate 注释来做到这一点。我尝试了这些不同的选项:
@预更新
@PreUpdate
private void onUpdate(){
this.lastEditDate = new Date();
}
Run Code Online (Sandbox Code Playgroud)
@更新时间戳
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
private Date lastEditDate;
Run Code Online (Sandbox Code Playgroud)
但我得到的是,当我更新一行时,所有行的时间戳都会更新,因此表中的所有时间戳始终相同。我在这里做错了什么?
我正在尝试使用 react hook form 制作一个包含两个字段的表单,其中文本字段的所需值取决于选择下拉列表的值。
这是我的代码:
const { handleSubmit, control, errors } = useForm();
const [isPickupPoint, togglePickupPoint] = useState(false);
const handleDestinationTypeChange: EventFunction = ([selected]) => {
togglePickupPoint(selected.value === "PICKUP_POINT");
return selected;
};
Run Code Online (Sandbox Code Playgroud)
<Grid item xs={6}>
<InputLabel>Destination type</InputLabel>
<Controller
as={Select}
name="destinationType"
control={control}
options={[
{ label: "Pickup point", value: "PICKUP_POINT" },
{ label: "Shop", value: "SHOP" },
]}
rules={{ required: true }}
onChange={handleDestinationTypeChange}
/>
{errors.destinationType && (
<ErrorLabel>This field is required</ErrorLabel>
)}
</Grid>
<Grid item xs={6}>
<Controller
as={
<TextField
label="Pickup Point ID" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 spring-kafka 将 kafka 与我的 Spring boot (v2.0.6.RELEASE) 应用程序集成。现在我想要一个消费者和一个生产者。我让生产者工作得很好,我可以看到消息通过控制台消费者发送到主题。我无法让消费者代码工作,当 kafka 主题中出现新消息时,它不会被调用。
这是我的卡夫卡配置类:
@Configuration
@EnableKafka
public class KafkaConfiguration {
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, <path to my custom serializer>);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
return props;
}
@Bean
public Map<String, Object> consumerConfigs(){
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, <path to my custom deserializer>);
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
// props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
return props;
}
@Bean
public ConsumerFactory<String, List<MyMessage>> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs());
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从子组件向父组件发出事件。这是父文件 TS 文件的一部分:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-car-detail',
templateUrl: './car-detail.component.html',
styleUrls: ['./car-detail.component.css'],
})
export class CarDetailComponent implements OnInit {
constructor() { }
ngOnInit() {
this.getCarDetail(this.route.snapshot.params['id']);
}
refreshList(event){
console.log("Parent called");
}
}
Run Code Online (Sandbox Code Playgroud)
以及涉及发射器的模板部分
<app-operations (myEvent)="refreshList($event)"></app-operations>
Run Code Online (Sandbox Code Playgroud)
这是子 TS 文件:
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
@Component({
selector: 'app-add-operation',
templateUrl: './add-operation.component.html',
styleUrls: ['./add-operation.component.css']
})
export class AddOperationComponent implements OnInit {
@Output() myEvent = new EventEmitter<any>();
constructor() { }
ngOnInit() {
}
callParent() {
console.log('callparentmethod');
this.myEvent.emit('eventDesc');
}
} …
Run Code Online (Sandbox Code Playgroud) java ×2
javascript ×2
angular ×1
apache-kafka ×1
eventemitter ×1
frontend ×1
hibernate ×1
jpa ×1
postgresql ×1
react-hooks ×1
reactjs ×1
spring ×1
spring-kafka ×1
timestamp ×1
typescript ×1