怎么把下面代码里编辑treesort改成固定不变@PostMapping(value = "save") @ResponseBody public String saveGcglService(@Validated Gcgl gcGl) { Gcgl entity = new Gcgl(); entity.setItemCode(gcGl.getParentCode()); List<Gcgl> list = gcglService.findList(entity); Gcgl gcgl = list.get(0); HashMap<String, String> map = new HashMap<>(); map.put("codeMin",gcGl.getParentCode() + "000"); map.put("codeMax",gcGl.getParentCode() + "999"); List<Gcgl> gcgls = tjxxDao.maxGcgl(map); if (gcgls==null||gcgls.size()<1) { gcGl.setTreeSort(gcgl.getTreeSort()+".1"); }else { gcGl.setTreeSort(gcgl.getTreeSort()+"."+(gcgls.size()+1)); } gcglService.save(gcGl); return renderResult(Global.TRUE, text("保存成功!")); }
时间: 2024-03-08 09:46:09 浏览: 29
这段代码中的 `treesort` 是在根据父节点的 `treeSort` 属性生成一个新的排序值,这个值是根据当前节点在兄弟节点中的位置生成的。如果你想固定不变,可以将以下代码中的 `gcGl.setTreeSort()` 改为一个固定值,例如:
```
gcGl.setTreeSort("固定值");
```
相关问题
后端代码为 @ResponseBody @ApiOperation(value = "获取作业头盔和作业点视频监控列表数据") @PostMapping(value = "/findVideosByWkps") public MResult findVideosByWkps(@RequestParam("wkps") List<String> wkps){ return cameraService.findVideosByWkps(wkps); }; 前端要怎么传参数
如果你想在前端使用JavaScript向后端发送一个包含@RequestParam注解的List<String>类型参数的POST请求,可以按如下方式进行:
1. 将List<String>转换为字符串。可以使用`JSON.stringify()`方法将List<String>转换为JSON字符串。例如:
```
var wkps = ["A", "B", "C"];
var wkpsStr = JSON.stringify(wkps);
```
2. 将字符串作为请求参数传递。可以使用Ajax方法向后端发送POST请求,并将字符串作为请求参数传递。例如:
```
var url = "/findVideosByWkps";
var data = {wkps: wkpsStr};
$.ajax({
url: url,
type: "POST",
data: data,
success: function(response) {
// 处理响应
},
error: function(jqXHR, textStatus, errorThrown) {
// 处理错误
}
});
```
在上述代码中,`data`对象中的`wkps`属性是@RequestParam注解指定的请求参数名称,其值为转换后的JSON字符串。在后端的Controller中,可以使用@RequestParam注解将该参数映射到List<String>类型的参数中。例如:
```
@RequestMapping(value = "/findVideosByWkps", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取作业头盔和作业点视频监控列表数据")
public MResult findVideosByWkps(@RequestParam("wkps") List<String> wkps) {
return cameraService.findVideosByWkps(wkps);
}
```
在上述代码中,@RequestParam注解指定了请求参数的名称为`wkps`,并将其映射到List<String>类型的参数中。当请求被发送时,请求参数会被解析为一个List<String>对象,可以在方法中直接使用List的方法来获取参数。
@PostMapping @ResponseBody@RequestBody关联关系
@PostMapping和@RequestBody是Spring MVC中的注解,用于处理HTTP POST请求和请求体中的数据。
@PostMapping注解用于将HTTP POST请求映射到特定的处理程序方法。它是@RequestMapping注解的缩写,用于指定HTTP请求的方法类型。
@RequestBody注解用于将HTTP请求正文中的数据绑定到方法的参数上。它告诉Spring MVC框架将请求体中的JSON或XML数据转换为Java对象。
@RequestBody和@PostMapping通常一起使用,以便从HTTP POST请求中获取请求体中的数据并将其转换为Java对象。
以下是一个使用@PostMapping和@RequestBody的示例:
```java
@RestController
@RequestMapping("/user")
public class UserController {
@PostMapping("/addUser")
@ResponseBody
public void addUser(@RequestBody User user){
System.out.println(user);
}
}
```
在上面的示例中,@PostMapping注解将HTTP POST请求映射到addUser()方法。@RequestBody注解将请求体中的数据绑定到User对象上,并将其作为参数传递给addUser()方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)