指路(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
根据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);
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>
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;
推荐使用yml配置文件
#Mybatis配置
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
👆部分配置文件内容
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:
相同点:
不同点: