SpringBoot-base

springboot 基础

注解

@CrossOrigin 跨域处理

json处理

springboot集成jackson工具

简单使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//忽略编译该参数为json    
@JsonIgnore
public String getPassword() {
return password;
}
//bean to json
ObjectMapper mapper = new ObjectMapper();
User user=new User();
String jsonstr=mapper.writeValueAsString(user);

@RestController //返回实体类自动转json
public class UserControl {
@RequestMapping(value = "register", method = RequestMethod.POST)
public Msg userReg(@RequestBody User user) { //@RequestBody 请求参数为json自动转换实体类
return user;
}
}