zl程序教程

您现在的位置是:首页 >  其他

当前栏目

项目开发知识盲区整理2

2023-03-14 22:39:33 时间

项目开发知识盲区整理2

SpringBoot运行Test时报错:SpringBoot Unable to find a @SpringBootConfiguration

把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像这样:

SpringBoot运行Test时报错:SpringBoot Unable to find a @SpringBootConfiguration


mp代码生成模板–mybait-plus

@SpringBootTest(classes = Demo1Application.class)
class Demo1ApplicationTests {

    @Test
    void contextLoads()
    {
        //获取当前系统的目录
        String ObjectPath = System.getProperty("user.dir");

        //1.全局策略配置
        GlobalConfig config = new GlobalConfig();
        config.setActiveRecord(true)//是否支持AR模式
                .setAuthor("大忽悠")//作者
                .setOutputDir(ObjectPath+"/src/main/java")//生成路径
                .setFileOverride(true)//文件覆盖
                .setIdType(IdType.AUTO)//主键策略
                .setServiceName("%sService")//设置生成service接口名字的首字母是否为I(默认会生成I开头的IStudentService)
                .setBaseResultMap(true)//自动SQL映射文件,生成基本的ResultMap
                .setBaseColumnList(true);//生成基本的SQL片段

        //2.数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)//设置数据库类型
                .setDriverName("com.mysql.jdbc.Driver")//数据库驱动名
                .setUrl("jdbc:mysql://localhost:3306/tx?useUnicode=true&characterEncoding=UTF-8")//数据库地址
                .setUsername("root")//数据库名字
                .setPassword("126433");//数据库密码


        //3.策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setCapitalMode(true)//全局大写命名
                .setNaming(NamingStrategy.underline_to_camel)//数据库表映射到实体的命名策略
                .setColumnNaming(NamingStrategy.underline_to_camel)//列的命名也支持驼峰命名规则
                .setInclude("s_coursetype")//设置要映射的表名,这里可以写多个
                .setEntityLombokModel(true)  //使用Lombok开启注解
                .setRestControllerStyle(true)//开启驼峰命名格式
                .setControllerMappingHyphenStyle(true);//controller层,开启下划线url : //localhost:8080/hello_id_2

        //4.包名策略
        PackageConfig packageConfig = new PackageConfig();
        packageConfig
                .setModuleName("com")//设置模块名
                .setParent("xfx")//所放置的包(父包)
                .setMapper("mapper")//Mapper包
                .setService("service")//服务层包
                .setController("controller")//控制层
                .setEntity("pojo")//实体类
                .setXml("mapper");//映射文件
        //5.整合配置
        AutoGenerator autoGenerator = new AutoGenerator();
        autoGenerator.setGlobalConfig(config)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategy)
                .setPackageInfo(packageConfig);
        //6.执行
        autoGenerator.execute();
    }
}

xm-select下拉树

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		
		<div id="demo1" class="xm-select-demo"></div>
		
	</body>
	

	<script src="./xm-select.js"></script>
	<script>


	var demo1 = xmSelect.render({
		el: '#demo1', //绑定的容器id
		autoRow: true,//自动换行
		filterable: true,//开启搜索框
		tree: {
			//显示树状结构
			show: true,
			//展示三角图标
			showFolderIcon: true,
			//展示分割线
			showLine: true,
			//间距
			indent: 20,
			//默认无展开
			expandedKeys: [],
		},
		//工具栏
		toolbar: {
			show: true,
			//只显示全选和清空
			list: ['ALL', 'CLEAR']
		},
		//开启搜索,默认按照name搜索
		filterable: true,
		//高度自动
		height: 'auto',
		//数据
		data: function(){
			return [
				{name: '常规课程', value: -1, children: [
					{name: '三岁课程', value:-2,children:[
						{name:'搭积木',value:1},
						{name:'拆积木',value:2},
					]},
					{name: '四岁课程', value:-3,children:[
						{name:'搭积木',value:3},
						{name:'拆积木',value:4},
					]},
					{name: '五岁课程', value:-4,children:[
						{name:'搭积木',value:5},
						{name:'拆积木',value:6},
					]},
				]},
				{name: '假期课程', value: -5, children: [
					
					{name: '寒假课程', value: -6, children: [
						{name: '课程1', value: 7},
						{name: '课程2', value: 8},
						{name: '课程3', value: 9},
					]},
					
					
					{name: '暑假课程', value: -7, children: [
						{name: '课程1', value: 10},
						{name: '课程2', value: 11},
						{name: '课程3', value:12},
					]},
				]},
				
				
			]
		}
	})
	//闭合所有节点
	demo1.changeExpandedKeys(false)
	</script>
</html>

xm-select

级联模式

        var demo2 = xmSelect.render({
            el: '#course', //绑定的容器id
            autoRow: true,//自动换行
            filterable: true,//开启搜索框
            //设置父图标的样式
            iconfont: {parent:'layui-icon layui-icon-table'},
            //下拉方向向下
            direction: 'down',
            //级联模式显示
                cascader: {
                    //是否显示级联模式
                    show: true,
                    //间距
                    indent: 200,
                    //是否严格遵守父子模式
                    strict: true,
                },
            //工具栏
            toolbar: {
                show: true,
                //只显示全选和清空
                list: ['ALL', 'CLEAR']
            },
            //开启搜索,默认按照name搜索
            filterable: true,
            //高度自动
            height: 'auto',
            //数据
            data: function ()
            {
                var res;
                //使用axios发送ajax请求
                $.ajax({
                    url: 'getCurriculumSystems',
                    type: "post",
                    dataType: "json",
                    async : false,//同步
                    success: function (data)
                    {
                      res=data
                    },
                    error: function ()
                    {
                        alert("出现异常")
                    }
                })
                return res
            },
            tips: '为当前用户开通课程权限',
            empty: '当前没有课程可以选择',
            searchTips: '搜索课程',
            paging: true,
            pageSize: 3,
            filterable: true,
            pageEmptyShow: false,
            theme: {
                color: '#0081ff',
            }
        })

data数据格式说明

	return [
				{name: '常规课程', value: -1, children: [
					{name: '三岁课程', value:-2,children:[
						{name:'搭积木',value:1},
						{name:'拆积木',value:2},
					]},
					{name: '四岁课程', value:-3,children:[
						{name:'搭积木',value:3},
						{name:'拆积木',value:4},
					]},
					{name: '五岁课程', value:-4,children:[
						{name:'搭积木',value:5},
						{name:'拆积木',value:6},
					]},
				]},
				{name: '假期课程', value: -5, children: [
					
					{name: '寒假课程', value: -6, children: [
						{name: '课程1', value: 7},
						{name: '课程2', value: 8},
						{name: '课程3', value: 9},
					]},
					
					
					{name: '暑假课程', value: -7, children: [
						{name: '课程1', value: 10},
						{name: '课程2', value: 11},
						{name: '课程3', value:12},
					]},
				]},	
			]

如果value值为负数,说明其下面还有小分类,并且当我们展开常规课程时,常规课程对应的value=-1,那么下面如果出现重复的value值同样为-1,那么其同样会被展开

展开value为负数的下拉框时,与当前负数vlaue相同的下拉框也会被展开,因此负数value不要重复

当我们选择一个正数value的选项时,与当前正数value相同的选项同样会被选中,因此正数value也不要重复

总结:value值不要重复


@MapKey的使用

@MapKey("id")
Map<Long,Map<String,String>> getInfoById(@Param("id") Long id, @Param("name") String name);

查询结果:

// 查询,返回结果:{1={area:上海,companyName=西西公司}}
// 如果是多条记录,返回结果如:{1={area:上海,companyName:西西公司},2={area:南京,compantyName:猴猴公司}}
Map<Long, Map<String, String>> map = productDao.getInfoById(id, "公司名称"); 

@MapKey的使用

如果是下面这种情况,相把返回的每一条记录封装为一个map,然后用一个list集合来存放这些map,此时因为返回值用到了map,就必须加@MapKey指定key值,如果对于的key值,返回结果没找到,那么不会有任何效果

    //获取所有课程体系
    @MapKey("id")
    public List<Map<Object,Object>> getCurriculumSystems();
    <select id="getCurriculumSystems" resultType="java.util.Map">
        SELECT c.courseName,sc.cname,ct.type FROM course c,s_coursetype sc,coursetype ct
        WHERE c.stype_id=sc.id AND c.type_id=ct.id;
    </select>

js的split和java的split函数一样,按照空格分割,返回分割得到的新数组

  var powerArr = uPow.split(" ");
  //这里是x-select设置多选框被选中,传入一个数组,设置多个被选中
  demo2.setValue(powerArr);

Linux环境下Springboot项目配置文件访问路径

在项目开发中总会需要访问服务器上的文件,如果是Tomcat项目,就可以直接在Tomcat中配置虚拟路径,接下来就看看如何在springboot项目中配置虚拟路径。

如下的config类中设置一个资源访问路径(upload),映射到本地件。

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    // 添加文档对应的映射
    registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    // 添加对应的映射
    registry.addResourceHandler("/qy/**").addResourceLocations("classpath:/static/qy/");
      registry.addResourceHandler("/img/**")
                .addResourceLocations("file:"+pathReader.getFilePath());
    super.addResourceHandlers(registry);
}
}

file代表真实路径

classpath代表类路径

linux下映射的本地文件应写成

file:/home/newsaas/ideatest-dev/file/upload/e_invoice 

但是实际项目发布后又发现虚拟路径没有生效,后面才发现我们的项目是配置了Nginx的,所以只需要在Nginx的配置文件中配置好访问路径就可以了。Nginx配置如下:

// location 后面跟的就是资源访问的路径
location /upload/ {
            //alias 后面跟的是映射的文件夹,该文件夹下的文件就可以被访问了
            alias   /home/newsaas/ideatest-dev/file/upload/;
            index  index.html index.htm;
        }	

自定义SpringBoot默认MVC配置的采坑实录

自定义SpringBoot默认MVC配置?好几个坑,这篇文章必须珍藏

springboot通过设置addResourceHandlers拦截请求访问本地资源踩坑实战


如何让linux后台一直运行springboot项目以及启动失败的问题

// An highlighted block
nohup java -jar blog.jar &
提示nohup: ignoring input and appending output to 'nohup.out'

如何让linux后台一直运行springboot项目以及启动失败的问题


POST提交数据之—Content-Type的理解

ContentType: application/json :前端返回给后端的是json字符串形式,而不是name=123&age=18的请求参数形式

POST提交数据之—Content-Type的理解


File类–新建文件,新建目录,递归删除目录

File类的createNewFile()

createNewFile();返回值为 boolean; 方法介绍:当且仅当不存在具有此抽象路径名指定名称的文件时,不可分地创建一个新的空文件。 使用: File file = new File(“D: est1.txt”); boolean res = file.createNewFile(); if(!res)System.out.println(“创建失败!”); 如果D:/test 目录下没有 1.txt文件,则创建该文件;如果没有test目录,直接抛出异常,如果1.txt已经存在,那么文件创建失败。 可以得知,createNewFile() 方法,根据抽象路径创建一个新的空文件,当抽象路径制定的文件存在时,创建失败。

mkdir()和mkdirs()区别

mkdir()和mkdirs()区别如下:

mkdirs()可以建立多级文件夹, mkdir()只会建立一级的文件夹, 如下:

new File("/tmp/one/two/three").mkdirs();

执行后, 会建立tmp/one/two/three四级目录

new File("/tmp/one/two/three").mkdir();

则不会建立任何目录, 因为找不到/tmp/one/two目录, 结果返回false

递归删除目录及下面的文件

public static void deleteAll(File file) {

        if (file.isFile() || file.list().length == 0) {
            file.delete();
        } else {
            for (File f : file.listFiles()) {
                deleteAll(f); // 递归删除每一个文件

            }
            file.delete(); // 删除文件夹
        }
    }

jquery中如何实现按回车触发按钮事件

 //回车提交事件
         $("body").keydown(function() {
             if (event.keyCode == "13") {//keyCode=13是回车键
                 $('#btnSumit').click();
             }
         });
         //--------回车提交事件完毕---------------------//

java中Class.forName的作用以及为什么加载数据库驱动包的时候有的却没有调用newInstance( )方法呢?

https://blog.csdn.net/weixin_30278237/article/details/94936860


sleep与wait的区别? 以及wait(long timeout)中timeout的含义

sleep是Thread的静态native方法,可随时调用,会使当前线程休眠,并释放CPU资源,但不会释放对象锁;

 public static native void sleep(long millis) throws InterruptedException;

wait方法是Object的方法,只能在同步方法或同步代码块中使用,调用会进入休眠状态,并释放CPU资源与对象锁,需要我们调用notify/notifyAll方法唤醒指定或全部的休眠线程,进入锁池,再次竞争CPU资源.

public final native void wait(long timeout) throws InterruptedException;

timeout:最大等待时间(毫秒),超过会被唤醒,再次进入锁池.

java:一个 wait(timeout) 引出的你可能对锁的误解

  1. sleep 是 Thread 方法,而 wait 是 Object 的方法
  2. sleep 不需要强制和 synchronized 配合使用,但 wait 需要和 synchronized 一起用
  3. sleep 在睡眠的同时,不会释放对象锁的,但 wait 在等待的时候会释放对象锁
  4. 它们状态 TIMED_WAITING

你真的懂object.wait和 wait(long timeout)的区别吗


getResourceAsStream的理解和用法

Java中getResourceAsStream的用法

加载.properties配置文件的三种方式

Properties类,配置文件,文件路径


Java之Enumeration接口

https://blog.csdn.net/qq_43639698/article/details/108619505


深入理解Java枚举类型(enum)

https://blog.csdn.net/javazejian/article/details/71333103


request.getRequestURL()等方法得到路径的区别

request.getRequestURL() 返回全路径 request.getRequestURI() 返回除去host(域名或者ip)部分的路径 request.getContextPath() 返回工程名部分,如果工程映射为/,此处返回则为空 request.getServletPath() 返回除去host和工程名部分的路径

此处是运行结果

request.getRequestURL():http://localhost:8080/bzbs/system/login.jsp request.getRequestURI():/bzbs/system/login.jsp request.getContextPath():/bzbs request.getServletPath():/system/login.jsp


解决docker容器内时区和宿主机不一致,相差8小时的问题

docker容器内时区相差8小时问题


Springboot配置ssl证书踩坑记

Springboot配置ssl证书踩坑记


Ubuntu 18.04 设置root远程登录

Ubuntu 18.04 设置root远程登录


Ubuntu MySQL允许远程连接访问

https://blog.csdn.net/hanshileiai/article/details/46967081


Layui官方文档镜像链接

layui镜像站


ObjectMapper详细介绍,真的就这么简单

ObjectMapper详细介绍,真的就这么简单

Jackson基础教程


idea右键项目没有git

右键项目,没有git选项

解决方法:

进入settings,然后搜索version,按下图点击即可:

over,解决:


live2dw插件–cdn使用

<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
 
<script>
    L2Dwidget.init({
        "model": {
            jsonPath: "https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json",
            "scale": 1
        },
        "display": {
            "position": "right",
            "width": 75,
            "height": 150,
            "hOffset": 0,
            "vOffset": -20
        },
        "mobile": {
            "show": true,
            "scale": 0.5
        },
        "react": {
            "opacityDefault": 0.7,
            "opacityOnHover": 0.2
        }
    });
</script>
<!--
	其他可选的模型: 
		小帅哥: https://unpkg.com/live2d-widget-model-chitose@1.0.5/assets/chitose.model.json
		萌娘:https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json 
		小可爱(女):https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json 
		小可爱(男):https://unpkg.com/live2d-widget-model-haruto@1.0.5/assets/haruto.model.json
		初音:https://unpkg.com/live2d-widget-model-miku@1.0.5/assets/miku.model.json 
-->

博客右下角的动态人物(live2d)

17款皮肤

L2Dwidget.js网页看板娘的使用总结

Live2d看板娘教程

L2Dwidget二次元看板娘的web用法

git链接 吸附球

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
	$(function(){
	  function n(n,e,t){
	     return n.getAttribute(e)||t
	   }
	   function e(n){
	     return document.getElementsByTagName(n)
	   }
	   function t(){
	     var t=e("script"),o=t.length,i=t[o-1];
		  return{l:o,z:n(i,"zIndex",-1),o:n(i,"opacity",.6),c:n(i,"color","46,139,87"),n:n(i,"count",150)}
	   }
	   function o(){
	     a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,
		  c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight
	   }
	   function i(){
	     r.clearRect(0,0,a,c);
		  var n,e,t,o,m,l;
		  s.forEach(function(i,x){
		    for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e<u.length;e++)n=u[e],
			   null!==n.x&&null!==n.y&&(o=i.x-n.x,m=i.y-n.y,
			   l=o*o+m*m,l<n.max&&(n===y&&l>=n.max/2&&(i.x-=.03*o,i.y-=.03*m),
				t=(n.max-l)/n.max,r.beginPath(),r.lineWidth=t/2,r.strokeStyle="rgba("+d.c+","+(t+.2)+")",r.moveTo(i.x,i.y),r.lineTo(n.x,n.y),r.stroke()))
		  }),
		  x(i)
    }
    var a,c,u,m=document.createElement("canvas"),d=t(),l="c_n"+d.l,r=m.getContext("2d"),
	   x=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||
    function(n){
      window.setTimeout(n,1e3/45)
    },
    w=Math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.cssText="position:fixed;top:0;left:0;z-index:"+d.z+";opacity:"+d.o,e("body")[0].appendChild(m),o(),window.onresize=o,
    window.onmousemove=function(n){
      n=n||window.event,y.x=n.clientX,y.y=n.clientY
    },
    window.onmouseout=function(){
      y.x=null,y.y=null
    };
	  for(var s=[],f=0;d.n>f;f++){
		  var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3})
	   }
	  u=s.concat([y]),
	  setTimeout(function(){i()},100)
	});
</script>