Commit 28027150 authored by liling's avatar liling

add code

parent bed17023
package cn.com.duia.dmp.common.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel("人群包配置详情表")
public class AppCategoryappInterestDto {
@ApiModelProperty("应用类别")
private String appCategory;
@ApiModelProperty("应用兴趣")
private List<String> appInterest;
public String getAppCategory() {
return appCategory;
}
public void setAppCategory(String appCategory) {
this.appCategory = appCategory;
}
public List<String> getAppInterest() {
return appInterest;
}
public void setAppInterest(List<String> appInterest) {
this.appInterest = appInterest;
}
}
...@@ -19,4 +19,12 @@ public class AppEntity { ...@@ -19,4 +19,12 @@ public class AppEntity {
public void setAppId(Long appId) { public void setAppId(Long appId) {
this.appId = appId; this.appId = appId;
} }
@Override
public String toString() {
return "AppEntity{" +
"appName='" + appName + '\'' +
", appId=" + appId +
'}';
}
} }
package cn.com.duia.dmp.common.util;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
* ClassName:Result <br/>
* ajax请求结果封装类 <br/>
* Date: 2017年5月10日 下午7:26:16 <br/>
*
* @author zhanglihui
* @version
* @param <K>
* @since JDK 1.6
* @see
*/
@ApiModel(value = "请求结果封装")
public class Result<K> implements Serializable {
private static final long serialVersionUID = -1467576157657126613L;
@ApiModelProperty(value = "请求是否成功", required = true)
private Boolean success;
@ApiModelProperty(value = "错误码")
private String errorCode;
@ApiModelProperty("响应信息")
private String desc;
@ApiModelProperty("请求成功时的响应数据")
private transient K data;
/**
* 构造成功响应
*
* @param data
* @param <K>
* @return Result
*/
public static <K> Result<K> successResult(K data) {
Result<K> result = new Result<>();
result.success = Boolean.TRUE;
result.data = data;
return result;
}
/**
* 构造成功响应
*
* @param <K>
* @return Result
*/
public static <K> Result<K> successResult() {
Result<K> result = new Result<>();
result.success = Boolean.TRUE;
return result;
}
/**
* 构造失败响应
*
* @param message
* @param errorCode
* @return Result
*/
public static <K> Result<K> failResult(String message, String errorCode) {
Result<K> result = new Result<>();
result.success = Boolean.FALSE;
result.desc = message;
result.errorCode = errorCode;
return result;
}
/**
* 构造失败响应
*
* @param errorCode
* @param e
* @return Result
*/
public static <K> Result<K> failResult(String errorCode, Throwable e) {
Result<K> result = new Result<>();
result.success = Boolean.FALSE;
result.desc = e.getMessage();
result.errorCode = errorCode;
return result;
}
/**
* @return success
*/
public Boolean getSuccess() {
return success;
}
/**
* @param success
*/
public void setSuccess(Boolean success) {
this.success = success;
}
/**
* desc.
*
* @return the desc
*/
public String getDesc() {
return desc;
}
/**
* desc.
*
* @param desc the desc to set
*/
public void setDesc(String desc) {
this.desc = desc;
}
/**
* data.
*
* @return the data
*/
public K getData() {
return data;
}
/**
* data.
*
* @param data the data to set
*/
public void setData(K data) {
this.data = data;
}
/**
* errorCode.
*
* @return the errorCode
*/
public String getErrorCode() {
return errorCode;
}
/**
* errorCode.
*
* @param errorCode the errorCode to set
*/
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}
package cn.com.duia.dmp.common.util;
import static cn.com.duia.dmp.common.util.SimpleStringFormat.format;
/**
* ClassName:ResultUtil <br/>
* 请求结果构建类 <br/>
* Date: 2017年5月10日 下午7:29:22 <br/>
* @author zhanglihui
* @version
* @since JDK 1.6
* @see
*/
public class ResultUtil {
private ResultUtil() {
throw new IllegalStateException("Utility class");
}
/**
* 构造一个失败的返回结果.
*
* @param <T> the generic type
* @param desc 错误描述
* @param errorCode
* @param args
* @return 失败的返回结果
*/
public static <T> Result<T> fail(String desc, String errorCode, Object... args)
{
Result<T> result = new Result<>();
result.setSuccess(false);
result.setDesc(format(desc, args));
result.setErrorCode(errorCode);
return result;
}
/**
* 构造一个成功的返回结果.<br>
*
* @param <T> the generic type
* @param desc 成功描述信息
* @param args
* @return Result对象
*/
public static <T> Result<T> successWithDesc(String desc, Object... args)
{
Result<T> result = new Result<>();
result.setSuccess(true);
result.setDesc(format(desc, args));
return result;
}
/**
* 构造一个成功的返回结果.
*
* @param <T> the generic type
* @param t 数据
* @param desc 描述信息
* @param args
* @return ResultDO对象带有Message
*/
public static <T> Result<T> success(T t, String desc, Object... args)
{
Result<T> result = new Result<>();
result.setData(t);
result.setDesc(format(desc, args));
result.setSuccess(true);
return result;
}
/**
*
* <一句话功能描述>
* @param t
* @return xx
*/
public static <T> Result<T> successWithData(T t)
{
Result<T> result = new Result<>();
result.setData(t);
result.setSuccess(true);
return result;
}
/**
*
* <一句话功能描述>
* @return xx
*/
public static <T> Result<T> success()
{
Result<T> result = new Result<>();
result.setSuccess(true);
return result;
}
}
package cn.com.duia.dmp.common.util;
/**
* ClassName:SimpleStringFormat <br/>
* 简单的字符串模板实现
* 支持 {} 替代符
* Date: 2016年8月11日 下午2:33:26 <br/>
* @author zhanglihui
* @version
* @since JDK 1.6
* @see
*/
public class SimpleStringFormat {
private SimpleStringFormat() {
throw new IllegalStateException("Utility class");
}
/**
* 格式化String
*
* @param template
* @param args
* @return formatString
*/
public static String format(String template, Object... args) {
String format = String.valueOf(template); // null -> "null"
if (args == null || args.length == 0) {
return format;
}
// start substituting the arguments into the '%s' placeholders
StringBuilder builder = new StringBuilder(template.length() + 16 * args.length);
int templateStart = 0;
int i = 0;
while (i < args.length) {
int placeholderStart = template.indexOf("{}", templateStart);
if (placeholderStart == -1) {
break;
}
builder.append(template.substring(templateStart, placeholderStart));
builder.append(args[i++]);
templateStart = placeholderStart + 2;
}
builder.append(template.substring(templateStart));
// if we run out of placeholders, append the extra args in square braces
if (i < args.length) {
builder.append(" [");
builder.append(args[i++]);
while (i < args.length) {
builder.append(", ");
builder.append(args[i++]);
}
builder.append(']');
}
return builder.toString();
}
}
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<select id="selectApp" resultType="cn.com.duia.dmp.common.entity.AppEntity"> <select id="selectApp" resultType="cn.com.duia.dmp.common.entity.AppEntity">
SELECT SELECT
app_id AS id, app_id AS appId,
slot_name AS appNames slot_name AS appName
FROM tb_slot FROM tb_slot
</select> </select>
......
...@@ -16,6 +16,7 @@ description = 'web' ...@@ -16,6 +16,7 @@ description = 'web'
dependencies { dependencies {
compile project(':dmp-core') compile project(':dmp-core')
compile project(':dmp-dal') compile project(':dmp-dal')
compile project(':dmp-common')
//swagger //swagger
compile('io.springfox:springfox-swagger2') compile('io.springfox:springfox-swagger2')
compile('io.springfox:springfox-swagger-ui') compile('io.springfox:springfox-swagger-ui')
......
...@@ -10,13 +10,13 @@ import org.springframework.context.annotation.ComponentScan; ...@@ -10,13 +10,13 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
//@EnableSwagger2 @EnableSwagger2
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@ImportResource({ "classpath:/spring/spring.xml" }) @ImportResource({ "classpath:/spring/spring.xml" })
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableCircuitBreaker @EnableCircuitBreaker
@EnableDuibaFeignClients(basePackages = { "cn.com.duia" }) @EnableDuibaFeignClients(basePackages = { "cn.com.duia" })
@ComponentScan(basePackages = {"cn.com.duiba.*"}) @ComponentScan(basePackages = {"cn.com.duia"})
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
......
package cn.com.duia.dmp.controller; package cn.com.duia.dmp.controller;
import cn.com.duia.dmp.common.dto.AppCategoryappInterestDto;
import cn.com.duia.dmp.common.entity.AppEntity; import cn.com.duia.dmp.common.entity.AppEntity;
import cn.com.duia.dmp.common.util.Result;
import cn.com.duia.dmp.common.util.ResultUtil;
import cn.com.duia.dmp.core.service.AppService; import cn.com.duia.dmp.core.service.AppService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.List;
@RestController @RestController
public class TestController { public class TestController {
//@Resource @Resource
//private AppService appService; private AppService appService;
// @ApiOperation(value = "第一个接口", httpMethod = "GET") @ApiOperation(value = "第一个接口", httpMethod = "GET")
@RequestMapping(value = "/hello", method = RequestMethod.GET) @RequestMapping(value ="/querydmp")
public List<AppEntity> hello(){ public Result hello(){
return new ArrayList<>(); Map<String,List<String>> am = new HashMap<>();
//return appService.selectApp(); List<AppCategoryappInterestDto> a = new ArrayList<>();
AppCategoryappInterestDto d = new AppCategoryappInterestDto();
d.setAppCategory("电商");
d.setAppInterest(Arrays.asList("网购","海淘","网上购物"));
AppCategoryappInterestDto c = new AppCategoryappInterestDto();
c.setAppCategory("社交");
c.setAppInterest(Arrays.asList("QQ","微信","飞秋"));
a.add(d);
a.add(c);
am.put("电商",Arrays.asList("网购","海淘","网上购物"));
am.put("社交",Arrays.asList("QQ","微信","飞秋"));
return ResultUtil.successWithData( a) ;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment