SpringBoot集成Jersey
添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
添加配置
①新建JerseyConfig.java
@Component
@ApplicationPath("/jersey")
public class JerseyConfig extends ResourceConfig{
public JerseyConfig(){
//packages("com.example.study");
register(UserResource.class);
}
}
②输出的json数据格式化(方便使用,不添加也可访问)
jackson:
default-property-inclusion: non_null
serialization:
indent-output: true
date-format: yyyy-MM-dd HH:mm:ss
parser:
allow-missing-values: true
测试使用
新建UserResource.java
@Component
@Path("/users")
public class UserResource {
@Autowired
private UserMappers userMapper;
@GET
@Produces(MediaType.APPLICATION_JSON)
public User get(){
List<User> users = userMapper.selectAll();
return users.get(0);
}
}
访问
http://localhost:8088/jersey/users
其它
这是我使用了jersey的项目,其余配置还有:
mybatis,mybatis generator
slf4+logback
thymeleaf模板引擎
alibaba的druid数据库连接池
https://github.com/Lifan1998/study
供初学者参考。