小编Ere*_*ent的帖子

如何查询具有未定义深度的层次结构类别树实体

我使用springboot为购物网站创建了一个层次结构或树形结构.我的问题是在寻找特定产品及其父母时如何查询这样的结构:

id,  category_name,   parent_id
'1', 'Electronics',      NULL
'2', 'Gaming',           NULL
'3', 'Home Audio',       '1'
'4', 'Console',          '2'
'5', 'Sony',             '4'
'6', 'Karaoke',          '3'
Run Code Online (Sandbox Code Playgroud)

这就是我所做的,关于我需要在实体上实现这个结构的任何指针,以及我如何查询它,即

同样重要的是要注意我正在使用postgres数据库

  1. findAllProducts在一个类别和
  2. 查找链接到产品的所有类别.

类别实体

@Entity
@Table(name = "categories")
public class Category {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(nullable = false)
    private String categoryName;

        @ManyToOne
        @JoinColumn(name = "parent_id")
        private Category parent;

        @OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE, orphanRemoval = true)
        private List<Category> children = new ArrayList<Category>();

    // Getter and setter removed for readability    
} …
Run Code Online (Sandbox Code Playgroud)

java tree spring-boot

9
推荐指数
1
解决办法
883
查看次数

nil 合并运算符 '??' 的左侧 具有非可选类型“String”,因此从不使用右侧

我有以下代码,我试图用它来初始化变量并对其执行一些操作。

let formattedPointsValue: String?
self.formattedPointsValue = model.pointUnitsEarned.stringValueWithWhiteSpaceThousandSeperator()+" "+"model.name".localized(in: .name) ?? .none
Run Code Online (Sandbox Code Playgroud)

但是我收到警告

nil 合并运算符 '??' 的左侧 具有非可选类型“String”,因此从不使用右侧。

当我删除?? .none我的项目时,我的项目运行良好,没有问题,但是当我运行单元测试时,我收到错误

致命错误:在解包可选值时意外发现 nil

我发现解决这个问题的唯一方法是使用这段代码。

if let unformattedValue = model.pointUnitsEarned {
    self.formattedPointsValue = unformattedValue.stringValueWithWhiteSpaceThousandSeperator()+" "+"model.name".localized(in: .name)
} else {
    self.formattedPointsValue = nil
}
Run Code Online (Sandbox Code Playgroud)

我想了解为什么这样的事情有效:

let legend: String?
self.legend = model.pointsCategory ?? .none
Run Code Online (Sandbox Code Playgroud)

但这失败了:

let formattedPointsValue: String?
self.formattedPointsValue = model.pointUnitsEarned.stringValueWithWhiteSpaceThousandSeperator()+" "+"model.name".localized(in: .name) ?? .none
Run Code Online (Sandbox Code Playgroud)

ios swift forced-unwrapping option-type

5
推荐指数
1
解决办法
6006
查看次数

如何使用 MVVM 登录?

我对 iOS 开发还是很陌生,我正在尝试从 MVVM 开始在 Swift 中自学良好的编码实践和设计模式。我需要将数据从我的 ServiceCall 类中的完成句柄传递到我的 ViewModel。我需要帮助以了解我如何做到这一点,以及在我的代码中使用 MVVM 的最佳实践指导。

这是我到目前为止所做的:

模型

struct Login {
  var appVersion: String ?
  var deviceID : String ?
  var deviceOS : String ?
  var password : String ?
  var username : String ?
}
Run Code Online (Sandbox Code Playgroud)

服务调用/API 客户端

class LoginServiceCall : NSObject, URLSessionDelegate {
  let viewResponse = ThrowResponse()
  func requestLogin(request: URLRequest, requestObject: Login, completion: @escaping ([NSDictionary] ? ) -> Void) {
    let searchParams = Login.init(appVersion: requestObject.appVersion, deviceID: requestObject.deviceID, deviceOS: requestObject.deviceOS, password: requestObject.password, username: requestObject.username) …
Run Code Online (Sandbox Code Playgroud)

dictionary nsdictionary mvvm completionhandler swift

5
推荐指数
0
解决办法
2464
查看次数

如何查询Postgres数据库以获取特定坐标10km半径内的所有点

我有一个商店数据库,在该数据库中,我保存了这些商店的坐标。我想获取半径为10公里的商店列表,但是由于使用的是Postgres数据库,因此我不确定如何编写Postgres查询。

我的数据库:

在此处输入图片说明

我正在尝试将查询添加到springboot地理位置微服务中:

仓库代码:

@Repository
public interface SellerGeolocationRepository extends CrudRepository<Seller_Geolocation, Long> {

    @Query(value="SELECT * FROM seller_geolocation_ms WHERE 
   // get coordinates that are in the vicinity
", nativeQuery = true)
        public Set<Seller_Geolocation> findAllSellersInRange(double longitude, double latitude);

    }
Run Code Online (Sandbox Code Playgroud)

SellerObject:

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "seller_geolocation_ms")
public class Seller_Geolocation {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private static final long serialVersionUID = 2L;

    private double latitude;
    private double longitude;
    private String country;
    private String city;
    private String zipCode;
    private String …
Run Code Online (Sandbox Code Playgroud)

java postgresql geolocation spring-boot

5
推荐指数
1
解决办法
216
查看次数

无法创建 tempDir。java.io.tmpdir 设置为 /tmp

在 ubuntu 服务器上运行我的 springboot web 服务 java jar 应用程序会导致如下所示的错误,我已经对该错误进行了一些研究,但是我无法得到解决方案。我用来运行 jar 文件的命令是

java -jar mySpringBootApp.jar
Run Code Online (Sandbox Code Playgroud)

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to /tmp
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
    at aacctt.payments.org.Application.main(Application.java:18) [classes!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [ mySpringBootApp-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [ …
Run Code Online (Sandbox Code Playgroud)

java spring jar spring-boot

4
推荐指数
1
解决办法
2万
查看次数

线程10:致命错误:展开一个可选值时意外发现nil

我正在尝试进行服务呼叫以获取用户详细信息,但是却出现此错误:

线程10:致命错误:展开一个可选值时意外发现nil

从此代码:

    let urlString = "http://myURL.com/getInfo/getAccountTransactions/{accountPublicKey}"
    print(urlString)
    let requestUrl = URL(string:urlString)
    let requestURL = URLRequest(url:requestUrl!)
Run Code Online (Sandbox Code Playgroud)

当我将代码包装在后卫中时,因为找到nil,所以代码不会执行,我不确定为什么,因为URL字符串永远不会是nill,因为它在同一代码上使用默认值进行了初始化。

这在警卫的代码让:

    let urlString = "http://myURL.com/getInfo/getAccountTransactions/{accountPublicKey}"
    guard let requestUrl = URL(string:urlString) else { return }
    let requestURL = URLRequest(url:requestUrl)
Run Code Online (Sandbox Code Playgroud)

这是整个服务的调用代码:

class TransactionServiceCall : NSObject, URLSessionDelegate{

let viewResponse = ThrowResponse()

func fetchTransactions(requestObject: Transaction, completion: @escaping (Dictionary<String,Any>?) -> Void) {
    let urlString = "http://myURL.com/getInfo/getAccountTransactions/{accountPublicKey}"

    guard let requestUrl = URL(string:urlString) else { return }
    let requestURL = URLRequest(url:requestUrl)

    let searchParams = Transaction.init(publicKey: requestObject.publicKey)
    var request = requestURL …
Run Code Online (Sandbox Code Playgroud)

nsurl nsurlconnection swift

3
推荐指数
1
解决办法
236
查看次数

Springboot如何以OneToMany关系保存数据

我是java和java开发的新手,我刚刚开始自学springboot,我想将数据保存到具有一对多关系的表中。我不知道如何去做,因为这与一对一的关系不同。

这是我的代码:

账户类别

Entity
@Table(name = "Account")
public class Account implements Serializable {

    @JsonIgnore
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int accountID;

     @JsonIgnore
    private String accountName;

     @JsonIgnore
    private String accountType;

    private Boolean openAccount;

     @JsonIgnore
    private Double balance;

    @JsonIgnore
    @OneToOne(mappedBy = "account")
    private Customer customer;

    @OneToMany(mappedBy = "account")
    private List<AccountTransactions> Transactions ;

    public Account() {
    }

    public Account(String accountType, String accountName, Boolean openAccount, Double balance, Customer customer) {
        this.accountType = accountType;
        this.accountName = accountName;
        this.openAccount = openAccount;
        this.balance = balance;
        this.customer = …
Run Code Online (Sandbox Code Playgroud)

java jpa spring-boot

2
推荐指数
2
解决办法
2万
查看次数

Config-Server无法配置数据源:未指定'url'属性,并且无法配置任何嵌入式数据源

我试图从包含所有应用程序属性的github存储库中获取数据库配置。下图说明了我所拥有的服务的结构:

在此处输入图片说明

当我访问我的配置服务器微服务时,一切正常,即使我在邮递员中对其进行测试,也可以恢复配置。

当我尝试运行产品服务同时指向配置服务器微服务以获取数据库配置时,问题就来了。我收到以下错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2018-11-17 17:53:23.730  INFO 9497 --- [  restartedMain] o.a.s.p.ProductServicesApplication       : Starting ProductServicesApplication on …
Run Code Online (Sandbox Code Playgroud)

java spring-boot spring-cloud-config application.properties

2
推荐指数
1
解决办法
5055
查看次数

-bash: ./deploy.sh: Permission denied ,错误:脚本返回退出代码 126

我正在尝试使用 Jenkins 实现持续部署,这涉及将 jar 文件发送到远程服务器并在远程服务器上启动 jar。

问题是我不断收到拒绝访问错误,并且我已经尝试了我在远程和本地服务器上的每个帐户似乎没有任何效果。我犯了同样的错误。

詹金斯文件

pipeline {
    agent any

    stages {

        stage ('Packaging stage') {

            steps {
                withMaven(maven : 'Maven') {
                    sh 'mvn clean install'
                }
            }
        }

        stage ('Deploy To Dev Server') {

             steps {
                sh './deploy.sh'
         }
       }
    }

}
Run Code Online (Sandbox Code Playgroud)

部署文件

#!/usr/bin/expect -f
spawn scp -P 10022 /var/lib/jenkins/.m2/repository/org/hector/eureka-naming-server/0.0.1-SNAPSHOT/eureka-naming-server-0.0.1-SNAPSHOT.jar
myUserName@myRemoteServer.net:/home/myname/repository/eureka-service-deploy

expect "password: "

send "myPassword\r"

expect "$ "
send "other_command_to_execute_on_remote\r"
expect "$ "
send "exit\r"
echo "Successfully sent file"
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

java bash jenkins spring-boot

2
推荐指数
1
解决办法
6533
查看次数

java.io.FileNotFoundException: /home/ec2-user/src/main/resources/keystore.jks(没有这样的文件或目录)

我在引用 jar 文件中的文件时遇到问题,特别是 keystore.jks。我将文件存储在资源文件中,但是当我尝试运行 springboot 项目时,似乎没有选择该文件。

我收到此错误:

java.io.FileNotFoundException: /home/ec2-user/src/main/resources/keystore.jks (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

这是我的applications.properties 文件:

server.ssl.key-store=src/main/resources/keystore.jks
server.ssl.key-store-password=mypassword
server.ssl.keyStoreType=JKS
server.ssl.keyAlias=my_alias
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构:

在此处输入图片说明

java resources spring-boot

1
推荐指数
1
解决办法
2863
查看次数