parent
316462b249
commit
4d6f52a52e
@ -0,0 +1,60 @@
|
|||||||
|
package BookOperation;
|
||||||
|
|
||||||
|
import Connect.Connect;
|
||||||
|
import JaveBean.Book;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class UploadServlet extends HttpServlet {
|
||||||
|
private Connect con = Connect.getCon();
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
request.setCharacterEncoding("gb2312");
|
||||||
|
response.setContentType("text/html;charset=utf-8");
|
||||||
|
|
||||||
|
String bookname=request.getParameter("bookname");
|
||||||
|
String category=request.getParameter("category");
|
||||||
|
double price= Double.parseDouble(request.getParameter("price"));
|
||||||
|
System.out.println(bookname);
|
||||||
|
System.out.println(category);
|
||||||
|
System.out.println(price);
|
||||||
|
|
||||||
|
Session hSession=Connect.getConfig();
|
||||||
|
Transaction tx=hSession.beginTransaction();
|
||||||
|
//String hql = "FROM User WHERE username=:name";
|
||||||
|
//Query query = hSession.createQuery(hql);
|
||||||
|
//query.setParameter("name",name);
|
||||||
|
//List results = query.list();
|
||||||
|
|
||||||
|
shangchuan(bookname,hSession,category,price);
|
||||||
|
|
||||||
|
tx.commit();
|
||||||
|
// User user= (User) results.get(0);
|
||||||
|
|
||||||
|
System.out.println("上传成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shangchuan(String bookname, Session session, String category, double price){
|
||||||
|
Book book = new Book();
|
||||||
|
//book.setBookid(7);
|
||||||
|
book.setBookname(bookname);
|
||||||
|
book.setPrice(price);
|
||||||
|
book.setCategory(category);
|
||||||
|
book.setImageurl("cbsdaka");
|
||||||
|
book.setSellerId(1);
|
||||||
|
session.save(book);//保存对象进入数据库
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue