<!-- Spring Boot 父依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencies>
<!-- Spring Boot web依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by Angela on 2017/4/20.
*/
@SpringBootApplication
public class Application {
public static void main(String[] args){
//springboot 入口
SpringApplication.run(Application.class,args);
}
}
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</artifactId> </dependency>
package com.demo.config.jersey;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;
/**
* Created by Angela on 2017/4/20.
*/
@Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
//构造函数,在这里注册需要使用的内容,(过滤器,拦截器,API等)
}
}
spring: name: local server: port: 8081
package com.demo.web;
import com.demo.model.City;
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Created by Angela on 2017/4/20.
*/
@Component
@Path("/demo")
public class Demo {
//path注解指定路径,get注解指定访问方式,produces注解指定了返回值类型,这里返回JSON
@Path("/city")
@GET
@Produces(MediaType.APPLICATION_JSON)
public City get(){
City city = new City();
city.setId(1L);
city.setCityName("beijing");
city.setCityCode("001");
System.out.println(city.toString());
return city;
}
}
package com.demo.config.jersey;
import com.demo.web.Demo;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;
/**
* Created by Angela on 2017/4/20.
*/
@Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
//注册类的方式
// register(Demo.class);
//注册包的方式
packages("com.demo.web");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有