springclouddemo7.2 service provider -order

** Learn from the station b springcloud project, now summarize the summary removal of a small error appearing in the video, some of the error-prone places were reminded

b outbound links: https://www.bilibili.com/video/av55629580?p=1
profile link:
https://pan.baidu.com/s/1o0Aju3IydKA15Vo1pP4z5w
extraction code: 21ru

On a link:
https://blog.csdn.net/qq_40893824/article/details/103641158
next section link:
https://blog.csdn.net/qq_40893824/article/details/103644807

The following list summarizes:
Order / New Entity OrderVO → order / repository / OrderRepository Modify Add → order / OrderHandler Modify Add → Check

order / OrderHandler modify delete → check → client / index.html and client / order.html modify → client / entity of OrderVO → client / entity / Order Add → client / feign / OrderFeign → order / OrderRepository modify → client / OrderHandler modify → test

Implementation details:
1. In order / entity new entity class OrderVO, tagging:

package com.southwind.entity;

import lombok.Data;

import java.util.List;

@Data
public class OrderVO {
    private int code;
    private String msg;
    private int count;
    private List<Order> data;
}

2. Add code public void count () in order / repository / OrderRepository interface; findAll modified as follows:

    public List<Order> findAllByUid(int index, int limit, int uid);
    public int countByUid(int uid);

3. Modify the order / mapping / OrderRepository.xml, add the code:
the param1, param2, Param3 means pass over the parameters 1,2,3

	<select id="findAllByUid" resultMap="orderMap">
		select id,mid,date,state from t_order where uid = #{param3} limit #{param1},#{param2}
	</select>

	<select id="countByUid" parameterType="int" resultType="int">
		select count(*) from t_order where uid=#{id}
	</select>

4. Modify Add countByUid findAll code and code order / OrderHandler of:

    @GetMapping("/findAllByUid/{index}/{limit}/{uid}")
    public List<Order> findAllByUid(@PathVariable("index")int index, @PathVariable("limit")int limit,@PathVariable("uid")int uid){
        return orderRepository.findAllByUid(index, limit, uid);
    }

    @GetMapping("/countByUid/{uid}")
    public int count(@PathVariable("uid")int uid){
        return orderRepository.countByUid(uid);
    }

Check: Restart Order
5. The entering http: // localhost: 8010 / order / findAllByUid / 0/10/1
Here Insert Picture Description
into the http: // localhost: 8010 / Order / findAllByUid / 0/10/2
Here Insert Picture Description
6. The entering http: // localhost : 8010 / order / countByUid / 1
Here Insert Picture Description
described under a single number of 12
into the http: // localhost: 8010 / order / countByUid / 2
Here Insert Picture Description
Description of the singular 2 2

First page search function to be implemented:
1. Modify findByUid in order / OrderHandler, the
type List <Order> read OrderVO:

    @GetMapping("/findAllByUid/{index}/{limit}/{uid}")
    public OrderVO findAllByUid(@PathVariable("index")int index, @PathVariable("limit")int limit, @PathVariable("uid")int uid){
        OrderVO orderVO = new OrderVO();
        orderVO.setMsg("");
        orderVO.setCount(orderRepository.countByUid(uid));
        orderVO.setData(orderRepository.findAllByUid(index, limit, uid));
        return orderVO;
    }

Then remove the code countByUid portion
2. Check into the HTTP: // localhost: 8010 / Order / findAllByUid / 0/10 /. 1
Here Insert Picture Description
3. In the client / index.html and client / order.html in line 13 is
<the href = A "/ account / redirect / order" to <a href = "/ menu / redirect / order"

4. Copy the order / entity OrderVO to the client / entity in
adding private long id in the client / entity / Order in;

5. Add code in client / feign / OrderFeign of:

    @GetMapping("/order/findAllByUid/{index}/{limit}/{uid}")
    public OrderVO findAllByUid(@PathVariable("index")int index, @PathVariable("limit")int limit, @PathVariable("uid")long uid);

6. In order / OrderRepository findAllByUid and the long type uid countByUid changed
order / OrderHandler uid in the same type of long to
order / mapping / OrderRepository.xml in parameterType = "int" to parameterType = "long"

7. Add code in client / OrderHandler in:
Note @ResponseBody not be omitted!

    @GetMapping("/findAllByUid")
    @ResponseBody
    public OrderVO findAllByUid(@RequestParam("page")int page, @RequestParam("limit")int limit, HttpSession session){
        User user = (User) session.getAttribute("user");
        int index = (page - 1)*limit;
        return orderFeign.findAllByUid(index, limit, user.getId());
    }

Testing:
8. Enter http: // localhost: 8030 / login.html login zhangsan:
Here Insert Picture Description
Click Joe Smith:
Here Insert Picture Description
click Home:
Here Insert Picture Description
9. In the client / controller / OrderHandler save part of return "index"; instead return "order ";
re-enter http: // localhost: 8030 / login.html login zhangsan: select the last dish to order, the page will jump to user Joe Smith's order history page:
Here Insert Picture Description
single success, add a record success!

On a link:
https://blog.csdn.net/qq_40893824/article/details/103641158
next section link:
https://blog.csdn.net/qq_40893824/article/details/103644807

Published 42 original articles · won praise 2 · Views 1179

Guess you like

Origin blog.csdn.net/qq_40893824/article/details/103643682