小编D.Z*_*Zet的帖子

JAVA DynamoDB:不支持; 需要@DynamoDBTyped或@DynamoDBTypeConverted

我已经创建了CRUD方法,但我遇到了一些问题.

这是我的添加方法代码:

public Product addProduct(Product content) {
    Product item = new Product();

    item.setName(content.getName());
    item.setCalories(content.getCalories());
    item.setFat(content.getFat());
    item.setCarbo(content.getCarbo());
    item.setProtein(content.getProtein());
    item.setProductKinds(content.getProductKinds());
    item.setAuthor(content.getAuthor());
    item.setMedia(content.getMedia());
    item.setApproved(content.getApproved());


    databaseController.saveTest(item);
    logger.log("Item created");


    return item;
}
Run Code Online (Sandbox Code Playgroud)

这是我的editProduct方法:

public Product editProduct(Product product) {
    Product databaseProduct = databaseController.get(Product.class, product.getId());
    databaseProduct.setAllProducts(product);
    databaseController.save(databaseProduct);
    return databaseProduct;
}
Run Code Online (Sandbox Code Playgroud)

在模型课中,我认为我已经做好了一切:

package pl.javamill.model.kitchen;

import com.amazonaws.services.dynamodbv2.datamodeling.*;
import pl.javamill.model.Request;
import pl.javamill.model.common.Author;
import pl.javamill.model.common.AuthorConverter;
import pl.javamill.model.common.Media;
import pl.javamill.model.common.MediaConverter;

import java.util.List;

@DynamoDBTable(tableName = "product")
public class Product extends Request {

/**
 * Id of kitchen content
 */
private String id;
/** …
Run Code Online (Sandbox Code Playgroud)

java amazon-web-services amazon-dynamodb aws-lambda

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

AWS DynamoDB:无法取消转换属性错误

我有一个问题,无法解决。我已经在KitchenService中创建了CRUD方法。我有addProduct等方法,这些方法都可以正常工作。.但是我在使用Product类字段的地方有Recipe类。

我的addRecipe方法:

public Recipe addRecipe (Recipe recipe){

    List<RecipeElement> recipeElements = recipe.getRecipeElements();
    for (RecipeElement recipeElement : recipeElements) {
        String id = recipeElement.getProduct().getId();
        Product product = databaseController.get(Product.class, id);
        recipeElement.setProduct(product);
    }

    databaseController.saveRecipe(recipe);
    logger.log("Recipe created");

    return recipe;
Run Code Online (Sandbox Code Playgroud)

构建成功,所以我想在POSTMAN中对其进行测试,这就是我发送的JSON Witch的外观:

{"id":null,"name":"test3","labels":["GLUTEN_FREE"],"author":{"name":"Plejer Anno?n","id":"testID2"},"media":{"name":"heheszki","url":"http://blabla.pl","mediaType":"IMAGE"},"recipeElements":[{"product":{"id":"ecacaf36-29a2-41c6-942e-be5a715ed094"},"weight":"100"}],"approved":false}
Run Code Online (Sandbox Code Playgroud)

然后我得到“消息”:“内部服务器错误”,所以我正在检查日志,这就是我在这里发现的内容:

Product[Media]; could not unconvert attribute: com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException

Caused by: com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: could not invoke public void pl.javamill.model.kitchen.Product.setMedia(pl.javamill.model.common.Media) on class pl.kitchen.Product with value {name=heheszki, url=http://blabla.pl, mediaType=IMAGE} of type class java.util.LinkedHashMap
Run Code Online (Sandbox Code Playgroud)

这是食谱类的外观:

@DynamoDBTable(tableName = "recipe")
public class Recipe extends Request {
/**
 * Id of kitchen …
Run Code Online (Sandbox Code Playgroud)

java json amazon-web-services amazon-dynamodb objectmapper

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

使用 LocalDate 类型参数发送请求

我想发送这样的请求:

  • http://localhost:8080/reports/daily?start_date=2018-03-22&end_date=2018-03-24

我有一个错误:

“2018-05-31 15:40:29.623 WARN 11496 --- [nio-8080-exec-5] .wsmsDefaultHandlerExceptionResolver:无法绑定请求元素:org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:无法转换'java.lang.String' 类型到所需类型 'java.time.LocalDate';嵌套异常是 org.springframework.core.convert.ConversionFailedException:无法从类型 [java.lang.String] 转换为类型 [@org .springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.LocalDate] for value '2018-03-22';嵌套异常是 java.lang.IllegalArgumentException:解析尝试失败的值[2018-03-22]》

问题很明显,所以我找到了解决方案并改变了一切。我的方法:

@RequestMapping(path = "reports/daily", method = RequestMethod.GET, 
                consumes = MediaType.APPLICATION_JSON_VALUE)
public String getDailyReport(@RequestParam ("start_date") 
                             @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 
                             LocalDate startDate, 
                             @RequestParam("end_date") 
                             @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 
                             LocalDate endDate) {
    double totalDistance = 0.0;
    double totalPrice = 0.0;
    List<Transit> transits = transitService.getTransits(startDate, endDate);
    for (Transit transit : transits) {
        if (transit.getDistance() != null && transit.getPrice() != null) {
            try {
                totalDistance …
Run Code Online (Sandbox Code Playgroud)

java spring date spring-boot localdate

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

JAVA - LocalDate.plusDay()无法正常工作

我想创建方法,将属于某些trainingCycle的训练添加到日历中.可疑的是,我犯了一些错误,因为它只将培训添加到一天.

TrainingCycle模型类:

@DynamoDBTable(tableName = "trainingCycle")
public class TrainingCycle extends Request {
private String id;
private String cycleName;
private Long cycleTime;
private LocalDateTime startTime;
private List<List<Training>> trainingsForDay;
Run Code Online (Sandbox Code Playgroud)

培训模型类:

@DynamoDBTable(tableName = "training")
@DynamoDBDocument
public class Training extends Request {

private String id;
private String trainingName;
private Integer predictedCaloriesToBurn;
private Integer burnedCalories;
private LocalDateTime startTime;
private LocalDateTime endTime;
private List<Exercise> exerciseList;
private List<TrainingLabels> trainingLabels;
private boolean approved;
private ActivityDay activityDay;
Run Code Online (Sandbox Code Playgroud)

AddTrainingCycle方法:

    public List<Day> addTrainingCycle(String userId, TrainingCycle trainingCycle, LocalDate localDate) {

    List<Day> days = …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing java-time

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

功能不是功能?

我有一点问题因为我想在bootstrap-datepicker的选项中使用我的函数.我有功能检查日期是否在日期数组中:

isInArray(array, value) {
    return !!array.find(item => {
        return item.getTime() == value.getTime()
    });
}
Run Code Online (Sandbox Code Playgroud)

我想在这个选项中使用它(https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#beforeshowmonth)所以我把它放到我的选项中:

this.datepickerOptionsForMonths = {
    minViewMode: 1,
    format: "mm-yyyy",
    startDate: this.dateFrom,
    endDate: this.dateTo,
    beforeShowMonth: function (date: Date) {
       return this.isInArray(this.datepickerRange, date.getDate());
    }
};
Run Code Online (Sandbox Code Playgroud)

现在是问题,因为编译完成,一切似乎都很好,但然后在控制台我遇到错误:

this.isInArray is not a function
Run Code Online (Sandbox Code Playgroud)

也许问题是我已经在datepickerOptionsForMonths所在的同一个体中使用过这个函数(在ngOnInit中).有人能帮我吗?

javascript typescript bootstrap-datepicker angular

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