<!-- [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]