栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java接口的几种写法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java接口的几种写法

一、在src/spring-mvc.xml里添加接口文件夹路径


二、在controller路径下新建一个class,DateController

package com.linyun.game.controller;
import com.linyun.game.util.BaseController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
@RequestMapping("/date")
public class DateController extends BaseController {
    
    
	private Integer total= 0;

    @Resource
	private IUserService userService;

}


@RequestMapping("/getDataList")
@ResponseBody
public Map getDataList(HttpServletRequest request) throws ParseException, UnsupportedEncodingException {
    Map map = new HashMap();
	Integer startRownumStr =  Integer.valueOf(request.getParameter("currentPages"));//第几页
	Integer onePageNum = Integer.valueOf(request.getParameter("pageSizes"));//数据数
	Integer start = (startRownumStr*onePageNum)-onePageNum;
	String startRownum = start.toString();
	String endRownum = request.getParameter("pageSizes");
	String account = request.getParameter("account");
    String beginTime = request.getParameter("startTime");
	String overTime = request.getParameter("endTime");
    try {
        List returnList = new ArrayList();
        Map dataMap = new HashMap();
	    dataMap.put("id", 1);
		dataMap.put("name", "xixi");
        returnList.add(dataMap);
        total = returnList.size();
        if (returnList!= null) {
			map.put("list", returnList);
			map.put("total", total);
		}

    } catch (Exception e) {
		e.printStackTrace();
	}
	return map;  
}



@RequestMapping("/getData")
@ResponseBody
public ResultInfo getData(HttpServletRequest request) throws Exception  {
	ResultInfo resultInfo = new ResultInfo();
	Map map = new HashMap();
	try {
       List opList =userService.getUserList();
       if (opList != null) {
			map.put("opList", opList);
		}
        
		success(resultInfo, "成功",200);
		resultInfo.setData(map);
	 } catch (Exception e) {
		e.printStackTrace();
	 }

return resultInfo;
}


 

BaseController,公共的返回成功失败调用信息

public class BaseController{
    public static String SUCCEE="succee";
	public static String FAIL="fail";
    
	protected void success(ResultInfo resultInfo,Object data,String token)
	{
		resultInfo.setCode(200);
		resultInfo.setMsg("成功");
		resultInfo.setToken(token);
		System.out.println(resultInfo);
		resultInfo.setData(data);
	}

    
	protected void error(ResultInfo resultInfo,String errorMsg,String code)
	{
		resultInfo.setCode(code);
		resultInfo.setMsg(errorMsg);
	}

    public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
    public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

}

转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号