结果展示:
JSP中:
<tr>
<td style="width: 20%">跳转链接:<span style="color: red">*</span></td>
<td style="width: 80%"><input style="width: 80%"
name="redirict_url" id="redirict_url" class="mini-combobox"
required="true" textField="value" valueField="value"
showNullItem="true" nullItemText="请选择" emptyText="请选择"
/></td>
</tr>
js中:
$.ajax({
type : 'POST',
url : ctx + "/planDef/redirictUrl.do",
success : function(data) {
mini.getbyName("redirict_url").setData(mini.encode(data));
}
});
controller中:
@RequestMapping("/{key}.do")
@ResponseBody
public Object queryKVInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("key") String key)
throws Exception {
logger.info("DefKVController.queryKVInfo.into...");
logger.info("请求数据:[{}]", key);
if (StringUtils.isBlank(key)) {
throw new BusinessException("key值为空");
}
List<DefKVInfoResDto> result = keyValueService.queryKVInfo(key);
logger.info("DefKVController.queryKVInfo.out...");
return result;
}
service中:
public List<DefKVInfoResDto> queryKVInfo(String key);
serviceImpl中:
@Override
public List<DefKVInfoResDto> queryKVInfo(String key) {
DefKvExample defKvExample = new DefKvExample();
defKvExample.createCriteria().andKEqualTo(key);
List<DefKv> list = defKvMapper.selectByExample(defKvExample);
if (list.size() == 0 || list == null) {
throw new BusinessException("未查询到有效的value值");
}
List<DefKVInfoResDto> kvList = new ArrayList<DefKVInfoResDto>();
for (DefKv defKv : list) {
DefKVInfoResDto resDto = new DefKVInfoResDto();
resDto.setKey(defKv.getK());
resDto.setValue(defKv.getV());
resDto.setRemark(defKv.getR());
kvList.add(resDto);
}
return kvList;
}
DefKVInfoResDto 中:
public class DefKVInfoResDto {
private String key;
private String value;
private String remark;
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;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
mapper中:
List<DefKv> selectByExample(DefKvExample example);
mapper.xml中:
<select id="selectByExample" parameterType="com.hualife.bit.modules.sys.dao.mybatis.entity.DefKvExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon May 14 09:58:40 GMT+08:00 2018.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from def_kv
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="com.hualife.bit.modules.sys.dao.mybatis.entity.DefKvExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon May 14 09:58:40 GMT+08:00 2018.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from def_kv
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon May 14 09:58:40 GMT+08:00 2018.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>