@ApiOperation(value = "保存用户号码") @PutMapping("/saveUserPhone") public JsonData<String> saveUserPhone(@RequestParam("code") String code,@RequestParam("encryptedData") String encryptedData, @RequestParam("iv") String iv)前端如何传值
时间: 2024-01-28 22:03:42 浏览: 153
前端可以使用 `axios` 或者 `fetch` 等方式发送 PUT 请求,将 `code`、`encryptedData` 和 `iv` 作为请求参数传递给后端。示例代码如下:
```javascript
axios.put('/saveUserPhone', {
params: {
code: 'xxx',
encryptedData: 'xxx',
iv: 'xxx'
}
}).then(response => {
console.log(response.data);
}).catch(error => {
console.error(error);
});
```
在上面的代码中,`axios.put` 方法表示发送一个 PUT 请求,`/saveUserPhone` 是请求的 API 地址,`params` 对象中包含了 `code`、`encryptedData` 和 `iv` 三个请求参数。后端可以通过 `@RequestParam` 注解获取这些参数的值。
相关问题
@Data public class Dish implements Serializable { private Long id;//主键 private String name;//菜品名称 private Long categoryId;//所属分类id private BigDecimal price;//菜品价格 private String code;//商品码 private String image;//图片 private String description;//描述信息 private Integer status;//0 停售 1 起售 private Integer sort;//顺序 @TableField(fill = FieldFill.INSERT) @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; @TableField(fill = FieldFill.INSERT_UPDATE) @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; @TableField(fill = FieldFill.INSERT) private Long createUser; @TableField(fill = FieldFill.INSERT_UPDATE) private Long updateUser; //===================数据表中不存在下面字段,仅仅用于页面显示=================== //菜品口味列表 @TableField(exist = false) private List<DishFlavor> flavors = new ArrayList<>(); //菜品分类名称 @TableField(exist = false) private String categoryName; @TableField(exist = false) private Integer copies; }利用springboot分页查询
可以使用Spring Data JPA提供的PagingAndSortingRepository接口来实现分页查询,具体步骤如下:
1.在DishRepository中继承PagingAndSortingRepository接口。
```
public interface DishRepository extends PagingAndSortingRepository<Dish, Long> {
}
```
2.在DishService中定义一个方法来实现分页查询。
```
@Service
public class DishService {
@Autowired
private DishRepository dishRepository;
public Page<Dish> findDishByPage(int pageNum, int pageSize) {
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
Pageable pageable = PageRequest.of(pageNum - 1, pageSize, sort);
return dishRepository.findAll(pageable);
}
}
```
3.在DishController中调用该方法。
```
@RestController
@RequestMapping("/dishes")
public class DishController {
@Autowired
private DishService dishService;
@GetMapping("/page")
public Page<Dish> findDishByPage(@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "10") int pageSize) {
return dishService.findDishByPage(pageNum, pageSize);
}
}
```
其中,PageRequest.of()方法用于创建分页请求对象,findAll()方法用于执行分页查询操作。在方法中还可以设置排序方式,例如按照创建时间倒序排序。
axios({ method: 'get', url: '/BookShopSystem_war/getQueryBook/' + bookName@GetMapping("/getQueryBook/{bookName}") @ResponseBody public Map<String, Object> getQueryBook(@PathVariable("bookName") String bookName) { List<Book> queryBookList = bookService.getQueryBook(bookName); HashMap<String, Object> result = new HashMap<>(); result.put("code", 0); result.put("msg", "success"); result.put("data", queryBookList); return result; }<select id="getQueryBook" parameterType="String" resultMap="bookResult"> select * from book where book_name like CONCAT('%',#{bookName},'%') </select>传递的参数会乱码
这个问题可能是因为没有设置正确的编码格式导致的。你可以尝试在请求头中添加 "Content-Type": "application/json;charset=UTF-8",把参数以 JSON 格式传递。另外,在后端的 Controller 中,可以添加注解 @RequestMapping(produces = "application/json;charset=UTF-8") 来指定返回的数据编码格式。同时,还可以在 MyBatis 的配置文件中添加 <setting name="defaultCharset" value="UTF-8"/> 来设置默认的编码格式。
阅读全文
相关推荐

















