springmvc的部分代码

获取数据库里面的数据并显示到前端页面中去 DB
public CountTabledao getdata() throws SQLException {
ResultSet rs = null;
Statement statement = null;
try {
Class.forName(“com.mysql.jdbc.Driver”);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = DriverManager.getConnection(“jdbc:mysql://10.0.30.171:3306/ifengqa”, “root”, “123456”);
String sql = "select * from projectlisttable ";
statement = connection.createStatement();
rs = statement.executeQuery(sql);
while (rs.next()) {
int id = rs.getInt(“Id”);
user.setId(id);
String name = rs.getString(“name”);
user.setName(name);
String belong = rs.getString(“belong”);
user.setBelong(belong);
String type = rs.getString(“type”);
user.setType(type);
String starttime = rs.getString(“starttime”);
user.setStarttime(starttime);
String submittime = rs.getString(“submittime”);
user.setSubmittime(submittime);
String checktime = rs.getString(“checktime”);
user.setChecktime(checktime);
String onlinetime = rs.getString(“onlinetime”);
user.setOnlinetime(onlinetime);
String currentprogress = rs.getString(“currentprogress”);
user.setCurrentprogress(currentprogress);
String pm = rs.getString(“PM”);
user.setPM(pm);
String rd = rs.getString(“RD”);
user.setRD(rd);
String qa = rs.getString(“QA”);
user.setQA(qa);
int bug = rs.getInt(“bug”);
user.setBug(bug);
int onlinebug = rs.getInt(“onlinebug”);
user.setOnlinebug(onlinebug);
System.out.println(user.getBelong());
System.out.println(user.getType());
System.out.println(user.getBug());
}
return user;
}

View层 <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getName()%> <%=dbUtildao.getdata().getBelong()%> <%=dbUtildao.getdata().getType()%> <%=dbUtildao.getdata().getStarttime()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> <%=dbUtildao.getdata().getId()%> 编辑 删除 控制层: @RequestMapping("/") public class ProjectListController { @RequestMapping( method = RequestMethod.GET) public String sayHello(ModelMap model) { return "table"; } @RequestMapping(value="/helloagain", method = RequestMethod.GET) public String sayHelloAgain(ModelMap model) { model.addAttribute("gre", "Hello World Again, from Spring 4 MVC"); model.addAttribute("info","my name id shixinfa address jiangxishangraoyugan"); return "welcome"; } @RequestMapping(value="/QA/UserLogin", method = RequestMethod.GET) public String login(ModelMap model) { model.addAttribute("greeting", "Hello World Again, from Spring 4 MVC"); model.addAttribute("user","username shixinfa password 15510225694"); return "welcome"; } @RequestMapping(value="/addlist.html", method = RequestMethod.GET) public String addlist(ModelMap model) { return "addlist"; } @RequestMapping(value="/addinfo.html", method = RequestMethod.POST) public String addinfo(ModelMap model) { return "addinfo"; } @RequestMapping(value="/table.html", method = RequestMethod.GET) public String table(ModelMap model) { return "table"; } @RequestMapping(value="/index.html", method = RequestMethod.GET) public String index(ModelMap model) { return "index"; } @RequestMapping(value="/edlist.html", method = RequestMethod.POST) public String edlist(ModelMap model) { return "edlist"; } @RequestMapping(value="/e.html", method = RequestMethod.GET) public String e(ModelMap model) { return "e"; } @RequestMapping(value="/deldata.html", method = RequestMethod.GET) public String del(ModelMap model) { return "delVip"; } @RequestMapping(value="/editdata.html", method = RequestMethod.POST) public String edit(ModelMap model) { return "delVip"; } @RequestMapping(value="/alter.html", method = RequestMethod.GET) public String alter(ModelMap model) { return "alter"; } } springmvc -servlet.xml 文件 /WEB-INF/views/ .jsp web.xml 文件 Ifeng Web Application dispatcher org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring-servlet.xml 1 AddListData AddListData AddListData default *.css default *.gif default *.jpg default *.png default *.ico default *.js default *.woff dispatcher / Test com.ifeng.qa.dao.DbAction Test /Ifeng/DbAction

猜你喜欢

转载自blog.csdn.net/weixin_37565521/article/details/82961194
今日推荐