package com.hzya.frame.execsql.controller;
import com.hzya.frame.execsql.entity.ExecSqlEntity;
import com.hzya.frame.execsql.service.IExecSqlService;
import com.hzya.frame.web.action.DefaultController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description 执行前端传过来的sql，只允许执行select
 * @Author xiang2lin
 * @Date 2021/4/28 14:19
 **/
@RestController
@RequestMapping(value = "/execsql")
public class ExecSqlController extends DefaultController {

    @Autowired
    @Resource(name = "ya_ExecSqlService")
    private IExecSqlService execSqlService;

    @RequestMapping("/select")
    @ResponseBody
    public List<HashMap<String,Object>> execSelectSql(ExecSqlEntity entity){
        List<HashMap<String,Object>> list = new ArrayList<>();
        try {
            list = execSqlService.execSelectSql(entity);
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
}
