11111

<!--    [q2.2]-->
<!--    Please complete the answer of Question 2nd-->
<insert id="insert" parameterType="com.cqust.model.Fruit">
       insert into user(fid,fName,fPrice,fNumber,fMemo)
       value(#{fid},#{fName},#{fPrice},#{fNumber},#{fMemo})
    </insert>

<!--    [/q2.2-->

 //[q2.3]
//   Please complete the answer of Question 2nd
    @Autowired
    private FruitMapper fruitMapper; // Autowire the FruitMapper interface

    @Test
    public void testInsert() {
        // Create a new Fruit object
        Fruit fruit = new Fruit();
        fruit.setfName("banana");
        fruit.setfPrice(2.50f);
        fruit.setfNumber(10);

        fruitMapper.insert(fruit);

        Fruit insertedFruit = getInsertedFruit(); // Implement this method to retrieve the inserted fruit

        assertNotNull(insertedFruit);
    }

    private Fruit getInsertedFruit() {

        return null;
    }

//[/q2.3]

//[q3.1]
// Please complete the answer of Question 3rd

public class FruitBiz {

    @Autowired
    private FruitMapper fruitMapper;//CRUD
    public void selectUser()
    {
        System.out.println("selectByCondition");
        // List<Fruit> lst=fruitMapper.insert("aa");
        //System.out.println(lst);
    }

    //[/q3.1]

  // [q4.1]
// Please complete the answer of Question 4th
    @Autowired
    private FruitBiz FruitBiz;

    // [q4.1]
    @GetMapping("/getAllFruits")
    @ResponseBody
    public List<Fruit> getFruits() {
        return fruitBiz.getAllFruits();
    }


// [/q4.1]

// [q5.1]
//Please complete the answer of Question 5th
    @Autowired
    private FruitBiz fruitService;

    @RequestMapping("/addFruitPage")
    public String showAddFruitPage() {
        return "addFruit"; // Assumes the JSP file is in src/main/webapp/WEB-INF/views/ directory
    }

    @PostMapping("/addFruit")
    public String addFruit(@RequestParam String name, @RequestParam double price, @RequestParam int quantity) {
        // Create a new Fruit object
        Fruit fruit = new Fruit();
        fruit.setfName("NB");
        fruit.setfPrice(2.3f);
        fruit.setfNumber(100);

        // Save the fruit to the database using the service
        fruitService.addFruit(fruit);

        // Redirect to a confirmation page or any other page as needed
        return "redirect:/confirmationPage";
    }


// [/q5.1]

//[q2.1]
//Please complete the answer of Question 2nd
int insert(Fruit fruit);

//[/q2.1]
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值