mysql 时间格式化:
date_format(i.createTime,"%Y-%m-%d %H:%i:%S") createTime
备注(只适用简单查询,比如做非空判断就比较麻烦)
@Select("select i.id,i.title,i.content,i.image,i.createTime,i.author,t.name from info i,info_type t where typeId = #{typeId})")
List
备注(适用比较复杂的查询)
xml 常用的返回两种类型
接收接口URL参数
前端接口传参
var typeId = $('#mdoelTypeEdtSearch').val();
admin.jsonReq(RD.url + 'kayu/product/copyAll?typeId='+ typeId +'', JSON.stringify(idData), function (data) {
layer.closeAll('loading');
if (data.code == 200) {
layer.msg(data.msg, { icon: 1 });
table.reload("roleTable");
} else {
layer.msg(data.msg, { icon: 2 });
}
}, 'post');
后端接收typeId传参
@PostMapping("copyAll")
public JsonResult copyAll(@RequestBody List ids){
String typeId = request.getParameter("typeId");//接收接口URL参数
Integer typeIdInt = null;
if (StringUtil.isNotNull(typeId)) {
typeIdInt = Integer.parseInt(typeId);
}
return productService.copyAll(ids,typeIdInt);
}
复制数据
ProductService
public JsonResult copyAll(List ids, Integer typeId) {
List proList = productMapper.selectBatchIds(ids);//找出所有ids的列
if (typeId != null) {
for (Product pro : proList) {
pro.setTypeId(typeId);//更改typeId为传过来的值typeId
}
}
productMapper.insertBatch(proList);
return JsonResult.ok("复制成功!");
}
xml
insert into product(title,content,createTime,updateTime,typeId,model,status,title02,title03,content2,content3) VALUES
(#{item.title},#{item.content},#{item.createTime},#{item.updateTime},#{item.typeId},#{item.model},
#{item.status},#{item.title02},#{item.title03},#{item.content2},#{item.content3}
)
返回一个对象 非list
public JsonResult getWebUrl(Setting setting){
EntityWrapper entityWrapper = new EntityWrapper<>();//mybatis plus 条件构造器
entityWrapper.eq("parent_id",setting.getId());
List list = settingMapper.selectList(entityWrapper);// 找到符合这个条件的所有数据
JSONObject jsonObject = new JSONObject();
for (int i = 0; i < list.size(); i++) {
jsonObject.put(list.get(i).getName(), list.get(i).getValue());
}
return JsonResult.ok("查询成功").put("data",jsonObject);
}
前台接收示列
返回JsonResult list
public JsonResult getWebUrl(Setting setting){
EntityWrapper entityWrapper = new EntityWrapper<>();
entityWrapper.eq("parent_id",setting.getId());
List list = settingMapper.selectList(entityWrapper);
List jsonList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(list.get(i).getName(), list.get(i).getValue());
jsonList.add(jsonObject);
}
return JsonResult.ok("查询成功").put("data",jsonList);
}
前台接收示列