emm~这里就是记录一下,hibernate的save,如果存在id,就可以直接save,就会覆盖原有的,如果不存在id就会在数据库创建一条新的记录

 

package edu.zut.cs.zutnlp.platform.web.toTable;

import edu.zut.cs.zutnlp.platform.base.web.spring.controller.GenericController;
import edu.zut.cs.zutnlp.platform.dao.toTable.domain.Props;
import edu.zut.cs.zutnlp.platform.dao.toTable.domain.TableMessage;
import edu.zut.cs.zutnlp.platform.toTable.PropsManager;
import edu.zut.cs.zutnlp.platform.toTable.TableMessageManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/Pros")
public class PropsController extends GenericController<Props,Long,PropsManager> {
PropsManager propsManager;

@Autowired
public void setPropsManager(PropsManager propsManager) {
this.propsManager = propsManager;
this.manager=this.propsManager;
}
@Autowired
TableMessageManager tableMessageManager;

@RequestMapping(value = "/list")
@ResponseBody
public List<Props> list(){
List<Props> propsList=new ArrayList<Props>();
propsList=this.propsManager.findAll();
return propsList;
}

@PostMapping(value = "/add",consumes = {"application/json"},produces = {"application/json"})
@ResponseBody
public Boolean add(@RequestBody Props props,
@RequestParam("TableMessageName") String TableMessageName){
TableMessage tableMessage=this.tableMessageManager.findByTableName(TableMessageName);
if (tableMessage!=null){
props.setTableMessage(tableMessage);
this.propsManager.save(props);
}else {
System.out.println(",表为空,不能建立属性在找到之后返回空");
return false;
}
if(this.propsManager.findByPropsName(props.getPrtysName())!=null) {
return true;
}
return false;
}

@ResponseBody
@PostMapping(value = "/delete")
public boolean delete(@RequestParam("PropsName") String PropsName){
Long id=this.propsManager.findByPropsName(PropsName).getId();
if (id==null){
return false;
}else {
this.propsManager.delete(id);
if((this.propsManager.findByPropsName(PropsName)==null)==true){
return true;
}
}
return false;
}

@ResponseBody
@PostMapping(value = "/updata",consumes = "application/json")
public boolean updata(@RequestBody Props props,
@RequestParam("PropsName")String PropsName){
if(this.propsManager.findByPropsName(PropsName)==null)
{
return false;
}else {
this.propsManager.updata(props);
return true;
}
}
@ResponseBody
@PostMapping(value = "/check/{PropsName}")
public Props findProps(@PathVariable @RequestParam String PropsName){
if(this.propsManager.findByPropsName(PropsName)!=null){
return this.propsManager.findByPropsName(PropsName);
}
return null;
}
}
posted on 2018-11-20 11:06  纯正肉包  阅读(266)  评论(0编辑  收藏  举报