springboot使用eav模型实现curd 包含controller
时间: 2024-03-16 22:42:24 浏览: 135
springboot实现crud
以下是一个简单的EAV模型的CRUD操作的Controller示例:
```java
@RestController
@RequestMapping("/eav")
public class EavController {
@Autowired
private EavService eavService;
@PostMapping("/entity")
public ResponseEntity<Entity> createEntity(@RequestParam String type, @RequestParam String name) {
Entity entity = eavService.createEntity(type, name);
return ResponseEntity.ok(entity);
}
@PostMapping("/attribute")
public ResponseEntity<Attribute> createAttribute(@RequestParam String name) {
Attribute attribute = eavService.createAttribute(name);
return ResponseEntity.ok(attribute);
}
@PostMapping("/value")
public ResponseEntity<Value> createValue(@RequestParam Long entityId, @RequestParam Long attributeId,
@RequestParam String value, @RequestParam String type) {
Entity entity = eavService.getEntity(entityId);
Attribute attribute = eavService.getAttribute(attributeId);
Value val = eavService.createValue(entity, attribute, value, type);
return ResponseEntity.ok(val);
}
@GetMapping("/values")
public ResponseEntity<List<Value>> getValues(@RequestParam Long entityId, @RequestParam Long attributeId) {
Entity entity = eavService.getEntity(entityId);
Attribute attribute = eavService.getAttribute(attributeId);
List<Value> values = eavService.getValues(entity, attribute);
return ResponseEntity.ok(values);
}
// ...
}
```
在Controller中,我们使用了EavService中的方法来实现EAV模型的CURD操作。在POST请求中,我们使用@RequestParam注解来获取请求参数;在GET请求中,我们使用@RequestParam注解来获取查询参数。
阅读全文