指路(1)(2)(3)👇
黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(1)准备工作、部门管理_tlias智能学习辅助系统的需求分析-CSDN博客https://blog.csdn.net/YOYU_/article/details/135476566黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(2)员工管理|分页查询、分页查询(带条件)-CSDN博客https://blog.csdn.net/YOYU_/article/details/135491233黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(3)员工管理|新增员工、文件上传-CSDN博客https://blog.csdn.net/YOYU_/article/details/135513546
一、修改员工
1.查询回显
根据id查询员工
EmpController:
@GetMapping("/{id}")public Result getById(@PathVariable Integer id){log.info("按照id查询员工,id{}" + id);Emp emp = empService.getById(id);return Result.success(emp);}
EmpMapper:
@Select("select * from emp where id = #{id}")Emp getById(Integer id);
2.修改员工
EmpMapper(动态SQL):
<update id="update">update emp<set><if test="username != null and username != ''">username = #{username},</if><if test="password != null and password != ''">password = #{password},</if><if test="name != null and name != ''">name = #{name},</if><if test="gender != null">gender = #{gender},</if><if test="image != null and image != ''">image = #{image},</if><if test="job != null">job = #{job},</if><if test="entrydate != null">entrydate = #{entrydate},</if><if test="deptId != null">dept_id = #{deptId},</if><if test="updateTime != null">update_time = #{updateTime},</if></set>where id = #{id}</update>
结果展示:
前后端联调:
二、配置文件
1.参数配置化
【@Value注解】用于外部配置的属性注入,具体方法为@Value("${配置文件中的key}")
AliOSSUtils.java:
private String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";private String accessKeyId = "LTAI5tGSj4igifA1HqxkErg2";private String accessKeySecret = "gm5mxGT65hYlFGlWKlsVkCnChGiS5x";private String bucketName = "web-tlias-casey";
优化配置到properties文件中==》
application.properties
@Value("${aliyun.oss.endpoint}")private String endpoint;@Value("${aliyun.oss.accessKeyId}")private String accessKeyId;@Value("${aliyun.oss.accessKeySecret}")private String accessKeySecret;@Value("${aliyun.oss.bucketName}")private String bucketName;
2.yml配置文件
推荐使用yml配置文件
#Mybatis配置
mybatis:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmap-underscore-to-camel-case: true
👆部分配置文件内容
3.@ConfigurationProperties:自动将配置文件中的配置项注入到bean对象的属性中
AliOSSProperties.java 新设置一个bean对象,xml配置文件的值会直接注入到以下四个属性中
@Data
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class AliOSSProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;
}
AliOSSUtils.java
@Autowiredprivate AliOSSProperties AliOSSProperties;//注入之后下面的参数报红,需要增加 获取阿里云OSS参数
@ConfigurationProperties和@Value:
相同点:
- 都是用来注入外部配置的属性
不同点:
- @Value注解只能一个一个的进行外部属性的注入
- @ConfigurationProperties可以批量的将外部属性注入到bean对象的属性中