自学内容网 自学内容网

springboot实现简单的数据查询接口(无实体类)

目录

前言:springboot整体架构

1、ZjGxbMapper.xml

2、ZjGxbMapper.java

3、ZjGxbService.java

4、ZjGxbController.java

5、调用接口测试数据是否正确

6、打包放到服务器即可


前言:springboot整体架构

文件架构,主要编写框选的这几类

1、ZjGxbMapper.xml

编写业务相关的增删改查语句

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.appport.mapper.ZjGxbMapper">
<!--   查询工程信息 根据需求编写sql语句-->
    <select id="selectGcxx" resultType="java.util.HashMap" >
        select a,b,c from table3  
    </select>
</mapper>

2、ZjGxbMapper.java

定义接口

package com.appport.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface ZjGxbMapper {
    /**
     * 查询所有的工程项目
     */
    public List<Map<String,?>> selectGcxx();
}

3、ZjGxbService.java

调用接口

package com.appport.service;

import com.appport.mapper.ZjGxbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author xiao_jiajia
 * @Description TODO $
 * @Date $ $
 * @Param $
 * @return $
 **/

@Service
public class ZjGxbService {
    @Autowired
    private ZjGxbMapper zjGxbMapper;
    
    //工程信息
    public List<Map<String,?>> selectGcxx(){
        List<Map<String,?>> gclist = zjGxbMapper.selectGcxx();
        return gclist;
    };
}

4、ZjGxbController.java

package com.appport.controller.system;

import com.alibaba.fastjson.JSONObject;
import com.appport.service.ZjGxbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author xiao_jiajia
 * @Description TODO $
 * @Date $ $
 * @Param xiao_jiajia$
 * @return $
 **/
@Controller
public class ZjGxbController {
    @Autowired
    private ZjGxbService zjGxbService;

    
    /**
     * 查询工程信息
     */
    @RequestMapping(value="project",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject project(){
        JSONObject object = new JSONObject();
        List<Map<String,?>> projectList = zjGxbService.selectGcxx();
        object.put("projectList",projectList);
        object.put("code",200);
        return object;
    }

}

5、调用接口测试数据是否正确

6、打包放到服务器即可


原文地址:https://blog.csdn.net/qq_43080548/article/details/143797701

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!