我想在 2 个实体、消费者和政策之间建立一对多关系。一个消费者应该有几个政策。
这是我想要的消费者 JSON 对象的示例:
{
id : 1,
name : "Peter",
endpoint: "123.456.778",
policies: [
{
id : 1,
name: "policy 01"
},
{
id : 2,
name: "policy 02"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止:
政策实体
@Entity
public class Policy {
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
消费者实体
@Entity
public class Consumer {
@Id
@GeneratedValue
@Column(name = "consumer_id")
private Integer id;
@Column(name = "name")
private String name; …Run Code Online (Sandbox Code Playgroud) 我是 Spring MVC 的新手。我面对UnsatisfiedDependencyException. 我已经添加,stereotype annotations但我仍然面临同样的问题。
上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“userController”的 bean 时出错:通过字段“userService”表达的不满意依赖;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖 [com.demo.app.service.UserService] 的合格 bean:预期至少有 1 个 bean 有资格作为自动装配候选。依赖注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)} 看起来很积极。
用户控制器:
@CrossOrigin
@RestController
public class UserController {
@Autowired(required=true)
private UserService userService;
@RequestMapping(value = { "/userSave" },consumes = {"multipart/form-data"}, method = RequestMethod.POST)
@ResponseBody
public String saveUserDetails(@RequestPart(value="file",required=false) MultipartFile file,
@RequestPart("user")User user,
HttpSession session, HttpServletRequest request,
HttpServletResponse response){
System.out.println("data reached...!");
String result=userService.saveUserData(user,session);
return result;
}
Run Code Online (Sandbox Code Playgroud)
}
用户服务:
public interface UserService {
public String saveUserData(User user,HttpSession session);
}
Run Code Online (Sandbox Code Playgroud)
UserServiceImpl:
@Service("userService") …Run Code Online (Sandbox Code Playgroud) 我正在使用每个循环对每个值执行单个插入。
我们如何使用密码查询进行批量插入。
这是我的代码...
控制器
@PostMapping("/geohash")
public Set<String> create(@RequestParam String name, @RequestBody LatLng[] latLngs) {
double[][] polygonPoints = convertTo2dArrayOfLatLng(latLngs);
Set<String> geoHashesForPolygon = GeoHashUtils.geoHashesForPolygon(6, polygonPoints);
for (String geohash : geoHashesForPolygon) {
min = Math.min(min, geohash.length());
geohashes = neoService.create(name, geohash);
}
return geoHashesForPolygon;
}
Run Code Online (Sandbox Code Playgroud)
我想将每个插入geoHashesForPolygon为单个节点..
密码查询
@Query("MATCH (c:C) WHERE c.name = {name} CREATE (g: G{name : {geohash}} )<-[:cToG]-(c) RETURN c,g")
public GeohashOfCluster create(@Param("name") String name,@Param("geohash") String geohash);
Run Code Online (Sandbox Code Playgroud) 我无法在我的界面中为 Neo4j 空间插件导入JavaSpatialRepository和GraphRepositoryJava。
我必须使用neo4j-spatial 插件将多边形数据添加到neo4j 数据库中。为此我使用wkt 格式。但是由于我的 pom.xml 中的版本不匹配,没有导入任何内容。
我曾尝试更改空间插件的版本,但仍然无济于事。我正在使用嵌入式驱动程序。
我正在添加完整的 pom.xml 配置。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neo4j</groupId>
<artifactId>Neo4j</artifactId>
<version>0.25.5-neo4j-3.3.5</version>
<packaging>jar</packaging>
<name>Neo4j</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.3.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId> …Run Code Online (Sandbox Code Playgroud) 我有两个<div>带有自己的控制器.第一个div有一个ng-model="listEntries".我listEntries在这个<div>控制器中初始化.
app.controller('firstController', function($scope,serviceForFirst){
serviceForFirst.init();
serviceForFirst.getList($scope);
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div ng-controller="firstController">
<ul>
<li ng-repeat="each in listEntries">
{{each.name}}
</li>
<ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我将传递$scope给getList()并设置$scope.listEntries值serviceForFirst.我然后listEntries用作ng-model.
app.service('serviceForFirst',function(){
var list=[];
var init=function(){
list = [{....}];
};
var getList=function($scope){
$scope.listEntries = list;
};
var update=function(newEntity){
list.push(newEntity);
};
return{
init:init,
getList:getList,
update:update
};
});
Run Code Online (Sandbox Code Playgroud)
这是我的第二个控制器和与之关联的服务.我打算listAll每次调用时都会推送新元素addNew().这就是我试图这样做的方式.
app.controller('secondController', function($scope,serviceForSecond){
serviceForSecond.init();
$scope.addNew=function(newEntity){
serviceForSecond.addNew(newEntity);
};
});
app.service('serviceForSecond',function(serviceForFirst){
var entities=[];
var …Run Code Online (Sandbox Code Playgroud) javascript angularjs angularjs-scope angularjs-ng-repeat angularjs-digest
我正在尝试实现一个REST API消耗excel文件。我正在使用spring-boot,这里提供了代码。
将FileSystemResource用作有效负载时,代码可以正常工作。但是我无法使代码与ByteArrayResource一起替换FileSystemResource:
RestApi.java:
@RestController
public class RestApi {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@PostMapping("/api/upload")
public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile uploadfile) {
LOGGER.debug("Single file upload!");
try {
LOGGER.info("\n\n ****** File name: {}, type {}! ************", uploadfile.getOriginalFilename(), uploadfile.getContentType());
this.processExcelFile(uploadfile.getInputStream());
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>("Successfully uploaded - " + uploadfile.getOriginalFilename(), new HttpHeaders(), HttpStatus.OK);
}
private List<String> processExcelFile(InputStream stream) throws Exception {
List<String> result = new ArrayList<String>(); …Run Code Online (Sandbox Code Playgroud) java ×4
spring ×3
neo4j ×2
spring-boot ×2
angularjs ×1
cypher ×1
hibernate ×1
javascript ×1
jpa ×1
rest ×1
spring-data ×1
spring-mvc ×1