小编Mil*_*lad的帖子

MongoDB嵌入式对象没有ID(空值)

我对使用Spring Data的MongoDB有疑问.我有这些域类:

@Document
public class Deal  {
    @Id
    private ObjectId _id;
    private Location location;
    private User user;
    private String description;
    private String title;
    private String price;
    private boolean approved;
    private Date expirationDate;
    private Date publishedDate;
}

@Document
public class Location {
    @Id
    private ObjectId _id;
    private Double latitude;
    private Double longitude;
    private String country;
    private String street;
    private String zip;
}

@Document
public class User {
    @Id
    private ObjectId _id;
    private String email;
    private String password;
    private String profile_image_url;
    private …
Run Code Online (Sandbox Code Playgroud)

java spring mongodb spring-data

25
推荐指数
4
解决办法
3万
查看次数

ClassNotFoundException FreeMarkerConfigurationFactory

我有一个使用FreeMarker的大型Web应用程序.当我最近更新到Spring 3.2.4并通过jetty或tomcat运行web应用程序时,我得到以下异常:java.lang.ClassNotFoundException:org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.

我知道Spring-webmvc中有FreeMarkerConfigurationFactory类,所以我的POM中包含依赖项.我不知道为什么我得到例外.我已经包含了我的POM和我的弹簧servlet.

<?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>
<artifactId>WhiteSwan-Web</artifactId>
<groupId>com.millad.whiteswan.web</groupId>
<version>1.5</version>
<packaging>war</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.12.v20130726</version>
        </plugin>
    </plugins>
</build>

<properties>
    <org.springframework.version>3.2.4.RELEASE</org.springframework.version>
 <org.springframework.security.version>3.1.4.RELEASE</org.springframework.security.version>
    <junit.version>4.11</junit.version>
    <joda.time.version>2.2</joda.time.version>
    <mockito.version>1.9.5</mockito.version>
    <freemarker.version>2.3.20</freemarker.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.5.3</version>
    </dependency>
   <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
       <version>2.0-beta8</version>
   </dependency>
   <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
       <version>2.0-beta8</version>
   </dependency>
    <dependency>
        <groupId>com.foursquare</groupId>
        <artifactId>fongo</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>${mockito.version}</version>
    </dependency>
    <dependency>
        <groupId>net.coobird</groupId>
        <artifactId>thumbnailator</artifactId>
        <version>0.4.5</version>
    </dependency>
    <!-- …
Run Code Online (Sandbox Code Playgroud)

java spring freemarker jetty spring-mvc

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

使用Play渲染JSON!和斯卡拉

我有一个关于从Scala类渲染JSON对象的简单问题.为什么我必须实现反序列化器(读,写).

我有以下案例类:

case class User(firstname:String, lastname:String, age:Int)
Run Code Online (Sandbox Code Playgroud)

在我的控制器中:

val milo:User = new User("Sam","Fisher",23);

Json.toJson(milo);
Run Code Online (Sandbox Code Playgroud)

我得到编译错误:找不到类型models.User的Json反序列化器.尝试为此类型实现隐式写入或格式.

在我以前的项目中,我必须在类中实现一个reader,writer对象才能工作,我发现它非常烦人.

object UserWebsite {
  implicit object UserWebsiteReads extends Format[UserWebsite] {

    def reads(json: JsValue) = UserWebsite(
      (json \ "email").as[String],
      (json \ "url").as[String],
      (json \ "imageurl").as[String])

    def writes(ts: UserWebsite) = JsObject(Seq(
      "email" -> JsString(ts.email),
      "url" -> JsString(ts.url),
      "imageurl" -> JsString(ts.imageurl)))
  }
} 
Run Code Online (Sandbox Code Playgroud)

json scala playframework playframework-2.0

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

Java的currentTimeMillis返回负值

我正在用Java开发一个简单的2D游戏,一切正常.为了找到正确的FPS刷新/重绘/更新,我使用currentTimeMillis来查找差异.

问题是currentTimeMillis有时会返回负值,而Thread.sleep会抛出异常(java.lang.IllegalArgumentException:timeout值为负)

我做的是在我的游戏中放一段时间,而currentTimeMillis <= -1再次检查直到它结束,然后睡觉.

代码示例:

private void gameLoop(){
    // Find FPS
    long FPS = 40;
    long beginTime = System.currentTimeMillis();
    while(beginTime < -1){
        beginTime = System.currentTimeMillis();
    }
    while(!done){
        // Sleep
        try{ 
            beginTime += FPS;
            long currTime = System.currentTimeMillis();
            while(currTime < -1){
                currTime = System.currentTimeMillis();
            }
            difference = (beginTime - currTime);
                           // Should be (currTime - beginTime) 

            Thread.sleep(difference); 
        }catch (Exception e){ 
            e.printStackTrace();
        }
        // RENDER GAME
        renderGame();
    }
    JOptionPane.showMessageDialog(null, "Game Over\nYou Died.");
    System.exit(0);
}// end gameLoop()
Run Code Online (Sandbox Code Playgroud)

当游戏开始时,这很好,但有时我仍然得到例外.有没有更好的办法?我仍然认为它返回负值是很奇怪的.

java time

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