1.dao层编写抽象方法,
sql语句:insert into 表名 (列表名1,列表名2) values(值1,值2)
delete from 表名 where id=#{id}
2.service接口编写对应抽象方法
3.service实现类注入service接口@Autowired
实现接口抽象方法
注意:校验前端所传来的id值是否为空并且是否小于1利用 if 语句判断,判断之后抛出异常
throw new IllegalArgumentException() 非法参数异常
throw new NoSuchElementException() 无参数异常
4.controller层
注入service类@Autowired,实现抽象方法,
删除 @RequestMapping("doDeleteById")
修改 @RequestMapping("doSavaGoods")
注意:修改方法中,sql语句执行返回结果要发送给查询页面进行展示
利用请求重定向
return "redirect:doGoodUI"
5.前端页面
去除页面边框前的小点:
<style type="text/css">
ul li{
list-style-type:none;
margin:5px //边框像素
}
</style>
删除数据交互
<td><a th:href="@{doDeleteById(id=${g.id}}">delete</a></td>
标签 th:href="@{doDeleteById(id=${g.id}}" 是thymeleaf引擎所定义的标签
添加数据交互--先输入要添加的数据,其中:
action=" ",填入要执行的方法名,如 doSaveGoods
<input type="text" name="name">,name是为了能够将填入的参数存入实体类对象中,而调用set方法,利用name的值拼接成setName方法
注意: <fieldset>标签 分块标签 作用是将页面分块
<legend>标签 标题标签 应用于标题