java後端接口

@RestController
@RequestMapping(value = "/room/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public int addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @ResponseBody
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public User login(@RequestBody Map<String, Object> params ){
        String username = params.get("username").toString();
        String password = params.get("password").toString();
        return userService.login(username,password);
}

    @ResponseBody
    @RequestMapping("/showall")
    public Map<String, Object> showAll(){
        return userService.showAll();
    }

    @ResponseBody
    @RequestMapping("/delete")
    public int delete(int id){
        return userService.delete(id);
    }

    @ResponseBody
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public int update(@RequestBody User user){
        return userService.update(user);
    }
}

以及使用阿里json解析

@ResponseBody
    @RequestMapping("/getCommentDetail")
    public Map<String,Object> getCommentDetail(@RequestBody String parameters){
        JSONObject jsonObject = JSONObject.parseObject(parameters);
        Integer productId = jsonObject.getInteger("productId");
        Integer offset = jsonObject.getInteger("offset");
        Integer limit = jsonObject.getInteger("limit");
        return adminCommentService.getCommentDetail(productId,offset,limit);
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章