AOS 自动生成代码(四) Controller生成

生成Controller文件选择相应的Controller目录

AOS 自动生成代码(四) Controller生成_第1张图片

选择相应的表:生成 Conttroller 时候选择相应的 Controlname 用于    Controlname 默认会根据系统提供的DAO生成。

                      JSP输出路径位置:JSP路径用于定位JSP的路径。

以上两个生成规则为:如DAO 路径:cn.core.autobuilder.dao 那么生成controlname : core  JSP输出路径 : core/autobuilder

@Controller
@RequestMapping(value = "test/co_test")

@RequestMapping(value = "init")
public String init(HttpSession session, HttpServletRequest request) {
	return "core/test/co_test.jsp";
  }


AOS 自动生成代码(四) Controller生成_第2张图片


生成代码后会自动生成菜单。

AOS 自动生成代码(四) Controller生成_第3张图片

生成代码:

package cn.core.test.modules.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.core.test.dao.mapper.Co_testMapper;
import cn.core.test.dao.po.Co_testPO;
import cn.core.test.modules.service.Co_testService;
import cn.osworks.aos.core.asset.AOSJson;
import cn.osworks.aos.core.asset.AOSUtils;
import cn.osworks.aos.core.asset.WebCxt;
import cn.osworks.aos.core.dao.SqlDao;
import cn.osworks.aos.core.excel.POIExcelUtil;
import cn.osworks.aos.core.typewrap.Dto;
import cn.osworks.aos.core.typewrap.Dtos;
import cn.osworks.aos.core.typewrap.impl.HashDto;

/**
 * 自动生成测试[co_test] controller
 * 

*

* * @author penghe * @date 2016-08-11 19:51:03 */ @Controller @RequestMapping(value = "test/co_test") public class Co_testController { @Autowired private Co_testService co_testservice; @Autowired private SqlDao sqlDao; @Autowired private Co_testMapper co_testmapper; /** * 自动生成测试 页面初始化 * * @param session * @param request * @return */ @RequestMapping(value = "init") public String init(HttpSession session, HttpServletRequest request) { return "test/co_test.jsp"; } /** * 查询自动生成测试 * * @param request * @param response */ @RequestMapping(value = "list") public void list(HttpServletRequest request, HttpServletResponse response) { Dto inDto = Dtos.newDto(request); HttpSession session = request.getSession(); if (session != null) session.setAttribute("co_testsessionid", inDto); // sql字定义查询 // List list = sqlDao.list("Co_test.listCo_test", inDto); // 标准查询 List list = co_testmapper.likePage(inDto); String outString = AOSJson.toGridJson(list, inDto.getPageTotal()); WebCxt.write(response, outString); } /** * 保存自动生成测试 * * @param session * @param request * @return */ @RequestMapping(value = "save") public void save(HttpServletRequest request, HttpServletResponse response) { Dto dto = Dtos.newDto(request);
                //系统默认值设置
		dto.put("option_name", dto.getUserInfo().getName_());
		dto.put("option_id", dto.getUserInfo().getAccount_());
		dto.put("option_datetime", AOSUtils.getDateTimeStr());
		Dto outDto = co_testservice.saveCo_test(dto);
		WebCxt.write(response, AOSJson.toJson(outDto));
	}

	/**
	 * 更新自动生成测试
	 * 
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "update")
	public void update(HttpServletRequest request, HttpServletResponse response) {
		Dto dto = Dtos.newDto(request);
		dto.put("option_name", dto.getUserInfo().getName_());
		dto.put("option_id", dto.getUserInfo().getAccount_());
		dto.put("option_datetime", AOSUtils.getDateTimeStr());
		Dto outDto = co_testservice.updateCo_test(dto);
		WebCxt.write(response, AOSJson.toJson(outDto));
	}

	/**
	 * 删除自动生成测试
	 * 
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "delete")
	public void delete(HttpServletRequest request, HttpServletResponse response) {
		Dto dto = Dtos.newDto(request);
		Dto outDto = co_testservice.delete(dto);
		WebCxt.write(response, AOSJson.toJson(outDto));
	}

	/**
	 * 导出自动生成测试
	 * 
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "exportexcel")
	public void exportexcel(HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws IOException {
		Dto dto = (HashDto) session.getAttribute("co_testsessionid");
		String filename = "";
		try {
			filename = URLEncoder.encode("co_test", "utf-8");
			InputStream bis = null;
			BufferedInputStream buffis = null;
			OutputStream fos = null;
			BufferedOutputStream bos = null;
			fos = response.getOutputStream();
			bos = new BufferedOutputStream(fos);
			String[] titleHead = new String[] { "ID", "名称", "地址", "出生日期", "性别", "使用次数", "钱多多", "操作人名称", "操作人ID",
					"操作时间", };
			String[] datarow = new String[] { "id_", "name_", "add_", "birth_date", "sex_", "usetimes_", "money_",
					"option_name", "option_id", "option_datetime", };
			List list = co_testmapper.likePage(dto);
			List outlist = new ArrayList();
			for (int i = 0; i < list.size(); i++) {
				Co_testPO co_testPO = list.get(i);
				Dto dataDto = new HashDto();
				AOSUtils.copyProperties(co_testPO, dataDto);
				outlist.add(dataDto);
			}
			bis = POIExcelUtil.create(filename, outlist, titleHead, datarow);
			buffis = new BufferedInputStream(bis);
			response.setContentType("application/xls");
			response.setHeader("Content-Disposition",
					"inline;filename=" + URLEncoder.encode(filename + ".xls", "utf-8"));
			int bytesRead = 0;
			byte[] buffer = new byte[1024];
			while ((bytesRead = buffis.read(buffer, 0, buffer.length)) != -1) {
				bos.write(buffer, 0, bytesRead);
			}
			bos.flush();
			bis.close();
			buffis.close();
			fos.flush();
			fos.close();
			bos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


你可能感兴趣的:(AOS开发)