笔记(注解)

只是自己简单记录用,并不详细。

@JsonFormat(pattern=“yyyy-MM-dd HH:mm:ss”,timezone = “GMT+8”) 将后台的时间格式化发送到前台
@DateTimeFormat(pattern=“yyyy-MM-dd”) 接受前台的时间格式 传到后台的格式
如果该注解不起作用,可能是jar包倒入错误。

//javaBean
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	private Date reportTime;// 报告时间

@Value("${}") : 在springBoot application.propertites中配置一个属性(key:value)类型

img.server.filepath=/apache-tomcat-7.0.88/webapps/express/img

代码中添加注解

@Service
public class CustomerServiceImpl implements CustomerService{

	@Value("${img.server.filepath}")
	private String uploadPath;	//该uploadPath值则变为application.propertites中配置的路径 /apache-tomcat-7.0.88/webapps/express/img

@RestController : 该注解相当于@ResponseBody + @Controller的集合,一般用于前后端分离时返回json或其他内容到页面。
@Controller : 返回指定页面如最常见的直接跳转jsp等。

@RequestMapping("") :请求地址映射,支持GET和POST
@PostMapping("") : 仅支持post
@GetMapping(") : 仅支持get

@Autowired :spring自动创建对象放到注解所在的类里面,按照类型自动装配
@Resource(name=“”) :按名称装配,找不到在按照类型装配

@SuppressWarnings(“serial”) 忽略警告

猜你喜欢

转载自blog.csdn.net/weixin_42563880/article/details/87776470