第五天(SpringBoot基础第二篇)
一、关于starter
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
<!-- 覆盖boot默认配置的基础信息 --> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
<resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/application*.yml</include> <include>**/application*.yaml</include> <include>**/application*.properties</include> </includes> </resource>
<filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter>
二、YAML文件
在我们翻阅stater的过程中,也应该发现配置文件除了可是使用application*.properties类型,还可以使用后YAML是"YAML Ain't a Markup Language"(YAML不是一种标记语言)的递归缩写。在开发的这种语 言时,YAML 的意思其实是:"Yet Another Markup Language"(仍是一种标记语言),但为了强调这 种语言以数据做为中心,而不是以标记语言为重点,而用反向缩略语重命名。
配置环境基础信息,创建application.yaml
1 语法规则
2 数据类型
#测试普通的值,注意字符串不用加单引号或者双引号 name: 张三 age: 12 #测试对象,对象还是k: v的方式 -- 注意缩进(不支持tab,使用空格) stu: name: 李四 age: 55 student: studentName: 李四 student-age: 55 #测试数组,使用- 值表示数组中的一个元素 hobbies: - 打篮球 - 羽毛球 - 踢足球 #组合形式 对象加数组 animal: fly: - 喜鹊 - 大雁 run: - 犀牛 - 河马 #组合形式 数组加对象 clazz: - {name: 翠花,age: 18} - {name: 李四,age: 20}
读取配置文件:
@Controller @RequestMapping("/userController") public class UserController { @Value("${name}") private String name; @Value("${age}") private String age; @Value("${stu.name}") private String stu; @Value("${hobbies[0]}") private String hobbies; @Value("${animal.fly[0]}") private String ob; @Value("${clazz[1].name}") private String ac; @RequestMapping("/show") public void show(){ System.out.println("基本类型:"+name+"-"+age); System.out.println("对象中的值:"+stu); System.out.println("数组中的值:"+hobbies); System.out.println("对象中的数组:"+ob); System.out.println("数组中的对象:"+ac); } }

student: name: 张三 age: 88 hobbies: #对象中包含数组 - 抽烟 - 喝酒 - 烫头
声明配置类
/** * 配置类 对象的创建交给IOC */ @Data @Configuration @ConfigurationProperties(prefix = "student") public class StudentEntityDataConfig { private String name; private int age; private String[] hobbies; }
使用方法
@Autowired private StudentEntityDataConfig studentEntityDataConfig;
三、 SpringBoot日志配置
1 日志格式
2022-11-14 20:58:46.767 INFO 13304 --- [ main] com.its.HelloSpringBootApplication : Starting HelloSpringBootApplication using Java 1.8.0_201 on DESKTOP-TTS40QH with PID 13304 (E:\课程记录 \T6\HelloSpringBoot\target\classes started by lenovo in E:\课程记录 \T6\HelloSpringBoot) 2022-11-14 20:58:46.771 INFO 13304 --- [ main] com.its.HelloSpringBootApplication : No active profile set, falling back to 1 default profile: "default" 2022-11-14 20:58:47.686 INFO 13304 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-11-14 20:58:47.694 INFO 13304 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-11-14 20:58:47.694 INFO 13304 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68] 2022-11-14 20:58:47.838 INFO 13304 --- [ main] o.a.c.c.C.[Tomcat]. [localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-11-14 20:58:47.838 INFO 13304 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1009 ms 2022-11-14 20:58:48.171 INFO 13304 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-11-14 20:58:48.181 INFO 13304 --- [ main] com.its.HelloSpringBootApplication : Started HelloSpringBootApplication in 1.884 seconds (JVM running for 3.091)
2 日志级别拓展log4j
3 日志输出
logging: level: org.springframework: info com.xja: info #建议:info 或者 warn
logging: level: org.springframework: info com.xja: info #建议:info 或者 warn file: #path: D://日志 name: D://日志/boot2.txt # 如果颜色消失,配置这个 spring: output: ansi: enabled: always
四、测试单元
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
2 编写单元测试类
1 import org.junit.Test; 2 import org.junit.runner.RunWith; 3 import org.springframework.boot.test.context.SpringBootTest; 4 import org.springframework.test.context.junit4.SpringRunner; 5 /** 6 * 使用Spring Initializr方式自动创建的主程序启动类对应的单元测试类 7 */ 8 @RunWith(SpringRunner.class) // 测试启动器,并加载Spring Boot测试注解 9 @SpringBootTest // 标记为Spring Boot单元测试类,并加载项目的ApplicationContext上下文 10 环境 11 public class Chapter01ApplicationTests { 12 // 自动创建的单元测试方法示例 13 @Test 14 public void contextLoads() { 15 } 16 }
五、JdbcTemplate

1 整合JdbcTemplate
1 <dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-data-jdbc</artifactId> 5 </dependency> 6 <dependency> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-thymeleaf</artifactId> 9 </dependency> 10 <dependency> 11 <groupId>org.springframework.boot</groupId> 12 <artifactId>spring-boot-starter-web</artifactId> 13 </dependency> 14 <dependency> 15 <groupId>com.mysql</groupId> 16 <artifactId>mysql-connector-j</artifactId> 17 <scope>runtime</scope> 18 </dependency> 19 <dependency> 20 <groupId>org.projectlombok</groupId> 21 <artifactId>lombok</artifactId> 22 <optional>true</optional> 23 </dependency> 24 <dependency> 25 <groupId>org.springframework.boot</groupId>
1 # 数据源 2 spring: 3 datasource: 4 url: jdbc:mysql:///boot?useUnicode=true&characterEncoding=UTF-8 5 driver-class-name: com.mysql.cj.jdbc.Driver 6 username: root 7 password:
1 2022-11-16 09:14:46.329 INFO 16472 --- [ main] 2 com.xja.Day03Application : Starting Day03Application using Java 3 1.8.0_201 on DESKTOP-TTS40QH with PID 16472 (E:\课程记录\T6\03-SpringBoot整合 4 \day03\target\classes started by lenovo in E:\课程记录\T6\03-SpringBoot整合\day03) 5 2022-11-16 09:14:46.336 INFO 16472 --- [ main] 6 com.xja.Day03Application : No active profile set, falling back 7 to 1 default profile: "default" 8 2022-11-16 09:14:47.614 INFO 16472 --- [ main] 9 .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC 10 repositories in DEFAULT mode. 11 2022-11-16 09:14:47.624 INFO 16472 --- [ main] 12 .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository 13 scanning in 5 ms. Found 0 JDBC repository interfaces. 14 2022-11-16 09:14:48.329 INFO 16472 --- [ main] 15 o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 16 (http) 17 2022-11-16 09:14:48.342 INFO 16472 --- [ main] 18 o.apache.catalina.core.StandardService : Starting service [Tomcat] 19 2022-11-16 09:14:48.342 INFO 16472 --- [ main] 20 org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache 21 Tomcat/9.0.68] 22 2022-11-16 09:14:48.559 INFO 16472 --- [ main] o.a.c.c.C.[Tomcat]. 23 [localhost].[/] : Initializing Spring embedded WebApplicationContext 24 2022-11-16 09:14:48.560 INFO 16472 --- [ main] 25 w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: 26 initialization completed in 2156 ms 27 2022-11-16 09:14:48.977 WARN 16472 --- [ main] 28 ion$DefaultTemplateResolverConfiguration : Cannot find template location: 29 classpath:/templates/ (please add some templates, check your Thymeleaf 30 configuration, or set spring.thymeleaf.check-template-location=false) 31 2022-11-16 09:14:49.090 INFO 16472 --- [ main] 32 com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 33 2022-11-16 09:14:49.283 INFO 16472 --- [ main] 34 com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 35 2022-11-16 09:14:49.586 INFO 16472 --- [ main] 36 o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 37 (http) with context path '' 38 2022-11-16 09:14:49.596 INFO 16472 --- [ main] 39 com.xja.Day03Application : Started Day03Application in 4.047 40 seconds (JVM running for 7.288)
2 案例测试
/*
Navicat Premium Data Transfer
Source Server : root
Source Server Type : MySQL
Source Server Version : 80022
Source Host : localhost:3306
Source Schema : cargo
Target Server Type : MySQL
Target Server Version : 80022
File Encoding : 65001
Date: 19/03/2023 14:29:21
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for cargo
-- ----------------------------
DROP TABLE IF EXISTS `cargo`;
CREATE TABLE `cargo` (
`cargo_id` int(0) NOT NULL AUTO_INCREMENT,
`cargo_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '名字',
`cargo_monad` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '单位',
`cargo_number` int(0) DEFAULT NULL COMMENT '数量',
`cargo_price` decimal(10, 2) DEFAULT NULL COMMENT '价格',
`cargo_vendor` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '生产厂商',
`cargo_statetime` date DEFAULT NULL COMMENT '入库时间',
`cargo_operator` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '操作员',
`category_id` int(0) DEFAULT NULL COMMENT '所属分类',
PRIMARY KEY (`cargo_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of cargo
-- ----------------------------
INSERT INTO `cargo` VALUES (1, '华为p80', '部', 100, 3999.00, '富士康代工', '2023-03-22', '张三', 1);
-- ----------------------------
-- Table structure for category
-- ----------------------------
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of category
-- ----------------------------
INSERT INTO `category` VALUES (1, '手机');
INSERT INTO `category` VALUES (2, '电脑');
INSERT INTO `category` VALUES (3, '家用电器');
SET FOREIGN_KEY_CHECKS = 1;
package com.yk.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
/**
* @author H.yk
* @date 2023/3/17 18:59
*
* 货物实体类
* 与货物类型是一对多关系
* 在货物表里设计一个货物类型的外键
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Cargo {
// cargo_id 货物id
private Integer cargoId;
// cargo_name 货物名字
private String cargoName;
// cargo_monad 货物单位
private String cargoMonad;
// cargo_number 货物数量
private Integer cargoNumber;
// cargo_price 货物单价
private Double cargoPrice;
// cargo_vendor 生产厂家
private String cargoVendor;
// cargo_statetime 入库时间
private String cargoStateTime;
// cargo_operator 操作员
private String cargoOperator;
// category_id 所属分类
private Integer Id;
// 货物类型的对象
private String name;
}
package com.yk.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author H.yk
* @date 2023/3/17 19:09
* 货物类型的实体类
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Category {
// 货物类型编号
private Integer id;
// 货物类型
private String name;
}
业务层实现类
1 package com.yk.service.impl; 2 3 import com.yk.dao.CargoDao; 4 import com.yk.dao.CategoryDao; 5 import com.yk.pojo.Cargo; 6 import com.yk.service.CargoService; 7 import com.yk.service.CategoryService; 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.stereotype.Service; 10 import org.springframework.transaction.annotation.Transactional; 11 12 import java.util.List; 13 14 /** 15 * @author H.yk 16 * @date 2023/3/17 19:18 17 * 货物的业务层 18 */ 19 @Service 20 @Transactional 21 public class CargoServiceImpl implements CargoService { 22 @Autowired 23 private CargoDao cargoDao; 24 @Autowired 25 private CategoryDao categoryDao; 26 @Override 27 public List<Cargo> queryCargoList () { 28 categoryDao.queryList(); 29 return cargoDao.queryCargoList(); 30 } 31 32 @Override 33 public List<Cargo> queryCargoByName (String name) { 34 return cargoDao.queryCargoByName(name); 35 } 36 37 @Override 38 public List<Cargo> queryCargoByTime (String s) { 39 return cargoDao.queryCargoByTime(s); 40 } 41 42 @Override 43 public Integer updateCargo (Cargo cargo) { 44 return cargoDao.updateCargo(cargo); 45 } 46 47 @Override 48 public Integer addCargo (Cargo cargo) { 49 return cargoDao.addCargo(cargo); 50 } 51 52 @Override 53 public Integer delCargo (Cargo cargo) { 54 return cargoDao.delCargo(cargo); 55 } 56 }
package com.yk.service.impl;
import com.yk.dao.CategoryDao;
import com.yk.pojo.Category;
import com.yk.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author H.yk
* @date 2023/3/17 19:32
* 货物类型的业务层
*/
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryDao categoryDao;
@Override
public List<Category> queryList () {
List<Category>categoryList= categoryDao.queryList();
return categoryList;
}
@Override
public Integer addCategory (Category category) {
return categoryDao.addCategory(category);
}
@Override
public Integer updateCategory (Category category) {
return categoryDao.updateCategory(category);
}
@Override
public Integer delCategory (Category category) {
return categoryDao.delCategory(category);
}
}
持久层
1 package com.yk.dao; 2 3 import com.yk.pojo.Cargo; 4 import com.yk.pojo.Category; 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.jdbc.core.BeanPropertyRowMapper; 7 import org.springframework.jdbc.core.JdbcTemplate; 8 import org.springframework.stereotype.Repository; 9 10 import java.util.List; 11 12 /** 13 * @author H.yk 14 * @date 2023/3/17 19:20 15 * 货物的持久层 16 */ 17 @Repository 18 public class CargoDao { 19 @Autowired 20 private JdbcTemplate jdbcTemplate; 21 @Autowired 22 CategoryDao categoryDao; 23 public List<Cargo> queryCargoList () { 24 String sql="SELECT * FROM `cargo`ca left join category cy on ca.category_id=cy.id"; 25 final List<Cargo> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Cargo.class)); 26 return query; 27 } 28 29 public List<Cargo> queryCargoByName (String name) { 30 String sql="SELECT * FROM `cargo` ca left join category cy on ca.category_id=cy.id where cargo_name like ?"; 31 final List<Cargo> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Cargo.class),"%"+name+"%"); 32 return query; 33 } 34 35 public List<Cargo> queryCargoByTime (String s) { 36 String sql="SELECT * FROM `cargo` ca left join category cy on ca.category_id=cy.id where cargo_statetime= ?"; 37 final List<Cargo> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Cargo.class),s); 38 return query; 39 } 40 41 public Integer updateCargo (Cargo cargo) { 42 String sql="update cargo set cargo_name=? where cargo_id=?"; 43 int update = jdbcTemplate.update(sql, cargo.getCargoName(),cargo.getCargoId()); 44 return update; 45 } 46 47 public Integer addCargo (Cargo cargo) { 48 String sql="INSERT INTO cargo (cargo_name,cargo_monad,cargo_number,cargo_price,cargo_vendor,cargo_statetime,cargo_operator,category_id)VALUES(?,?,?,?,?,?,?,?)"; 49 int update = jdbcTemplate.update(sql, cargo.getCargoName(),cargo.getCargoMonad(),cargo.getCargoNumber(),cargo.getCargoPrice(),cargo.getCargoVendor(),cargo.getCargoStateTime(),cargo.getCargoOperator(),cargo.getId()); 50 return update; 51 } 52 53 public Integer delCargo (Cargo cargo) { 54 String sql="delete from cargo where cargo_id=?"; 55 int update = jdbcTemplate.update(sql,cargo.getCargoId() ); 56 return update; 57 } 58 }
货物类型的持久层
package com.yk.dao;
import com.yk.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author H.yk
* @date 2023/3/17 19:40
* 货物类型的持久层
*/
@Repository
public class CategoryDao {
@Autowired
JdbcTemplate jdbcTemplate;
public List<Category> queryList () {
String sql="SELECT * FROM `category`";
final List<Category> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Category.class));
return query;
}
public Integer addCategory (Category category) {
String sql="INSERT INTO category(name)VALUES(?)";
int update = jdbcTemplate.update(sql, category.getName());
return update;
}
public Integer updateCategory (Category category) {
String sql="update category set name=? where id=?";
int update = jdbcTemplate.update(sql, category.getName(),category.getId());
return update;
}
public Integer delCategory (Category category) {
String sql="delete from category where id=?";
int update = jdbcTemplate.update(sql,category.getId());
return update;
}
}
货物的测试类(代替控制层做输出)crud和模糊查询
1 package com.yk; 2 3 import com.yk.pojo.Cargo; 4 import com.yk.pojo.Category; 5 import com.yk.service.CargoService; 6 import org.junit.jupiter.api.Test; 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.boot.test.context.SpringBootTest; 9 10 import java.util.Date; 11 import java.util.List; 12 13 /** 14 * @author H.yk 15 * @date 2023/3/17 19:14 16 * 货物的测试类方法(代替货物的控制层做输出) 17 */ 18 @SpringBootTest 19 public class CargoTest { 20 @Autowired 21 private CargoService cargoService; 22 23 24 /** 25 * 查询所有商品集合 26 */ 27 @Test 28 public void queryCargoList(){ 29 30 List<Cargo> cargoList= cargoService.queryCargoList(); 31 cargoList.forEach(System.out::println); 32 } 33 /** 34 * 根据商品名模糊查询 35 */ 36 @Test 37 public void queryCargoByName(){ 38 39 List<Cargo> cargoList= cargoService.queryCargoByName("华为"); 40 cargoList.forEach(System.out::println); 41 } 42 43 /** 44 * 根据时间查询 45 */ 46 @Test 47 public void queryCargoByTime(){ 48 49 List<Cargo> cargoList= cargoService.queryCargoByTime("2023-03-22"); 50 cargoList.forEach(System.out::println); 51 } 52 53 /** 54 * 添加商品信息 55 */ 56 @Test 57 public void addCargo () { 58 Cargo cargo = new Cargo(0,"联想手机","部",1000,100.9,"联发科","2023-09-09","小明",1,null); 59 Integer i = cargoService.addCargo(cargo); 60 if (i > 0) { 61 System.out.println("添加成功"); 62 } else { 63 System.out.println("添加失败"); 64 } 65 } 66 67 /** 68 * 修改商品信息 69 */ 70 @Test 71 public void updateCargo () { 72 Cargo cargo = new Cargo(); 73 cargo.setCargoId(1); 74 cargo.setCargoName("小米手机"); 75 Integer i = cargoService.updateCargo(cargo); 76 if (i > 0) { 77 System.out.println("修改成功"); 78 } else { 79 System.out.println("修改失败"); 80 } 81 } 82 /** 83 * 根据id删除之情的商品类型 84 */ 85 @Test 86 public void delCargo () { 87 Cargo cargo = new Cargo(); 88 cargo.setCargoId(1); 89 Integer i = cargoService.delCargo(cargo); 90 if (i > 0) { 91 System.out.println("删除成功"); 92 } else { 93 System.out.println("删除失败"); 94 } 95 } 96 }
货物类型的crud测试类(代替控制层做输出)
1 package com.yk; 2 3 import com.yk.pojo.Category; 4 import com.yk.service.CategoryService; 5 import org.junit.jupiter.api.Test; 6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.boot.test.context.SpringBootTest; 8 9 import java.util.List; 10 11 /** 12 * @author H.yk 13 * @date 2023/3/17 19:30 14 * 货物类型的测试类(代替货物类型的控制层) 15 */ 16 @SpringBootTest 17 public class CategoryTest { 18 @Autowired 19 private CategoryService categoryService; 20 21 /** 22 * 查询商品类型集合 23 */ 24 @Test 25 public void queryList () { 26 List<Category> categoryList = categoryService.queryList(); 27 categoryList.forEach(System.out::println); 28 } 29 30 /** 31 * 添加商品类型 32 */ 33 @Test 34 public void addCategory () { 35 Category category = new Category(0, "家用电器"); 36 Integer i = categoryService.addCategory(category); 37 if (i > 0) { 38 System.out.println("添加成功"); 39 } else { 40 System.out.println("添加失败"); 41 } 42 } 43 44 /** 45 * 修改商品类型 46 */ 47 @Test 48 public void updateCategory () { 49 Category category = new Category(); 50 category.setId(2); 51 category.setName("战时用品"); 52 Integer i = categoryService.updateCategory(category); 53 if (i > 0) { 54 System.out.println("修改成功"); 55 } else { 56 System.out.println("修改失败"); 57 } 58 } 59 60 /** 61 * 根据id删除之情的商品类型 62 */ 63 @Test 64 public void delCategory () { 65 Category category = new Category(); 66 category.setId(2); 67 Integer i = categoryService.delCategory(category); 68 if (i > 0) { 69 System.out.println("删除成功"); 70 } else { 71 System.out.println("删除失败"); 72 } 73 } 74 75 }