1.创建Java实体类
package com.example.server;
public class SceneService {
private String servicename;
private ServiceTypeEnum servicetype;
private String serviceurl;
public String getServicename() {
return servicename;
}
public void setServicename(String servicename) {
this.servicename = servicename;
}
public ServiceTypeEnum getServicetype() {
return servicetype;
}
public void setServicetype(ServiceTypeEnum servicetype) {
this.servicetype = servicetype;
}
public String getServiceurl() {
return serviceurl;
}
public void setServiceurl(String serviceurl) {
this.serviceurl = serviceurl;
}
}
2.创建Mapper接口
package com.example.server;
import org.apache.ibatis.annotations.*;
import java.util.Map;
@Mapper
public interface SceneServicesMapper {
//按名称查询
@Select("select * from sys_scene_services_tb where servicename=#{name}")
public SceneService selectServiceByName(String servicename);
//查询服务列表
@Select("select * from sys_scene_services_tb")
@MapKey("servicename")
public Map<String,SceneService> selectServices();
//删除
@Delete("delete from sys_scene_services_tb where servicename=#{name}")
public int deleteService(String servicename);
//修改
@Update("update sys_scene_services_tb set servicetype=#{servicetype}, serviceurl=#{serviceurl} where servicename=#{servicename}")
public int updateService(SceneService sceneService);
//插入
@Insert("insert into sys_scene_services_tb(servicename,servicetype,serviceurl) values(#{servicename},#{servicetype},#{serviceurl})")
public int insertService(SceneService sceneService);
}
3. 创建控制类Controller
package com.example.server.controller;
import com.example.server.SceneService;
import com.example.server.SceneServicesMapper;
import net.minidev.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
public class SceneServicesController {
@Autowired
SceneServicesMapper sceneServicesMapper;
//查询
@RequestMapping("/get/{name}")
public SceneService getServiceByName(@PathVariable("name") String name) {
return sceneServicesMapper.selectServiceByName(name);
}
// 查询服务列表
@RequestMapping("/services")
public Map<String,SceneService> getServices(){
return (Map<String, SceneService>) sceneServicesMapper.selectServices();
}
//删除
@RequestMapping("/delete/{name}")
public String deleteService(@PathVariable("name") String name){
sceneServicesMapper.deleteService(name);
return "删除成功!";
}
//插入
@RequestMapping("/insert")
public SceneService insertService(SceneService sceneService){
sceneServicesMapper.insertService(sceneService);
return sceneService;
}
//修改
@RequestMapping("/update")
public SceneService updateService(SceneService sceneService){
sceneServicesMapper.updateService(sceneService);
return sceneService;
}
}