小编Tru*_*rin的帖子

Spring Boot Ajax post 表单与模型和百里香叶一起提交

我有一个 spring boot 控制器,它返回一个视图,我想通过使用 ajax 端点来更改它,但同时使用 modelAttribute 从表单中获取值,然后在页面上发送一个或多个列表并迭代那些带有百里香叶的清单。这可能吗?这是控制器:

@RequestMapping(value="/search", method=RequestMethod.POST)
    @ResponseBody
    public String search(@ModelAttribute("specification") Specification specification, Model model) {

        List<SearchResultAutovit> list;

        list = scrapper.searchMethod(specification.getPrice,specification.getModel);

        if (list == null || list.isEmpty()) { 
            model.addAttribute("msg","Something"); 
        } else { 
            model.addAttribute("listaAutovit", list); 
        }
        return "?";
    }
Run Code Online (Sandbox Code Playgroud)

Ajax 请求:

$(".btn.btn-danger").on('click', {function fire_ajax_submit() {
    var str = $(".form-inline.justify-content-center").serialize();

    $.ajax({
        type:"post",
        data:str,
        url:"/search",
        async: false,
        dataType: "json",
        success: function(){
           alert("success");
        }
    });

}
Run Code Online (Sandbox Code Playgroud)

我不想从 ajax succes 部分操作页面,因为当模型被发送到页面时,我已经用 thymeleaf 这样做了。

ajax jquery spring thymeleaf spring-boot

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

Spring Boot 无法反序列化包含 OffsetDateTime 的对象

我正在尝试调用一个休息端点,它返回一个 pojo 对象,如下所示:

public class Process   {
  @JsonProperty("id")
  private String id = null;

  @JsonProperty("processDefinitionId")
  private String processDefinitionId = null;

  @JsonProperty("businessKey")
  private String businessKey = null;

  @JsonProperty("startedAt")
  private OffsetDateTime startedAt = null;

  @JsonProperty("endedAt")
  private OffsetDateTime endedAt = null;

  @JsonProperty("durationInMs")
  private Integer durationInMs = null;

  @JsonProperty("startActivityDefinitionId")
  private String startActivityDefinitionId = null;

  @JsonProperty("endActivityDefinitionId")
  private String endActivityDefinitionId = null;

  @JsonProperty("startUserId")
  private String startUserId = null;

  @JsonProperty("deleteReason")
  private String deleteReason = null;

  //constructors and setters+getters
}
Run Code Online (Sandbox Code Playgroud)

这是调用:

ResponseEntity<Process> responseModel = restTemplate.exchange("http://localhost:8062/processes", HttpMethod.POST, httpEntity, Process.class);
Run Code Online (Sandbox Code Playgroud)

问题是我尝试了一些方法,例如忽略 …

java spring object mapper spring-boot

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

在python中将元组转换为int

我有一个返回元组的查询,我试图将第一个值从该元组转换为 int 但它总是给我这个错误: TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'

我不明白为什么要这样做,因为返回的值如下所示: [(25,)]

这是代码:

cursor.execute("SELECT temp FROM temperatures WHERE datetimetest = ?", [datenow])
    currentTemp = cursor.fetchall()
    print(currentTemp) # this gives me [(25,)]
    convertedTemp = int(currentTemp[0])
Run Code Online (Sandbox Code Playgroud)

python sql type-conversion

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

标签 统计

spring ×2

spring-boot ×2

ajax ×1

java ×1

jquery ×1

mapper ×1

object ×1

python ×1

sql ×1

thymeleaf ×1

type-conversion ×1