package Test.code;
import java.io.File;
import java.io.FileWriter;
import Test.TestUtil;
public class ControllerTest {
public static void controllerTest(String tableName,String tableBean,String currentBao) throws Exception{
String rn = "\r\n";
String []array = TestUtil.stringToArray(tableBean);
String src =
"package " + currentBao + ".controller;"+ rn+
rn +
"import java.util.List;"+ rn+
"import javax.servlet.http.HttpSession;"+ rn+
"import org.springframework.beans.factory.annotation.Autowired;"+ rn+
"import org.springframework.stereotype.Controller;"+ rn+
"import org.springframework.ui.ModelMap;"+ rn+
"import org.springframework.web.bind.annotation.PathVariable;"+ rn+
"import org.springframework.web.bind.annotation.RequestMapping;"+ rn+
"import org.springframework.web.bind.annotation.RequestMethod;"+ rn+
rn +
"import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";"+ rn+
"import " + currentBao + ".service."+TestUtil.upperFirstChar(tableName)+ "Service;"+ rn+
rn +
"@Controller"+ rn+
"public class "+TestUtil.upperFirstChar(tableName)+ "Controller {"+ rn+
rn +
" @Autowired"+ rn+
" "+TestUtil.upperFirstChar(tableName)+ "Service service;"+ rn+
rn +
" @RequestMapping(value = \"/"+tableName+"View.do\")"+ rn+
" public String "+tableName+"View(ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" List<"+TestUtil.upperFirstChar(tableName)+"> "+tableName+"List = service.all"+TestUtil.upperFirstChar(tableName)+"();"+ rn+
" modelMap.put(\""+tableName+"List\", "+tableName+"List);"+ rn+
" return \"back/jsp/"+tableName+"/"+tableName+"View\";"+ rn+
" }"+ rn+
rn +
" @RequestMapping(value = \"/"+tableName+"Del{"+array[0]+"}.do\")"+ rn+
" public String "+tableName+"Del(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" service.del"+TestUtil.upperFirstChar(tableName)+"("+array[0]+");"+ rn+
" String message1=\"删除成功\";"+ rn+
" String message2=\"请返回……\";"+ rn+
" String url=\""+tableName+"View.do\";"+ rn+
" modelMap.put(\"message1\", message1);"+ rn+
" modelMap.put(\"message2\", message2);"+ rn+
" modelMap.put(\"url\", url);"+ rn+
" return \"infomationShow\";"+ rn+
" }"+ rn+
rn +
" @RequestMapping(value =\"/"+tableName+"GoAdd.do\")"+ rn+
" public String "+tableName+"GoAdd(ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" return \"back/jsp/"+tableName+"/"+tableName+"Add\";"+ rn+
" }"+ rn+
rn +
" @RequestMapping(value = \"/"+tableName+"Add.do\",method=RequestMethod.POST)"+ rn+
" public String "+tableName+"Add("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" service.add"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+
" String message1=\"添加成功\";"+ rn+
" String message2=\"请返回……\";"+ rn+
" String url=\""+tableName+"View.do\";"+ rn+
" modelMap.put(\"message1\", message1);"+ rn+
" modelMap.put(\"message2\", message2);"+ rn+
" modelMap.put(\"url\", url);"+ rn+
" return \"infomationShow\";"+ rn+
" }"+ rn+
rn +
" @RequestMapping(value = \"/"+tableName+"GoUpdate{"+array[0]+"}.do\")"+ rn+
" public String "+tableName+"GoUpdate(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" "+TestUtil.upperFirstChar(tableName)+" "+tableName+" = service."+tableName+"("+array[0]+");"+ rn+
" modelMap.put(\""+tableName+"\", "+tableName+");"+ rn+
" return \"back/jsp/"+tableName+"/"+tableName+"Update\";"+ rn+
" }"+ rn+
rn+
" @RequestMapping(value = \"/"+tableName+"Update.do\",method=RequestMethod.POST)"+ rn+
" public String "+tableName+"Update("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" service.update"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+
" String message1=\"修改成功\";"+ rn+
" String message2=\"请返回……\";"+ rn+
" String url=\""+tableName+"View.do\";"+ rn+
" modelMap.put(\"message1\", message1);"+ rn+
" modelMap.put(\"message2\", message2);"+ rn+
" modelMap.put(\"url\", url);"+ rn+
" return \"infomationShow\";"+ rn+
" }"+ rn+
rn +
"}"+ rn ;
String path = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/";
File fpath = new File(path);
if (!fpath.exists()) {
fpath.mkdirs();
}
String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/"+TestUtil.upperFirstChar(tableName)+"Controller.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write(src);
fw.flush();
fw.close();
}
public static void controllerTest_(String tableName,String firstTable,String tableBean,String currentBao) throws Exception{
String rn = "\r\n";
String []array = TestUtil.stringToArray(tableBean);
String src =
"package " + currentBao + ".controller;"+ rn+
rn +
"import java.util.List;"+ rn+
"import javax.servlet.http.HttpSession;"+ rn+
"import org.springframework.beans.factory.annotation.Autowired;"+ rn+
"import org.springframework.stereotype.Controller;"+ rn+
"import org.springframework.ui.ModelMap;"+ rn+
"import org.springframework.web.bind.annotation.PathVariable;"+ rn+
"import org.springframework.web.bind.annotation.RequestMapping;"+ rn+
"import org.springframework.web.bind.annotation.RequestMethod;"+ rn+
rn +
"import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";"+ rn+
"import " + currentBao + ".service."+TestUtil.upperFirstChar(tableName)+ "Service;"+ rn+
rn +
"@Controller"+ rn+
"public class "+TestUtil.upperFirstChar(tableName)+ "Controller {"+ rn+
rn +
" @Autowired"+ rn+
" "+TestUtil.upperFirstChar(tableName)+ "Service service;"+ rn+
rn +
" @RequestMapping(value = \"/"+tableName+"View{"+firstTable+"Id}.do\")"+ rn+
" public String "+tableName+"View(@PathVariable(\""+firstTable+"Id\")String "+firstTable+"Id ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+
" List<"+TestUtil.upperFirstChar(tableName)+"> "+tableName+"List = service.all"+TestUtil.upperFirstChar(tableName)+"("+firstTable+"Id);"+ rn+
" "+TestUtil.upperFirstChar(tableName)+" "+tableName+" = new "+TestUtil.upperFirstChar(tableName)+"(); "+ rn+
" "+tableName+".set"+TestUtil.upperFirstChar(firstTable)+"Id("+firstTable+"Id);"+ rn+
" modelMap.put(\""+tableName+"\", "+tableName+");"+ rn+
" modelMap.put(\""+tableName+"List\", "+tableName+"List);"+ rn+
" return \"back/jsp/"+tableName+"/"+tableName+"View\";"+ rn+
" }"+ rn+
rn +
" @RequestMapping(value = \"/"+tableNa
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
springMvc 入门学习(自动生成 springmvc 单表 两关联表 生成 及显示) http://knight-black-bob.iteye.com/blog/2208162 自动生产web 增删查修改 springmvc+mybatis springmvc mybatis小实例 自动生成 java 类 和 mybatis sql 语句 和jsp 页面 ,属于自动生产 实例 增删查改 含简单数据库
资源推荐
资源详情
资源评论













收起资源包目录






















































































































共 90 条
- 1

curiousby
- 粉丝: 23
- 资源: 152
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页