在命运的前面
我怀疑
在面具后面
铁一般决心
这边的
@MapperScan : https://blog.csdn.net/nba_linshuhao/article/details/82783454其实就是让接口变成实现类,然后加上@Mapper,
但是每个都要加就很麻烦,所以直接用@MapperScan 来表示要变成实现类的接口的所在的包。
这个主要是搭载mybatis和mybatis plus等来使用,mapper注解一般来实现的是
类似:
import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; public interface BaseTableMapper { @Select("select table_name,table_comment from information_schema.TABLES where TABLE_SCHEMA=#{schema}") List<Map> getListTablesByDataBase(String schema); @Select("select table_schema,table_name,table_type,table_comment from information_schema.TABLES") List<Map> allTables(); @Select("select table_schema,table_name,column_name,column_type,column_key,column_comment from information_schema.COLUMNS where TABLE_NAME=#{tableName}") List<Map> listTableColumns(String tableName); }springboot项目,若打包成war包,使用外置的tomcat启动
1、需要继承 org.springframework.boot.context.web.SpringBootServletInitializer类
2、然后重写configure(SpringApplicationBuilder application)方法 因为我们的项目是打成war包,然后部署到tomcat的~(还延续了mvc的方式)
因为项目中有时候需要项目启动之后,执行某些功能。
所以简单的实现方案就是来进行实现
CommandLineRunner接口,实现功能的代码放在实现的run方法中
当然也可以写在一个model类里面,也可以写在启动类的里面。
比如:
import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @Component public class MyStartupRunner implements CommandLineRunner { @Override public void run(String... args) throws Exception { System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作<<<<<<<<<<<<<"); } }# 如果有多个类实现CommandLineRunner接口,如何保证顺序 > SpringBoot在项目启动后会遍历所有实现CommandLineRunner的实体类并执行run方法,如果需要按照一定的顺序去执行,那么就需要在实体类上使用一个@Order注解(或者实现Order接口)来表明顺序
比如在类的上面加上@Order(value=2)
@Order 注解的执行优先级是按value值从小到大顺序。
参考了:https://www.cnblogs.com/myblogs-miller/p/9046425.html
PS:
String os = System.getProperty("os.name");这样可以获得你当前操作系统的名字,比如我用的是win10 就可以获取到 Windows 10
我们的需求是启动了项目之后,根据环境修改一下对应的视频流脚本~
然后可以这样来重写一个run接口~
比如
@Override public void run(String... args) throws Exception { String os = System.getProperty("os.name"); log.info(os); if (os.toUpperCase().contains("WIN")){ return; } log.info("开始修改文件权限..."); String absolutePath = new ClassPathResource("ffmpeg/"+ SystemConstants.HANDLE_VIDEO_COMMAND_TEMPLATE).getFile().getAbsolutePath(); StringBuilder commandBuilder1 = new StringBuilder("chmod +x").append(" ").append(absolutePath); new FfmpegRunner().runWithNoMsgWaitFor(commandBuilder1.toString(), "start_video_chmod"); //sed -i "s/\r//g" test.sh StringBuilder commandBuilder2 = new StringBuilder("sed -i").append(" ").append("s/\\r//g").append(" ").append(absolutePath); new FfmpegRunner().runWithNoMsgWaitFor(commandBuilder2.toString(), "start_video_sed"); log.info("修改文件权限完成..."); }
