mapper层代码
package com.yb.nc.mapper;
import com.yb.nc.vo.NameList;
import com.yb.nc.vo.StudyMode;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Mapper
public interface StudyModeMapper {
//查询
public List ListnbCode(String nbCode);
//修改
public int update(StudyMode studyMode);
//增加
public int add(NameList nameList);
//删除
public Integer delent(String nbCode);
}
service层代码
package com.yb.nc.service;
import com.yb.nc.mapper.StudyModeMapper;
import com.yb.nc.vo.NameList;
import com.yb.nc.vo.StudyMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class StudyModeService {
@Autowired(required = false)
StudyModeMapper studyModeMapper;
//查询
public List ListnbCode(String nbCode ) {
return studyModeMapper.ListnbCode(nbCode);
}
//修改
public int update(StudyMode studyMode){
return studyModeMapper.update(studyMode);
}
//增加
public int add(NameList nbCode) {
return studyModeMapper.add(nbCode);
}
//删除名单
public Integer delent(String nbCode){
return studyModeMapper.delent(nbCode);
}
}
controller层代码
package com.yb.nc.controllers;
import com.yb.nc.service.StudyModeService;
import com.yb.nc.util.JsonResult;
import com.yb.nc.vo.NameList;
import com.yb.nc.vo.StudyMode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.List;
@RestController
@Api(tags = "配置")
@EnableSwagger2
/**
* @Description: java类作用描述
* @Author: yc
* @CreateDate: 2019/7/3 0003 上午 11:23
* @UpdateUser: yc
* @UpdateDate: 2019/7/3 0003 上午 11:23
* @UpdateRemark: 修改内容
* @Version: 1.0
*/
public class StudyController {
private static final Logger log = LogManager.getLogger(StudyController.class);
@Autowired
StudyModeService studyModeService;
/**
* @Description: 查询
* @Author: yc
* @CreateDate: 2019/7/3 0003 上午 11:24
* @UpdateUser: yc
* @UpdateDate: 2019/7/3 0003 上午 11:24
* @UpdateRemark: 修改内容
* @Version: 1.0
*/
@ApiOperation(value = "通过NB序列号查询配置参数",notes = "通过NB序列号查询配置参数")
@RequestMapping(value = "/nb/list",method = RequestMethod.POST)
public ResponseEntity list(String nbCode){
JsonResult jsonResult = new JsonResult();
//查询
List studyModes = studyModeService.ListnbCode(nbCode);
//返回
jsonResult.setCode("成功");
jsonResult.setResult(studyModes);
return ResponseEntity.ok(jsonResult);
}
/**
* @Description: 修改
* @Author: yc
* @CreateDate: 2019/7/3 0003 上午 11:23
* @UpdateUser: yc
* @UpdateDate: 2019/7/3 0003 上午 11:23
* @UpdateRemark: 修改内容
* @Version: 1.0
*/
@ApiOperation(value = "用户修改NB运行参数",notes = "用户修改NB运行参数")
@RequestMapping(value = "/nb/update",method = RequestMethod.PUT)
public ResponseEntity update(StudyMode studyMode){
JsonResult jsonResult = new JsonResult();
//修改
studyModeService.update(studyMode);
//返回
jsonResult.setCode("修改成功:"+studyMode);
return ResponseEntity.ok(jsonResult);
}
/**
* @Description: 添加
* @Author: yc
* @CreateDate: 2019/7/3 0003 上午 11:23
* @UpdateUser: yc
* @UpdateDate: 2019/7/3 0003 上午 11:23
* @UpdateRemark: 修改内容
* @Version: 1.0
* @return
*/
@ApiOperation(value = "1.添加白名单,2.添加忽略名单,3.添加阻拦名单",notes = "添加名单",httpMethod = "POST")
@RequestMapping(value = "/nb/addlist",method = RequestMethod.POST)
public ResponseEntity add(NameList nbCode){
JsonResult js = new JsonResult();
//添加
studyModeService.add(nbCode);
//返回
js.setCode("添加成功:"+nbCode);
//日志记录
log.debug("添加成功,nameList:" + nbCode);
return ResponseEntity.ok(js);
}
@ApiOperation(value = "删除名单",notes = "删除名单",httpMethod = "DELETE")
@RequestMapping(value = "nb/delent",method = RequestMethod.DELETE)
public ResponseEntity delent1(@RequestParam(value = "nbCode") String nbCode){
JsonResult js = new JsonResult();
studyModeService.delent(nbCode);
js.setCode("删除成功:"+nbCode);
log.debug("删除成功:"+nbCode);
return ResponseEntity.ok(js);
}
}
json(不需要者可以忽略)实体类
package com.yb.nc.util;
/**
* 接口返回包装类
*
*/
public class JsonResult {
private String code=null;
private Object result = null;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Object getResult() {
return result;
}
public void setResult(Object result) {
this.result = result;
}
}
SQL
//增
INSERT INTO roster(nb_code,roster_type,roster_ip,roster_mac)VALUES (#{nbCode},#{type},#{ipAddress},#{macAddress})
//查
//修改
UPDATE run_parameter set single =#{single},learning =#{learning},ctime=#{ctime},btime=#{btime},ltime=#{ltime} where nb_code =#{nbCode}
//删除
delete from roster where nb_code = #{nbCode}