发表于: 2017-09-28 23:56:35
1 745
今天完成的任务
写了一个实体类,然后把这个实体类打印到网页上
public class Product {
private int id;
private String name;
private float price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
实体类没什么好说的,这个写的几乎不可能有错
@Controller
public class ProductController {
@RequestMapping("/addProduct")
public ModelAndView add(Product product) throws Exception {
ModelAndView mav = new ModelAndView("showProduct");
List<Product> a= new ArrayList<Product>();
Product outA=new Product();
outA.setId(1);
outA.setName("石榴");
outA.setPrice((float) 2.5);
mav.addObject("product",outA);
return mav;
}
}
控制类
也是昨天写过的
@RequestMapping("/addProduct")
调用了addProduct.jsp
这个addProduct.jsp声明了两种变量,上面的outA即在此输出
<form action="addProduct">
产品名称 :<input type="text" name="name" value=""><br />
产品价格: <input type="text" name="price" value=""><br />
<input type="submit" value="增加商品">
</form>
ModelAndView mav = new ModelAndView("showProduct");
调用的showProduct.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
产品名称: ${product.name}<br>
产品价格: ${product.price}
这个jsp即是在网页打印的内容
上面这两个jsp等价于前几天写的
model.addAttribute("msg", "Spring MVC Hello World");
但具体为什么要分为两个jsp写还不是很明白
网页打印的内容
其实整合ssm框架就是在整合spring+mybatis的基础上,将打印的数据库内容由控制台转到网页上来
任务二的REST接口是否就是定义此功能的?
一个合格的任务二作业是否应该包含在网页中实现数据库的增删改查..
整合ssm框架
遇到的问题
收获
评论