• 第二阶段团队冲刺第七天


    实现了加入书架的功能

     

    package Servlet;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import dao.dao;
    import entity.Book;
    import entity.Bookshelf;
    import net.sf.json.JSONObject;
    
    
    public class AddBookshelfServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html; charset=utf-8");
            String bookname =request.getParameter("bookName");
            String username =request.getParameter("username");
    
            Bookshelf bookshelf =new Bookshelf(bookname,username);
            dao dao =new dao();
            PrintWriter out = response.getWriter();
            JSONObject json=new JSONObject();
            if(dao.addshelf(bookshelf)) {
                json.put("result", 1);
                out.print(json);
            }else {
                json.put("result", 0);
                out.print(json);
            }
        }
    
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }
    
    AddBookshelfServlet.java
    package com.example.fooks.utils;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    
    import androidx.recyclerview.widget.RecyclerView;
    
    import com.example.fooks.R;
    import com.example.fooks.entity.Book;
    import com.example.fooks.entity.Bookshelf;
    
    import java.util.List;
    
    
    public class ShopsAdapter extends BaseAdapter {
        private List<Book> mList;
        private Context mContext;
        private LayoutInflater mLayoutInflater;
    
    
        public ShopsAdapter(List<Book> mList, Context mContext) {
            this.mList = mList;
            this.mContext = mContext;
            this.mLayoutInflater = LayoutInflater.from(mContext);
        }
    
        @Override
        public int getCount() {
            return mList.size();
        }
    
        @Override
        public Object getItem(int position) {
            return mList.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if(convertView==null)
            {
                viewHolder= new ViewHolder();
                convertView=mLayoutInflater.inflate(R.layout.booklist,null);
                viewHolder.mBook= convertView.findViewById(R.id.book_show);
                convertView.setTag(viewHolder);
            }else {
                viewHolder=(ViewHolder)convertView.getTag();
            }
    
            Book book=mList.get(position);
            viewHolder.mBook.setText(book.getBookName());
    
            return convertView;
        }
    }
    
    ShopsAdapter.java
  • 相关阅读:
    java如何实现以数据流的形式下载压缩包到本地?
    在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了?
    windows中当你的键盘无法使用时我们可以用另一种方法哦
    Idea中如何将web项目打包成war包并放到tomcat中启动
    [CSS3] Use media query to split css files and Dark mode (prefers-color-scheme: dark)
    [PWA] Storage information for PWA application
    [HTML5] Native lazy-loading for the web
    [Dynamic Programming] 198. House Robber
    [Javascript] Sort by multi factors
    [Javascript] Keyword 'in' to check prop exists on Object
  • 原文地址:https://www.cnblogs.com/biigteam/p/13069097.html
Copyright © 2020-2023  润新知