查询删除
@Controller
public class ResultController {
@Resource
private ResultService resultService;
@GetMapping("/index")
public String text(Model model) {
List<Result> list = resultService.list();
model.addAttribute("list", list);
return "index";
}
;
@GetMapping("/delete/{id}")
public String delete(@PathVariable Long id) {
resultService.removeById(id);
return "redirect:/index";
}
;
显示删除jsp页面
<table width="100%" border="1">
<tr>
<th>学号</th>
<th>编号</th>
<th>日期</th>
<th>成绩</th>
<th>操作</th>
</tr>
<tr th:each="lis:${list}">
<td th:text="${lis.studentNo}"></td>
<td th:text="${lis.subjectNo}"></td>
<td th:text="${lis.examDate}"></td>
<td th:text="${lis.studentResult}"></td>
<td>
<a th:href="@{/delete/{id}(id=${lis.studentNo})}">删除</a>
</td>
</tr>
</table>
日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
新增
@GetMapping("/add")
public String delete2(){
return "add";
}
@PostMapping("/add")
public String add(Inventory inventory){
System.out.println(inventory.toString());
inventoryService.save(inventory);
return "redirect:/index";
}
显示新增jsp页面
<table border="1" width="100%">
<tr>
<th>编号</th>
<th>物品</th>
<th>价格</th>
<th>日期</th>
<th>操作</th>
</tr>
<tr th:each="inven:${inventories}">
<td th:text="${inven.shoppingId}"></td>
<td th:text="${inven.shoppingName}"></td>
<td th:text="${inven.shoppingPrice}"></td>
<td th:text="${#dates.format(inven.shoppingTime, 'yyyy-MM-dd HH:mm')}"></td>
<td>
<a th:href="@{/delete/{id}(id=${inven.shoppingId})}">删除</a>
</td>
</tr>
<a th:href="@{/add}">保存</a>
</table>
实体类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Inventory implements Serializable {
@TableId(value = "shopping_id",type = IdType.AUTO)
private Long shoppingId;
private String shoppingName;
private double shoppingPrice;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date shoppingTime;
}
Service
@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper,Inventory> implements InventoryService {}
public interface InventoryService extends IService<Inventory> {
}
Mapper
public interface InventoryMapper extends BaseMapper<Inventory> {
}
更新
@GetMapping("/update/{id}")
public String update(@PathVariable("id") Long id,Model model){
System.out.println(id);
Inventory inventory = inventoryService.getById(id);
model.addAttribute("inventory",inventory);
return "update";
}
@PostMapping("/updateInfo")
public String updateInfo(Inventory inventory){
System.out.println(inventory);
boolean update = inventoryService.updateById(inventory);
return "redirect:/index";
}
显示更新jsp
<body>
<form th:action="@{/updateInfo}" method="post">
<input type="hidden" name="shoppingId" th:value="${inventory.shoppingId}"/>
姓名:<input type="text" name="shoppingName" th:value="${inventory.shoppingName}">
价格:<input type="text" name="shoppingPrice" th:value="${inventory.shoppingPrice}">
日期:<input type="date" name="shoppingTime" th:value="${#dates.format(inventory.shoppingTime, 'yyyy-MM-dd')}">
<button type="submit">提交</button>
</form>
</body>
文件上传
@GetMapping("/file")
public String File(){
return "file";
}
@PostMapping("/upload")
public String upload(@RequestParam("headImg") MultipartFile multipartFile) throws IOException {
if(!multipartFile.isEmpty()){
String name = multipartFile.getOriginalFilename();
multipartFile.transferTo(new File("D:\\" + name));
}
return "file";
}
文件上传jsp
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="headImg" />
<button type="submit">提交</button>
</form>
模糊查询
@PostMapping("/likeQuery")
public String likeQuery(@RequestParam("loveName") String loveName, ModelMap modelMap, QueryWrapper<Love> wrapper) {
wrapper.like("love_name", loveName);
List<Love> pol = loveService.list(wrapper);
modelMap.addAttribute("pol",pol);
modelMap.addAttribute("lovename",loveName);
return "index";
}
JS页面
<p>
<form action="/likeQuery" method="post">
模糊查询:<input type="text" name="loveName" th:value="${lovename}" />
<button type="submit">查询</button>
</form>
</p>