javaWeb small projects

Java as a learning plus white, very happy to be able to record their own growth process. Technology Co., please forgive me!

   My main learning is Java backend, when I learned to do a little web project javaee projects have a preliminary opinion!

   The teacher said things are objects, all things are CRUD. My little web project is only realized the CRUD.

 Text here:

  I will break it down into three parts. Data storage, data manipulation, data. Technique are: MySQL store object data, the data JavaEE CRUD operations, html + ajax + jquery binding data, show page rendering.

  First part of the database : Create database and two tables, as shown below:

 

 

 This is a menu table, dishes are dishes table, id primary key, description table foreign keys, dtype is the main dish category id key for this table. For good sql statement after the new test CRUD (auto-increment primary key is set, when the need to add id add automatically add sequence):

Add: insert into dishes (name, price, tid, img, description) values ​​( 'Pork', 8 '1', 'fat and not greasy');

查询:select d.*,t.name as tname from dishes d,dtype t where d.tid=t.id

Review: update dishes set name = 'braised fish', price = 99, img = 2, description = 'fresh meat', tid = 1 where id = 1;

删除:delete from dishes where id=1

The basis of statements such as the above, javaee operation will be used. To add more than a few data for testing.

 

The second part, javaee programming background:

1, javaweb new project, and then create a new package, and the like. To clean and beautiful, using a layered architecture. I was seven layer architecture, as shown below:

 

 

 bean: the entity class. Object properties, get, set, method, tostring, constructor.

DAO: CRUD four methods defined as:

 dao.Impll: interface classes as:

DishesResultSetHandler: collection traverse the object properties. Figure:

 

 

 service: the business layer, because, CRUD, no service, wants to directly return dao layer method.

the servlet: processing client requests, many codes, for example it is simple:

DishesService service=new DishesServiceImpl();
    Gson gson=new Gson();
protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println(request.getQueryString());
        String type=request.getParameter("type");
        switch (type) {
        case "getDishesAll":
            getDishesAll(request,response);
            break;
private void getDishesAll(HttpServletRequest request, HttpServletResponse response) {
        ResponseBody rb=new ResponseBody();
        rb.setData(service.getDishesAll());
        try {
            response.getWriter().write(gson.toJson(rb));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

tools: technology dbutils connection pool and as annotated:

 

 Test categories: is to use the jUnit 5, test notes. Not a map.

druid.properties: new file, connect to the local database, I was with Ali cloud;

 

 

The third part, distal end. ok, so far, I can not seem to write, words to be. There is a jQuery + Ajax, in no anything. Internet can also find a good-looking HTML template, and then use vue sets, data binding, vue have CRUD methods, very powerful. Official website look ok.

 

 

 

 

Also write like FML. Posted a cursor did not, and that can not be written, but also a rare move down, Java is a very powerful thing, writing up feeling more comfortable than c, unlike PHP as a little hybridity feeling. This is what I wrote a small program, which many functions are not written. Like login, which also involves the session, cokie, for safety involved again to filter, monitor and so on.

Of course, now just a small case, we need to build their own environment, after spring frame-to-back, mvc framework, etc. mainstream framework, all this will become very easy. Distributed cluster after then, give you more convenient, do not have to worry about, because no conditions and the level of. I do not know what to say anyway, come on!

 

 

 

 

 

 

 

 

 

 








































   

 

 

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/-zyz/p/12392277.html