我使用Spring数据来管理REST API.我的postgresql数据库中的所有表都有一个UUID类型的主键.我能够保留这些数据但无法获取它.下面是我正在使用的代码和我面临的问题.
MyTableParent.java
@MappedSuperclass
public class MyTableParent {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(
name = "uuid",
strategy = "com.mypackage.UUIDGenerator",
parameters = {
@Parameter(
name = UUID_NAMESPACE,
value = "something"
)
}
)
private UUID id;
// Constructor getter setter
}
Run Code Online (Sandbox Code Playgroud)
MyTable.java
@Entity
@Table(name = "my_table")
public class MyTable extends MyTableParent {
private String name;
// constructor getter setter
}
Run Code Online (Sandbox Code Playgroud)
这是我的表的服务类
TableService.java
@Service("tableservice")
public class TableService {
private TableRepository tableRepository;
public TableService(TableRepository tableRepository) {
this.tableRepository = tableRepository;
}
public List<MyTable> read(MultiValueMap<String, …
Run Code Online (Sandbox Code Playgroud) 我有一个mongoose架构
var schema = new Schema({
id:Number
updated_at:Date
});
Run Code Online (Sandbox Code Playgroud)
我正在使用findOneAndUpdate()
这样更新此模型
model.findOneAndUpdate(
{ id: json.id },
json,
{
upsert: true,
runValidators: true
})
.then(() => {
recordsUpdated++;
})
.catch((err) => {
this.emit('error', err);
});
Run Code Online (Sandbox Code Playgroud)
传入的值json
不正确,我需要对其进行一些修改.我正在寻找一个预钩子进行修改.我试过了
faction.pre('findOneAndUpdate', function (next) {
this.update({ $set: { updated_at: this.getUpdate().updated_at * 1000 } });
next();
});
Run Code Online (Sandbox Code Playgroud)
简而言之,我想在更新数据库之前将时间戳(以秒为单位)转换为毫秒,但这不起作用.
我在我的应用程序中使用 SpringBoot,并且目前正在使用applicationContext.getBean(beanName,beanClass)
它在对它执行操作之前获取我的 bean。我在几个问题中看到不鼓励使用getBean()
. 由于我对 Spring 非常陌生,因此我不了解所有最佳实践并且很矛盾。上述链接问题中提出的解决方案可能不适用于我的用例。我应该如何处理这个问题?
@RestController
@RequestMapping("/api")
public class APIHandler {
@Value("${fromConfig}")
String fromConfig;
private ApplicationContext applicationContext;
public Bot(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@PostMapping(value = "")
public ResponseEntity post(@RequestBody HandlingClass requestBody) {
SomeInterface someInterface = applicationContext.getBean(fromConfig, SomeInterface.class);
someInterface.doSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为SomeInterface
定义的接口,如下所示:
public interface SomeInterface {
void doSomething();
}
Run Code Online (Sandbox Code Playgroud)
我有 2 个类实现了这个接口,称为UseClass1
和UseClass2
。我的配置文件存储了一个带有类的 bean 名称的字符串,我需要在运行时知道它并调用该方法的适当实现。
任何方向将不胜感激。
我正在使用 Docker for Windows(Windows 10 是 2004 年的,所以我有 WSL2),并且我正在尝试容器化 Nuxt 应用程序。该应用程序在我的本地系统上运行良好,在创建 Dockerfile 并构建它之后,我无法将其转发到我的主机系统上。然而,当尝试使用来自https://github.com/BretFisher/docker-mastery-for-nodejs/tree/master/ultimate-node-dockerfile的示例应用程序时(test
应该使用该文件夹中的 Dockerfile ),我可以访问相同的。
如果我exec
进入正在运行的容器,我能够获得运行时的输出curl http://localhost:3000
,所以一切都应该很好。
我的 Dockerfile 看起来像
\nFROM node:12.18.3-buster-slim\nLABEL org.opencontainers.image.authors=sayak@redacted.com\nEXPOSE 3000\nWORKDIR /app\nRUN chown -R node:node /app\nCOPY --chown=node:node package*.json ./\nENV NODE_ENV=development\nRUN apt-get update -qq && apt-get install -qy \\\n ca-certificates \\\n bzip2 \\\n curl \\\n libfontconfig \\\n --no-install-recommends\nUSER node\nRUN npm config list\nRUN npm ci \\\n && npm cache clean --force\nENV PATH=/app/node_modules/.bin:$PATH\nCOPY --chown=node:node . .\nRUN nuxt build\nENV NODE_ENV=production\nCMD …
Run Code Online (Sandbox Code Playgroud) java ×2
node.js ×2
spring-boot ×2
docker ×1
dockerfile ×1
kubernetes ×1
mongoose ×1
postgresql ×1
spring ×1