@RequestMapping(“deleteByid”)
public String deleteByid(int id) {
int rows=service.delete(id);
return “redirect:/selectAll.do”;
}
//添加页面跳转
@RequestMapping(“getpage”)
public String getpage() {
return “/addPage”;
}
//添加
@RequestMapping(“addPerson”)
public String addPerson(TbPerson tbPerson) {
SimpleDateFormat simple=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
tbPerson.setCreatetime(simple.format(new Date()));
int rows=service.addPerson(tbPerson);
return “redirect:/selectAll.do”;
}
//根据id查询
@RequestMapping(“getbyid”)
public String getbyid(Model model,int id) {
TbPerson tbPerson=service.getByid(id);
model.addAttribute(“tbPerson”, tbPerson);
return “/addPage”;
}
//修改
@RequestMapping(“update”)
public String update(TbPerson tbPerson) {
SimpleDateFormat simple=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
tbPerson.setCreatetime(simple.format(new Date()));
int rows=service.update(tbPerson);
return “redirect:/selectAll.do”;
}
}
com.dao
TbPersonMapper.java
package com.dao;
import com.entity.TbPerson;
import java.util.List;
public interface TbPersonMapper {
int deleteByPrimaryKey(Integer id);
int insert(TbPerson record);
TbPerson selectByPrimaryKey(Integer id);
List selectAll();
int updateByPrimaryKey(TbPerson record);
}
TbPersonMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>delete from tb_person
where id = #{id,jdbcType=INTEGER}
insert into tb_person (id, BookName, author,
pages, createTime)
values (#{id,jdbcType=INTEGER}, #{bookname,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR},
#{pages,jdbcType=INTEGER}, #{createtime,jdbcType=TIMESTAMP})
update tb_person
set BookName = #{bookname,jdbcType=VARCHAR},
author = #{author,jdbcType=VARCHAR},
pages = #{pages,jdbcType=INTEGER},
createTime = #{createtime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
select id, BookName, author, pages, createTime
from tb_person
where id = #{id,jdbcType=INTEGER}
select id, BookName, author, pages, createTime
from tb_person ORDER BY createTime DESC
com.entity
TbPerson.java
package com.entity;
import java.util.Date;
public class TbPerson {
private Integer id;
private String bookname;
private String author;
private Integer pages;
private String createtime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname == null ? null : bookname.trim();
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) { <