@Data
@ToString
@Document(collection =
"
cms_config
"
)
public class CmsConfig {
@Id
private String id;//主键
private String name;//数据模型的名称
private List<CmsConfigModel> model;//数据模型项目
}
@Data
@ToString
public class CmsConfigModel {
private String key;//主键
private String name;//项目名称
private String url;//项目url
private Map mapValue;//项目复杂值
private String value;//项目简单值
}
@Api(value
=
"
cms配置管理接口
"
,description =
"
cms配置管理接口,提供数据模型的管理、查询接口
"
)
public interface CmsConfigControllerApi {
@ApiOperation(
"
根据id查询CMS配置信息
"
)
public CmsConfig getmodel(String id);
}
public interface CmsConfigRepository extends MongoRepository<CmsConfig,String> {
}
@Service
public class CmsConfigService {
@Autowired
CmsConfigRepository cmsConfigRepository;
//根据id查询配置管理信息
public CmsConfig getConfigById(String id){
Optional<CmsConfig> optional =
cmsConfigRepository
.findById(id);
if(optional.isPresent()){
CmsConfig cmsConfig
=
optional.
get();
return cmsConfig;
}
return null;
}
}
@RestController
@RequestMapping(
"
/cms/config
"
)
public class CmsConfigController implements CmsConfigControllerApi {
@Autowired
CmsConfigService cmsConfigService;
@Override
@GetMapping(
"
/getmodel/{id}
"
)
public CmsConfig getmodel(@PathVariable(
"
id
"
) String id) {
return cmsConfigService.
getConfigById(id);
}
}
<dependency>
<groupId>com.squareup
.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
...
public class ManageCmsApplication {
public static void main(String[] args) {
SpringApplication.run(ManageCmsApplication.class,args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
}
}
@Test
public void testRestTemplate(){
ResponseEntity<Map> forEntity
=
restTemplate.
getForEntity(
"
http://localhost:31001/cms/config/get/5a791725dd573c3574ee333f
"
,
Map
.class);
System.out.
println(forEntity);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |