发表于: 2020-09-15 21:44:58
1 1367
今天完成的事情:写用户表假数据。复习了些内容。
明天计划的事情:明天继续假数据。看看能不能多余时间开发接口
遇到的问题:暂无
收获:
假数据,实体类用的内部类形式,因为还没方案评审,所以还没建表。
@Api(value = "用户controller",tags = "用户操作接口")
@RequestMapping("/a/m")
@RestController
public class UserManageController {
private long time = System.currentTimeMillis();
@ApiOperation("按条件搜索用户")
@GetMapping("/manager/search")
public List<User> create(@ApiParam("昵称") @RequestParam String nikeName,@ApiParam("id") @RequestParam int id,@ApiParam("年级") @RequestParam int grade,
@ApiParam("手机号") @RequestParam String phone,@ApiParam("邮箱") @RequestParam int email,@ApiParam("状态") @RequestParam int status,
@ApiParam("逆袭豆始") @RequestParam int beanStartAt ,@ApiParam("逆袭豆末") @RequestParam int beanEndAt,@ApiParam("区域") @RequestParam String location){
List<User> result = new ArrayList<User>();
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
return result;
}
@ApiOperation("用户列表")
@GetMapping("/manager/list")
@ResponseBody
public List<User> list(@ApiParam("当前页") @RequestParam int page,
@ApiParam("每页多少条") @RequestParam int size){
List<User> result = new ArrayList<User>();
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
result.add(new User(9527,"李四","abfa@ff.com","北京海淀区",8,200,"18125486987","创建者","修改者",time,time,0));
result.add(new User(9528,"张三三","grw@ff.com","广东佛山",9,111,"18125486987","创建者","修改者",time,time,1));
result.add(new User(968,"李思思","gjtyj@ff.com","浙江杭州",11,520,"18125486987","创建者","修改者",time,time,0));
result.add(new User(900,"王磊","dadaf@ff.com","成都武侯区",12,524,"18125486987","创建者","修改者",time,time,1));
return result;
}
@ApiOperation("用户详情")
@GetMapping("/manager/{id}")
public User findById(@PathVariable Long id){
return new User(250,"甄子丹","abfa@ff.com","北京海淀区",7,200,"18125486987","创建者","修改者",time,time,1);
}
@ApiOperation("用户冻结")
@PutMapping("/manager")
public String deleteById(@ApiParam("状态,0为冻结,1为解除")@RequestParam int status,@ApiParam("用户id")@RequestParam int id){
return "冻结用户成功!";
}
@Controller和@RestController区别
2.使用@RestController注解时 返回内容示例 使用@Controller注解时返回视图页面
3.在一个方法中如果你是要返回一个视图页面,使用@Controller注解
4.在一个方法中要返回一段内容示例,则可以使用@RestController注解或者使用@Controller注解 然后再具体方法上使用@ResponseBody注解
@PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中
lombok使用
是一个代码生成库,可以减少编写实体类的getter和setter的方法编写,以及构造方法等,只用在类上加注解就行。
1.安装lombok插件
1)开IntelliJ IDEA后点击菜单栏中的File-->Settings-->plugins--->搜索lombok --> install
2) 配置注解处理器
Settings设置页面,我们点击Build,Execution,Deployment-->选择Compiler-->选中Annotation Processors,然后在右侧勾选Enable annotation processing即可。
2.使用
1)引入依赖
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
</dependencies>
2)使用注解
@Getter自动生成 getter 方法
@NoArgsConstructor: 自动生成无参数构造函数。
@AllArgsConstructor: 自动生成全参数构造函数。
评论