黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(4)员工管理|修改员工、配置文件

指路(1)(2)(3)👇

黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(1)准备工作、部门管理_tlias智能学习辅助系统的需求分析-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/YOYU_/article/details/135476566黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(2)员工管理|分页查询、分页查询(带条件)-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/YOYU_/article/details/135491233黑马程序员JavaWeb开发|案例:tlias智能学习辅助系统(3)员工管理|新增员工、文件上传-CSDN博客icon-default.png?t=N7T8https://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.StdOutImpl
    map-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 

    @Autowired
    private AliOSSProperties AliOSSProperties;
    //注入之后下面的参数报红,需要增加 获取阿里云OSS参数

@ConfigurationProperties和@Value:

相同点:

  • 都是用来注入外部配置的属性

不同点:

  • @Value注解只能一个一个的进行外部属性的注入
  • @ConfigurationProperties可以批量的将外部属性注入到bean对象的属性中
  • 15
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Buuuleven.(程序媛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值