老师,后台分类插入只有最后修改时间
package com.lmz.book.dao;
import com.lmz.book.entity.Category;
import com.sun.org.apache.xml.internal.resolver.Catalog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
public interface CategoryDao {
@Insert("insert into category(name) value(#{name})")
void insert(String name);
@Select("select * from category order by create_time asc")
@Results(id = "all",value = {
@Result(column = "id",property = "id",id=true),
@Result(column = "name",property = "name"),
@Result(column = "create_time",property = "createTime"),
@Result(column = "update_time",property = "updateTime")
})
List<Category> select();
}
package com.lmz.book.controller;
import com.lmz.book.biz.CategoryBiz;
import com.lmz.book.biz.impl.CategoryBizImpl;
import com.lmz.book.entity.Category;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
public class CategoryController {
private CategoryBiz categoryBiz=new CategoryBizImpl();
public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Category> categoryList = categoryBiz.getAll();
request.getServletContext().setAttribute("categoryList",categoryList);
request.getRequestDispatcher("/WEB-INF/pages/admin/category_list.jsp").forward(request,response);
}
public void toAdd(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
List<Category> categoryList = categoryBiz.getAll();
request.getServletContext().setAttribute("categoryList",categoryList);
request.getRequestDispatcher("/WEB-INF/pages/admin/category_toAdd.jsp").forward(request,response);
}
public void save(HttpServletRequest request,HttpServletResponse response) throws IOException {
Category category=new Category();
category.setName(request.getParameter("name"));
categoryBiz.save(category);
response.sendRedirect("list.do");
}
}
public class Category {
private int id;
private String name;
private Date createTime;
private Date updateTime;
private List<Book> bookList=new ArrayList<Book>();
public List<Book> getBookList() {
return bookList;
}
public void setBookList(List<Book> bookList) {
this.bookList = bookList;
}
麻烦老师帮忙看下,另外老师,其实我不是很懂这里时间的获取是怎么得到的,我的代码里插入的只有一个string类型的name,现在得到的这个时间貌似应该是创建时间?但是我不清楚这个时间是怎么获得的
正在回答
同学你好!
只插入name是可以,因为id,和时间数据库会自动更新。
如果你想传入对象,也是可以的,你可以参考icake项目中的方法
如果你在测试的过程中,出现了问题,建议你贴一下具体的问题。
祝学习愉快~
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星