key + value形式
controller:
@RestController
@RequestMapping("pub")
public class PubController {
@ApiOperation("key+value形式")
@GetMapping("info")
public JsonData<List<PubListVo>> info(
@ApiParam(value = "id", required = true) @RequestParam("id") Long id
) {
List<PubListVo> pubListVoList = service.info(id);
return JsonData.buildSuccess(pubListVoList);
}
}
service:
public interface service {
List<PubListVo> info(Long id);
}
serviceImpl:
@Service
public class serviceImpl implements service {
@Autowired
private Mapper mapper;
@Override
public List<PubListVo> info(Long id) {
List<PubListVo> infoList = mapper.info(id);
infoList.forEach(obj->{
obj.setValue(obj.getKey()+","+obj.getValue());
});
return infoList;
}
}
mapper:
public interface mapper extends BaseMapper<DO> {
List<PubListVo> info(Long id);
}
<resultMap id="infoMap" type="com.vo.PubListVo">
<id column="key" property="key"/>
<result column="value" property="value"/>
</resultMap>
<select id="info" resultMap="infoMap">
SELECT
ta.id `value`,
ta.name `key`
FROM table_a ta
<where>
<if test="id!=null and id!=''">
And ta.id=#{id}
</if>
</where>
</select>
公共响应:
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Objects;
@ApiModel(value = "PubListVo对象", description = "下拉框数据集信息")
public class PubListVo implements Serializable {
public PubListVo() {
}
public PubListVo(String key, String value) {
this.key = key;
this.value = value;
}
@ApiModelProperty(value = "下拉框的key", example = "1")
private String key;
@ApiModelProperty(value = "下拉框的value", example = "中国")
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "PubListVo{" +
"key='" + key + '\'' +
", value='" + value + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PubListVo vo = (PubListVo) o;
return key.equals(vo.key) &&
value.equals(vo.value);
}
@Override
public int hashCode() {
return Objects.hash(key, value);
}
}