springboot 使用常用注解

找到方法封装成json格式

@RestController = @Controller+@ResponseBody
//一个组合注解,用于快捷配置启动类,springboot启动主入口

@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan
//封装地址,适用所有提交方法
@RequestMapping

//封装地址,适用get,post,put,delete提交方法
@GetMapping @PostMapping @PutMapping @DeleteMapping

Jackson处理相关自动
//指定字段不返回(注解后此属性不会返回给前端)
@JsonIgnore
//指定日期格式
@JsonFormat(pattern=“yyyy-mm-dd hh:mm:ss",lacale="zh,timezone="GTF-8")
//空字段不返回(此属性为空不会返回给前端)
@JsonInclude(Include.NON_NULL)
//指定别名(防止黑客攻击)
@JsonProperty

默认按照类型装配,使用名称装配结合@Qualifier
@Autowired
@Autowired()@Qualifier("**")
默认按照名称装配,找不到匹配名称按类型装配
@Resource(name=“**”)

springboot文件上传
(1)静态页面直接访问:localhost:8080/index.html
注意点:
如果直接访问html页面,则需要把html放在sringboot默认加载文件夹
(2)MultipartFile对象的transferTo方法,用于文件保存(效率和操作高)

还有很多注解,后期会陆续加上^_^!
posted @ 2019-10-29 14:21  让人生留下足迹  阅读(394)  评论(0编辑  收藏  举报