
阅读博客遇到的任何问题可以加微信2335515050咨询
安装 anaconda创建anaconda虚拟环境conda create --name hesuan启用环境conda activate hesuan安装依赖conda install numpyVSCode选择刚才创建的虚拟环境
<el-select size="small" style="flex-grow: 1;flex-basis: 0" v-model="selRole" placeholder="角色名称" value-key="yt2100" @change="onRoleSelected" > <el-option v-for="item in roleList " :key="item.yt2100" :label="item.yt2102" :value="item" > </el-option> </el-select>
Springboot校验器添加依赖implementation 'org.springframework.boot:spring-boot-starter-validation'Controller层@Api(tags = "用户相关接口") @RestController @RequestMapping("/user") @Slf4j @Validated //注意这个注解 public class UserController {方法 @ApiOperation(value = "用户登录") @PostMapping(value = "/modify") public ApiResponse modifyUser( @RequestBody @Valid RequestUserInfo userInfo) { log.info(JSON.toJSONString(userInfo)); return ApiResponse.success("提交成功"); }对象@Data @NoArgsConstructor @AllArgsConstructor public class RequestUserInfo { @NotBlank(message = "姓名不能为空") private String name; @NotBlank(message = "身份证不能为空") private String idCardNum; @NotBlank(message = "出生日期不能为空") private String birthDay; }以上三个缺一不可
点一下图上的定位按钮就会跳到对应的activity当中去
通过root 用户局域网访问mysql无法访问必须另外创建用户 create user 'nurmemet'@'%' identified by '112233'; 刷新权限 flush privileges; 给新添加的用户分配访问已有数据库的权限,intildb是数据库名称,你可以改成自己的数据库名称 grant all privileges on intildb.* to 'nurmemet'@'%';
sudo service msyql stop sudo service mysql start sudo service mysql restart
sudo cat /etc/mysql/debian.cnf
apt-get autoremove --purge mysql-server apt-get remove mysql-common
tar -xvf 文件名 -C 解压目录 # 注意一定要指定目录不然会解压到当前目录,而且解压目录必须存在的
useradd username -m 设置密码 passwd username Enter new UNIX password: 123456 Retype new UNIX password: 123456 改变组 usermod -g root username 确定是否在root组 id username uid=1001(username) gid=0(root) groups=0(root)``
facebook pytorch 深度学习 python 自然语言处理库 facebook python caffe2 深度学习
首先进入用户目录 cd ~/ 查看用户目录隐藏文件 ls -a 新建git配置文件 vim .git-credentials 输入 https://{username}:{password}@github.com 例如 https://zhang3:12345@github.com 保存推出,再执行命令 git config --global credential.helper store 执行完后 进入用户目录 cd ~/ 打开.gitconfig文件,会发现多出了一行内容helper = store [credential] helper = store 现在输入git pull命令拉取代码会发现已经不需要输入密码了
war 文件放到任意目录,打开Tomcat根目录下的conf文件夹下的server.xml文件在Host节点下main添加一个Context节点 <Context docBase="/home/nurmemet/webapps/intil-0.0.1-SNAPSHOT.war" path="intil"/> docBase也可以是相对路径也可以是绝对路径,当相对路径的时候,是相对于Host节点的appBase,比如说appBase设置为/home/webappsdocBase设置为myapp1,意思是把war包放到/home/webapps/myapp1文件夹下面。path的含义是访问项目的时候要加上path,比如,现在要访问我们配置的项目的话要输入http://...:8080/intil/ 开始
http请求 ContentType默认为x-www-form-urlencoded,当method为post的时候客户端发送的数据会放到requestbody里面以纯文本的形式发送如图所示,如果用java要发送以下形式的数据wireshark截图flidder截图spring可以以下方式接受如果ContentType 改成application/json fiddler截图wireshark截图spring接受
project 标签下添加一下代码 在project标签下添加 <repositories><!-- 代码库 --> <repository> <id>maven-ali</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> <repository> <id>maven-uk</id> <url>https://maven.tmatesoft.com/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> <repository> <id>maven-repo1</id> <url>https://repo1.maven.org/maven2/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> <repository> <id>maven-center2</id> <url>http://central.maven.org/maven2/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> </repositories>
首先下载redis redis下载地址 #https://redis.io/download 下载 wget http://download.redis.io/releases/redis-5.0.4.tar.gz 解压 ,解压到当前目录下 tar -xzvf redis-5.0.4.tar.gz 进入Redis 目录,make 命令进行编译 make make install 修改配置文件把bind 127.0.0.1 修改为 0.0.0.0daemonize no 修改为yes vim redis.conf 启动redis
idea 识别不出 springboot 项目,可能是没有启用idea springboot 插件看看有没有被勾上
首先查看mysql root用户权限就可以远程登陆了
修改配置maven下载mysql jdbc driver地址https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.16配置mysql jdbc driver
注意下面的框框里面的是完整的临时密码下一步使用此密码重设MySQL密码提示密码太简单修改密码策略 再重设密码新密码登录Mysql
mysql官网下载rpm包https://dev.mysql.com/downloads/repo/yum/启动mysql服务
解压到当前目录解压到指定目录
project标签下添加以下代码 <repositories><!-- 代码库 --> <repository> <id>maven-ali</id> <url>http://maven.aliyun.com/nexus/content/groups/public//</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> </repositories>
<!--控件要设置尺寸的话,设置的尺寸必须比下面的图形的尺寸要小,不然显示不开--> <Label Content="直角测试" Width="90" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="359,207,283,62" > <Label.Background> <VisualBrush > <VisualBrush.Visual> <Path Stroke="Red" SnapsToDevicePixels="True" StrokeThickness="3" > <Path.Data> <PathGeometry> <PathFigure StartPoint="0,0"> <!--折线图--> <PolyLineSegment Points="100,0 100,90 55,90 50,100 45,90 0,90 0,0"></PolyLineSegment> </PathFigure> </PathGeometry> </Path.Data> </Path> </VisualBrush.Visual> </VisualBrush> </Label.Background> </Label> <Label Content="圆角测试" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="16,273,653,20" > <Label.Background> <VisualBrush Stretch="Fill"> <VisualBrush.Visual> <Path Stroke="Red" StrokeThickness="2" Stretch="UniformToFill"> <Path.Data> <PathGeometry> <!--路径开始点--> <PathFigure StartPoint="5,0"> <!--线段--> <LineSegment Point="95,0"></LineSegment> <!--弧形--> <ArcSegment Point="100,5" Size="5,5" SweepDirection="Clockwise"></ArcSegment> <!--线段--> <LineSegment Point="100,85"></LineSegment> <!--弧形--> <ArcSegment Point="95,90" Size="5,5" SweepDirection="Clockwise"></ArcSegment> <!--折线--> <PolyLineSegment Points="55,90 50,100 45,90 5,90"></PolyLineSegment> <!--弧形--> <ArcSegment Point="0,85" Size="5,5" SweepDirection="Clockwise"></ArcSegment> <!--线段--> <LineSegment Point="0,5"></LineSegment> <!--弧形--> <ArcSegment Point="5,0" Size="5,5" SweepDirection="Clockwise"></ArcSegment> </PathFigure> </PathGeometry> </Path.Data> </Path> </VisualBrush.Visual> </VisualBrush> </Label.Background> </Label> 效果图
添加一个绘图面板项目按右键添加类DrawingPanel using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace Drawing { class DrawingPanel :Panel { //所有图形 private List<Visual> visuals = new List<Visual>(); private List<DrawingVisual> hits=new List<DrawingVisual>(); protected override Visual GetVisualChild(int index) { return visuals[index]; } protected override int VisualChildrenCount { get { return visuals.Count; } } public void addVisuals(Visual visual) { visuals.Add(visual); base.AddVisualChild(visual); base.AddLogicalChild(visual); } public void DeleteVisual(Visual visual) { visuals.Remove(visual); base.RemoveVisualChild(visual); base.RemoveLogicalChild(visual); } public DrawingVisual GetVisual(Point point) { HitTestResult hitTestResult = VisualTreeHelper.HitTest(this,point); return hitTestResult.VisualHit as DrawingVisual; } // public List<DrawingVisual> GetVisuals(Geometry geometry) { hits.Clear(); GeometryHitTestParameters parameters = new GeometryHitTestParameters(geometry); HitTestResultCallback callback = new HitTestResultCallback(this.HitTestResultCallback); VisualTreeHelper.HitTest(this, null, callback, parameters); return hits; } //HitTest回调函数 private HitTestResultBehavior HitTestResultCallback(HitTestResult result) { GeometryHitTestResult geometryHitTest = (GeometryHitTestResult)result; DrawingVisual visual = geometryHitTest.VisualHit as DrawingVisual; if (visual != null && geometryHitTest.IntersectionDetail == IntersectionDetail.FullyInside) { hits.Add(visual); } return HitTestResultBehavior.Continue; } } } 然后是在窗口中使用以下是布局VisualLayer.xmal代码(项目按右键-WPF项目-窗口) <Window x:Class="WpfApp1.VisualLayer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" xmlns:local1="clr-namespace:Drawing" mc:Ignorable="d" Title="VisualLayer" Height="450" Width="800"> <Grid> <Grid.ColumnDefinitions > <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <ToolBarTray Orientation="Vertical"> <ToolBar> <RadioButton Margin="0,3" Name="cmdSelectMove"> <StackPanel> <Image Source="pointer.png" Width="35" Height="35"></Image> <TextBlock>Select/Move</TextBlock> </StackPanel> </RadioButton> <RadioButton Margin="0,3" IsChecked="True" Name="cmdAdd"> <StackPanel> <Rectangle Width="30" Height="30" Stroke="SteelBlue" StrokeThickness="3" Fill="AliceBlue"> </Rectangle> <TextBlock>Add Square</TextBlock> </StackPanel> </RadioButton> <RadioButton Margin="0,3" Name="cmdDelete"> <StackPanel> <Path Stroke="SteelBlue" StrokeThickness="4" StrokeEndLineCap="Round" Fill="Red" HorizontalAlignment="Center"> <Path.Data> <GeometryGroup> <PathGeometry> <PathFigure StartPoint="0,0"> <LineSegment Point="18,18"></LineSegment> </PathFigure> <PathFigure StartPoint="0,18"> <LineSegment Point="18,0"></LineSegment> </PathFigure> </PathGeometry> </GeometryGroup> </Path.Data> </Path> <TextBlock> Delete Square</TextBlock> </StackPanel> </RadioButton> <RadioButton Margin="0,3" Name="cmdSelecMultipe" > <StackPanel> <Image Source="pointer.png" Width="35" Height="35"></Image> <TextBlock>Select Multiple</TextBlock> </StackPanel> </RadioButton> </ToolBar> </ToolBarTray> <Border Grid.Column="1" Margin="3" BorderBrush="SteelBlue" BorderThickness="1"> <local1:DrawingPanel x:Name="drawingSurface" Background="White" ClipToBounds="True" MouseLeftButtonDown="drawingSurface_MouseLeftButtonDown" MouseLeftButtonUp="drawingSurface_MouseLeftButtonUp" MouseMove="drawingSurface_MouseMove"> </local1:DrawingPanel> </Border> </Grid> </Window> VisualLayer.xaml.cs代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApp1 { /// <summary> /// VisualLayer.xaml 的交互逻辑 /// </summary> public partial class VisualLayer : Window { private Brush drawingBrush = Brushes.AliceBlue; private Brush selectedDrawingBrush = Brushes.LightGoldenrodYellow; private Pen drawingPen = new Pen(Brushes.SteelBlue, 3); private Size squareSize = new Size(30, 30); private DrawingVisual drawingVisual; private Vector clickOffset; private bool isDragging; private DrawingVisual selectedVisual; private bool isMultiSelecting = false; private Point selectionSquareTopLeft; private Brush selectionSquareBrush = Brushes.Transparent; private Pen selectionSquarePen = new Pen(Brushes.Black, 2); private DrawingVisual selectionSquare; public VisualLayer() { InitializeComponent(); DrawingVisual v = new DrawingVisual(); DrawingSquare(v, new Point(10,10), false); } private void DrawingSquare(DrawingVisual v,Point topLeftCorner,bool isSelected) { using(DrawingContext dc = v.RenderOpen()) { Brush brush = drawingBrush; if (isSelected) brush = selectedDrawingBrush; dc.DrawRectangle(brush, drawingPen, new Rect(topLeftCorner, squareSize)); } } private void drawingSurface_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point pointClicked = e.GetPosition(drawingSurface); if (cmdAdd.IsChecked==true) { DrawingVisual drawingVisual = new DrawingVisual(); DrawingSquare(drawingVisual, pointClicked, false); drawingSurface.addVisuals(drawingVisual); } else if (cmdDelete.IsChecked == true) { DrawingVisual drawingVisual = drawingSurface.GetVisual(pointClicked); if (drawingVisual != null) drawingSurface.DeleteVisual(drawingVisual); } else if (cmdSelectMove.IsChecked == true) { DrawingVisual visual = drawingSurface.GetVisual(pointClicked); if (visual != null) { Point topLeftCorner = new Point( visual.ContentBounds.TopLeft.X + drawingPen.Thickness / 2, visual.ContentBounds.TopLeft.Y + drawingPen.Thickness / 2); DrawingSquare(visual, topLeftCorner, true); clickOffset = topLeftCorner - pointClicked; isDragging = true; if (selectedVisual != null && selectedVisual != visual) { // The selection has changed. Clear the previous selection. ClearSelection(); } selectedVisual = visual; } } else if (cmdSelecMultipe.IsChecked == true) { selectionSquare = new DrawingVisual(); drawingSurface.addVisuals(selectionSquare); selectionSquareTopLeft = pointClicked; isMultiSelecting = true; // Make sure we get the MouseLeftButtonUp event even if the user // moves off the Canvas. Otherwise, two selection squares could be drawn at once. drawingSurface.CaptureMouse(); } } private void ClearSelection() { Point topLeftCorner = new Point( selectedVisual.ContentBounds.TopLeft.X + drawingPen.Thickness / 2, selectedVisual.ContentBounds.TopLeft.Y + drawingPen.Thickness / 2); DrawingSquare(selectedVisual, topLeftCorner, false); selectedVisual = null; } private void drawingSurface_MouseMove(object sender, MouseEventArgs e) { if (isDragging) { Point pointDragged=e.GetPosition(drawingSurface)+clickOffset; DrawingSquare(selectedVisual, pointDragged, true); } else if(isMultiSelecting) { Point pointDragged = e.GetPosition(drawingSurface); DrawSelectionSquare(selectionSquareTopLeft, pointDragged); } } private void DrawSelectionSquare(Point point1, Point point2) { selectionSquarePen.DashStyle = DashStyles.Dash; using(DrawingContext dc= selectionSquare.RenderOpen()) { dc.DrawRectangle(selectionSquareBrush, selectionSquarePen, new Rect(point1, point2)); } } private void drawingSurface_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { isDragging = false; if (isMultiSelecting) { RectangleGeometry geometry = new RectangleGeometry( new Rect(selectionSquareTopLeft, e.GetPosition(drawingSurface))); List<DrawingVisual> visualsInRegion = drawingSurface.GetVisuals(geometry); MessageBox.Show(String.Format("You selected {0} square(s).", visualsInRegion.Count)); isMultiSelecting = false; drawingSurface.DeleteVisual(selectionSquare); drawingSurface.ReleaseMouseCapture(); } } } } 效果图
选中项目按右键添加-资源文件-WPF-窗口generate_bitmap.xml文件内容为 <Window x:Class="WpfApp1.generate_bitmap" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Title="generate_bitmap" Height="450" Width="800"> <Grid x:Name="Layout_Root" Background="White"> <Grid.RowDefinitions > <!--定义行--> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition ></RowDefinition> </Grid.RowDefinitions> <Button Content="Button" Grid.Row="1" Height="81" HorizontalAlignment="Left" Margin="106,90,0,0" Name="button1" VerticalAlignment="Top" Width="193"></Button> <Button HorizontalAlignment="Center" Content="Generate_Bitmap" Width="120" Margin="5" Padding="10" Click="Button_Click" ></Button> <Image Grid.Row="1" x:Name="img" Margin="5" Width="400" Height="300" IsHitTestVisible="False"></Image> </Grid> </Window> 下面是generate_bitmap.xaml.cs文件内容 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApp1 { /// <summary> /// generate_bitmap.xaml 的交互逻辑 /// </summary> public partial class generate_bitmap : Window { public generate_bitmap() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { WriteableBitmap wb = new WriteableBitmap((int)img.Width, (int)img.Height, 96, 96, PixelFormats.Bgr32, null); Int32Rect rect = new Int32Rect(0,0,(int)img.Width, (int)img.Height); byte[] pixels = new byte[(int)img.Width * (int)img.Height * wb.Format.BitsPerPixel / 8]; Random rand = new Random(); for(int y = 0; y < wb.PixelHeight; y++) { for(int x = 0; x < wb.PixelWidth; x++) { int alpha = 0; int red = 0; int green = 0; int blue = 0; // Determine the pixel's color. if ((x % 5 == 0) || (y % 7 == 0)) { red = (int)((double)y / wb.PixelHeight * 255); green = rand.Next(100, 255); blue = (int)((double)x / wb.PixelWidth * 255); alpha = 255; } else { red = (int)((double)x / wb.PixelWidth * 255); green = rand.Next(100, 255); blue = (int)((double)y / wb.PixelHeight * 255); alpha = 50; } int pixelOffset = (x + y * wb.PixelWidth) * wb.Format.BitsPerPixel / 8; pixels[pixelOffset] = (byte)blue; pixels[pixelOffset + 1] = (byte)green; pixels[pixelOffset + 2] = (byte)red; pixels[pixelOffset + 3] = (byte)alpha; } int stride = (wb.PixelWidth * wb.Format.BitsPerPixel) / 8; wb.WritePixels(rect, pixels, stride, 0); } img.Source = wb; } } } 下面是启动duihuakua对话框的代码 private void Button_Click(object sender, RoutedEventArgs e) { Type type = this.GetType(); Assembly assembly = type.Assembly; //根据window类的名称获取window对象 Window window=(Window)assembly.CreateInstance("WpfApp1.generate_bitmap"); window.Show(); } 运行xia效果
<Button Content="Button" HorizontalAlignment="Left" Margin="31,234,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="-0.213,0.579"> <Button.Effect> <BlurEffect Radius="2"/> </Button.Effect> </Button> <TextBlock FontSize="20" Margin="5"> <TextBlock.Effect> <DropShadowEffect></DropShadowEffect> </TextBlock.Effect> <TextBlock.Text>阴影效果</TextBlock.Text> </TextBlock> <TextBlock FontSize="20" Margin="127,10,-117,0"> <TextBlock.Effect> <DropShadowEffect Color="SteelBlue"></DropShadowEffect> </TextBlock.Effect> <TextBlock.Text>阴影效果</TextBlock.Text> </TextBlock> <TextBlock FontSize="20" Margin="251,10,-241,0" Foreground="White" > <TextBlock.Effect> <DropShadowEffect BlurRadius="15"></DropShadowEffect> </TextBlock.Effect> <TextBlock.Text>阴影效果</TextBlock.Text> </TextBlock> <TextBlock FontSize="20" Margin="251,10,-241,0" Foreground="Magenta" > <TextBlock.Effect> <DropShadowEffect ShadowDepth="0"></DropShadowEffect> </TextBlock.Effect> <TextBlock.Text>阴影效果</TextBlock.Text> </TextBlock> <TextBlock FontSize="20" Margin="5,93,5,-83" Foreground="Magenta" > <TextBlock.Effect> <DropShadowEffect ShadowDepth="25"></DropShadowEffect> </TextBlock.Effect> <TextBlock.Text>阴影效果</TextBlock.Text> </TextBlock> 运行效果图
首先在App.xaml文件当中添加样式和模板 <!--编辑器通用主题样式--> <Style x:Key="nu_editor_style"> <Setter Property="Control.Padding" Value="12"></Setter> <Setter Property="Control.Background" Value="#FFC1EDF7"></Setter> <Setter Property="Control.BorderBrush" Value="#FFA0A2A4"></Setter> <Setter Property="Control.BorderThickness" Value="8"></Setter> <Setter Property="Control.ClipToBounds" Value="True"></Setter> </Style> <!--Label 控件模板--> <ControlTemplate x:Key="nu_editor_label_template" TargetType="Label" > <lib:CustomDrawnDecorator BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}"> <ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Content="{TemplateBinding ContentControl.Content}" RecognizesAccessKey="True" /> </lib:CustomDrawnDecorator> </ControlTemplate> 下面是Decorator的代码 using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApp1 { public class CustomDrawnDecorator : Decorator { double arrowLen = 30d; static Thickness defaultBorderThickness = new Thickness(4d); public static DependencyProperty BorderBrushProperty = DependencyProperty.Register("BorderBrush", typeof(Brush), typeof(CustomDrawnDecorator), new PropertyMetadata(Brushes.Gray)); public static DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(CustomDrawnDecorator), new PropertyMetadata(defaultBorderThickness)); public static DependencyProperty BackgroundProperty= DependencyProperty.Register("Background", typeof(Brush), typeof(CustomDrawnDecorator) , new FrameworkPropertyMetadata(Brushes.RosyBrown)); static CustomDrawnDecorator() { } public Brush Background { get { return (Brush)GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } public Brush BorderBrush { get { return (Brush)GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } } public Thickness BorderThickness { get { return (Thickness)GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } } protected override void OnRender(DrawingContext dc) { base.OnRender(dc); Rect bounds = new Rect(0, 0, base.ActualWidth, base.ActualHeight); Pen p = new Pen(BorderBrush,getBorderThickness()); //填充背景 dc.DrawRectangle(Background, null, bounds); //左长线 dc.DrawLine(p, new Point(getBorderThickness() / 2, 0), new Point(getBorderThickness() / 2, ActualHeight)); //右长线 dc.DrawLine(p, new Point(ActualWidth - getBorderThickness() / 2, 0), new Point(ActualWidth - getBorderThickness() / 2, ActualHeight)); //左上短线 dc.DrawLine(p, new Point(0, getBorderThickness() / 2), new Point(arrowLen, getBorderThickness() / 2)); //右上短线 dc.DrawLine(p, new Point(ActualWidth - arrowLen, getBorderThickness() / 2), new Point(ActualWidth, getBorderThickness() / 2)); //左下短线 dc.DrawLine(p, new Point(0, ActualHeight - getBorderThickness() / 2), new Point(arrowLen, ActualHeight - getBorderThickness() / 2)); //右下短线 dc.DrawLine(p, new Point(ActualWidth - arrowLen, ActualHeight - getBorderThickness() / 2), new Point(ActualWidth, ActualHeight - getBorderThickness() / 2)); //dc.DrawRectangle(Background, p, bounds); //dc.DrawLine(new Pen(Background, getBorderThickness() / 2), new Point(arrowLen, getBorderThickness() / 4), new //Point(ActualWidth - arrowLen, getBorderThickness() / 4)); //dc.DrawLine(new Pen(Background, getBorderThickness() / 2), new Point(arrowLen, ActualHeight - getBorderThickness() / 4), //new Point(ActualWidth - arrowLen, ActualHeight - getBorderThickness() / 4)); } public double DpiScaleX { get; } private double getBorderThickness() { return BorderThickness.Right != 0 ? BorderThickness.Right : defaultBorderThickness.Right; } } } 然后在 mainWindow.xaml文件当中tianji添加Label控件 <Label Width="300" Height="100" Style="{StaticResource nu_editor_style}" Template="{StaticResource nu_editor_label_template}" Content="我是Label控件" FontSize="17" HorizontalAlignment="Left" Margin="180,185,0,0" VerticalAlignment="Top" /> 运行效果
首先在app.xaml文件的下面添加以下样式 <!--编辑器通用主题样式--> <Style x:Key="nu_editor_style"> <Setter Property="Control.Padding" Value="12"></Setter> <Setter Property="Control.Background" Value="#FFC1EDF7"></Setter> <Setter Property="Control.BorderBrush" Value="#FFA0A2A4"></Setter> <Setter Property="Control.BorderThickness" Value="8"></Setter> <Setter Property="Control.ClipToBounds" Value="True"></Setter> </Style> <ControlTemplate x:Key="nu_editor_template" TargetType="{x:Type TextBoxBase}" > <lib:CustomDrawnDecorator BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}"> <ScrollViewer Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="PART_ContentHost" /> </lib:CustomDrawnDecorator> </ControlTemplate> 在mainWindow.xaml文件中添加TextBox控件 <TextBox Width="300" Height="100" Style="{StaticResource nu_editor_style}" Template="{StaticResource nu_editor_template}" HorizontalAlignment="Left" Margin="180,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" > sdfsd </TextBox> 还有下面是Decorator的代码 using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApp1 { public class CustomDrawnDecorator : Decorator { double arrowLen = 30d; static Thickness defaultBorderThickness = new Thickness(4d); public static DependencyProperty BorderBrushProperty = DependencyProperty.Register("BorderBrush", typeof(Brush), typeof(CustomDrawnDecorator), new PropertyMetadata(Brushes.Gray)); public static DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(CustomDrawnDecorator), new PropertyMetadata(defaultBorderThickness)); public static DependencyProperty BackgroundProperty= DependencyProperty.Register("Background", typeof(Brush), typeof(CustomDrawnDecorator) , new FrameworkPropertyMetadata(Brushes.RosyBrown)); static CustomDrawnDecorator() { } public Brush Background { get { return (Brush)GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } public Brush BorderBrush { get { return (Brush)GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } } public Thickness BorderThickness { get { return (Thickness)GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } } protected override void OnRender(DrawingContext dc) { base.OnRender(dc); Rect bounds = new Rect(0, 0, base.ActualWidth, base.ActualHeight); Pen p = new Pen(BorderBrush,getBorderThickness()); //填充背景 dc.DrawRectangle(Background, null, bounds); //左长线 dc.DrawLine(p, new Point(getBorderThickness() / 2, 0), new Point(getBorderThickness() / 2, ActualHeight)); //右长线 dc.DrawLine(p, new Point(ActualWidth - getBorderThickness() / 2, 0), new Point(ActualWidth - getBorderThickness() / 2, ActualHeight)); //左上短线 dc.DrawLine(p, new Point(0, getBorderThickness() / 2), new Point(arrowLen, getBorderThickness() / 2)); //右上短线 dc.DrawLine(p, new Point(ActualWidth - arrowLen, getBorderThickness() / 2), new Point(ActualWidth, getBorderThickness() / 2)); //左下短线 dc.DrawLine(p, new Point(0, ActualHeight - getBorderThickness() / 2), new Point(arrowLen, ActualHeight - getBorderThickness() / 2)); //右下短线 dc.DrawLine(p, new Point(ActualWidth - arrowLen, ActualHeight - getBorderThickness() / 2), new Point(ActualWidth, ActualHeight - getBorderThickness() / 2)); //dc.DrawRectangle(Background, p, bounds); //dc.DrawLine(new Pen(Background, getBorderThickness() / 2), new Point(arrowLen, getBorderThickness() / 4), new //Point(ActualWidth - arrowLen, getBorderThickness() / 4)); //dc.DrawLine(new Pen(Background, getBorderThickness() / 2), new Point(arrowLen, ActualHeight - getBorderThickness() / 4), //new Point(ActualWidth - arrowLen, ActualHeight - getBorderThickness() / 4)); } private double getBorderThickness() { return BorderThickness.Right != 0 ? BorderThickness.Right : defaultBorderThickness.Right; } } } 运行结果
ssh 首次登陆服务器时会弹出服务器公钥确认提示如果要禁用该提示功能,可以在ssh的配置文件中进行配置,默认是ask,默认情况下可能没有这个属性,也可以自己添加进去。StrictHostKeyChecking ask添加之后我们先从ssh信任服务器列表中删除上面的服务器的ip,再做测试。删除 ~/.ssh/known_hosts文件的内容,在连接的时候发现已经提示你输入yes/no了也可以通过命令行模式实现 ssh root@120.23.46.246 -o stricthostkeychecking=no # 首次登陆免输yes登录 ssh root@120.26.246.30 "echo hello 我要登录远程服务器并且执行此语句,执行完就退出远程服务器" ssh配置文件 sudo cat /etc/ssh/sshd_config ssh信任主机秘钥目录 /.ssh/known_hosts # 当前用户家目录的.ssh目录下 登录远程主机查看当前ssh服务在哪个端口运行 netstat -lntup|grep ssh ssh实现免密码登录先用rsa算法生成公钥和秘钥再把公钥拷贝到目标服务器查看目标服务器生成的文件现在就可以免密码登录了 ssh 优化 #修改端口,不使用默认端口 #改监听,只监听特定的IP #no root ,不允许以root用户的身份登录 #修改当前环境下允许登录的用户 Match User anoncvs #UseDNS no 加快响应速度因为在内网环境下
普通用户切换到root用户sudo su切换到普通用户exit
chmod是权限管理命令change the permissions mode of a file的缩写.给文件添加可执行权限u代表所有者,x代表执行权限。 + 表示增加权限。chmod u+x file.sh 就表示对当前目录下的file.sh文件的所有者增加可执行权限。linux 执行脚本 执行当前目录下的test.sh脚本 ./test.sh 也可以 sh test.sh
ps 命令 progress status 进程状态 命令 具体使用方法grep 命令 Global Regular Expression Printlinux 管道 比如说我先显示所有进程ps -ef图片没有截完整的图在以下进程中筛选出Java进程ps -ef|grep java可以看出linux 管道符号 |数据流会在管道里面作为下一个命令的输入流流动。关于grep 详细用法awk命令AWK是一种处理文本文件的语言,是一个强大的文本分析工具,也是三位创始人的名字的首字母。 awk是把文本一行一行的处理awk '{print $2}'含义是把管道中的数据每一行按空格分隔提取,然后把第二项输出假如test.txt文件内容如下 $()放的是命令,相当于 ''
有了mac地址为什么还用ip地址ip地址是属于逻辑地址,mac地址是属于物理地址,ip地址是有结构特性,有层次关系,mac地址却没有,ip地址有结构特性是为了路由方便,而且mac地址是不能修改的,ip地址是可以改的,有了ip地址设备从某个网络移到另外一个网络只是修改ip地址就可以了,不用修改其mac地址
网络层次结构第一层 链路层网卡以及网卡驱动,只负责数据的传输,无连接的,也不做差错检验,只负责传送到指定的网卡地址。第二层 网络层 ip协议属于网络层,负责数据传送到指定的ip地址,但不做差错检验,arp协议也属于网络层,因为链路层是无法识别ip的,它对ip是一无所知的第三层 传输层 tcp协议属于传输层,负责数据的正确送达,进行差错检验等。第四层 应用层 http协议属于应用层dns协议也属于应用层ftp协议也属于应用层smtp邮件传输协议也属于应用层
对称与非对称秘钥混合使用保证数据安全甲想给乙发送加密数据,首先甲给乙发送消息说明它要使用混合加密方式发送数据,此时乙会生成一个公钥和一个私钥并把公钥发给甲,甲使用乙发过来的公钥对对称秘钥进行加密发过去,再把用对称秘钥加密的数据发送给乙,乙使用自己的私钥对甲发过来的经过加密的对称秘钥进行解密,然后通过对称秘钥对原始数据进行解密。
异常处理
造成这种情况的原因是将Tomcat放到/opt或其它系统目录下了,解决方案是 打开终端,进入到Tomcat的上一级目录里面,如Tocat目录在/opt/Tomcat 在终端输入命令 sudo chmod -R 777 /opt/Tomcat,那么Tomcat文件夹和它下面的所有子文件夹的属性都变成了777(读/写/执行权限) 另外一种方法是把Tomcat解压到/Home下面,总之将它的权限变成读写执行就可以了。
for 命令每次 for 命令遍历值列表,它都会将列表中的下个值赋给 $test 变量。 $test 变量可以像 for命令语句中的其他脚本变量一样使用。在最后一次迭代后, $test 变量的值会在shell脚本的剩余部分一直保持有效。它会一直保持最后一次迭代的值(除非你修改了它) for test in Alabama Alaska Arizona Arkansas California Colorado do echo "The next state is $test" done echo "The last state we visited was $test" test=Connecticut echo "Wait, now we're visiting $test" for 命令用空格来划分列表中的每个值。如果在单独的数据值中有空格,就必须用双引号将这些值圈起来 for test in Nevada "New Hampshire" "New Mexico" "New York" do echo "Now going to $test" done 从变量读取列表 list="Alabama Alaska Arizona Arkansas Colorado" # 拼接字符串 list=$list" Connecticut" for state in $list do echo "Have you ever visited $state?" done 从命令读取值 # 文件读取 file="states" for state in $(cat $file) do echo "Visit beautiful $state" done 这个例子在命令替换中使用了 cat 命令来输出文件states的内容。你会注意到states文件中每一行有一个州,而不是通过空格分隔的。 for 命令仍然以每次一行的方式遍历了 cat 命令的输出,假定每个州都是在单独的一行上。但这并没有解决数据中有空格的问题。如果你列出了一个名字中有空格的州, for 命令仍然会将每个单词当作单独的值更改字段分隔符造成这个问题的原因是特殊的环境变量 IFS ,叫作内部字段分隔符(internal field separator)。IFS 环境变量定义了bash shell用作字段分隔符的一系列字符。默认情况下,bash shell会将下列字符当作字段分隔符: 空格 制表符 换行符如果bash shell在数据中看到了这些字符中的任意一个,它就会假定这表明了列表中一个新数据字段的开始。在处理可能含有空格的数据(比如文件名)时,这会非常麻烦,就像你在上一个脚本示例中看到的。要解决这个问题,可以在shell脚本中临时更改 IFS 环境变量的值来限制被bash shell当作字段分隔符的字符。例如,如果你想修改 IFS 的值,使其只能识别换行符,那就必须这么做:IFS=$'n'将这个语句加入到脚本中,告诉bash shell在数据值中忽略空格和制表符 file="states" IFS=$'\n' for state in $(cat $file) do echo "Visit beautiful $state" done 在处理代码量较大的脚本时,可能在一个地方需要修改 IFS 的值,然后忽略这次修改,在脚本的其他地方继续沿用 IFS 的默认值。一个可参考的安全实践是在改变 IFS 之前保存原来的 IFS 值,之后再恢复它。这种技术可以这样实现:IFS.OLD=$IFSIFS=$'n'<在代码中使用新的IFS值>IFS=$IFS.OLD这就保证了在脚本的后续操作中使用的是 IFS 的默认值用通配符读取目录 for file in /home/* do if [ -d "$file" ] then echo "$file is a directory" elif [ -f "$file" ] then echo "$file is a file" fi done C 语言的 for 命令 for (( i=1; i <= 10; i++ )) do echo "The next number is $i" done 使用多个变量 for (( a=1, b=10; a <= 10; a++, b-- )) do echo "$a - $b" done while 命令
简单if-then #!/bin/bash if pwd then echo "It worked" fi 这个脚本在 if 行采用了 pwd 命令。如果命令成功结束, echo 语句就会显示该文本字符串。在命令行运行该脚本时,会得到如下结果shell执行了 if 行中的 pwd 命令。由于退出状态码是 0 ,它就又执行了 then 部分的 echo 语句。下面是另外一个例子 if IamNotaCommand then echo "It worked" fi echo "We are outside the if statement" if-then-else 语句 testuser=NoSuchUser # if grep $testuser /etc/passwd then echo "The bash files for user $testuser are:" ls -a /home/$testuser/.b* echo else echo "The user $testuser does not exist on this system." echo fi 嵌套 if testuser=NoSuchUser # if grep $testuser /etc/passwd then echo "The user $testuser exists on this system." else echo "The user $testuser does not exist on this system." if ls -d /home/$testuser/ then echo "However, $testuser has a directory." fi fi testuser=NoSuchUser # if grep $testuser /etc/passwd then echo "The user $testuser exists on this system." # elif ls -d /home/$testuser then echo "The user $testuser does not exist on this system." echo "However, $testuser has a directory." # else echo "The user $testuser does not exist on this system." echo "And, $testuser does not have a directory." fi test 命令到目前为止,在 if 语句中看到的都是普通shell命令。你可能想问, if-then 语句是否能测试命令退出状态码之外的条件。答案是不能。但在bash shell中有个好用的工具可以帮你通过 if-then 语句测试其他条件。test 命令提供了在 if-then 语句中测试不同条件的途径。如果 test 命令中列出的条件成立,test 命令就会退出并返回退出状态码 0 。这样 if-then 语句就与其他编程语言中的 if-then 语句以类似的方式工作了。如果条件不成立, test 命令就会退出并返回非零的退出状态码,这使得if-then 语句不会再被执行 if test then echo "No expression returns a True" else echo "No expression returns a False" fi 变量 my_variable 中包含有内容( Full ),因此当 test 命令测试条件时,返回的退出状态为 0 。这使得 then 语句块中的语句得以执行。如你所料,如果该变量中没有包含内容,就会出现相反的情况 my_variable="Full" # if test $my_variable then echo "The $my_variable expression returns a True" # else echo "The $my_variable expression returns a False" fi bash shell提供了另一种条件测试方法,无需在 if-then 语句中声明 test 命令if [ condition ]thencommandsfi方括号定义了测试条件。注意,第一个方括号之后和第二个方括号之前必须加上一个空格,否则就会报错。数值比较 value1=10 value2=11 # if [ $value1 -gt 5 ] then echo "The test value" fi # if [ $value1 -eq $value2 ] then echo "The values are" else echo "The values are" fi bash shell只能处理整数,单纯的输出浮点型变量的值可以但不能用作测试条件 字符串比较 testuser=baduser # if [ $USER != $testuser ] then echo "This is not $testuser" else echo "Welcome $testuser" fi 字符串顺序要测试一个字符串是否比另一个字符串大就是麻烦的开始。当要开始使用测试条件的大于或小于功能时,就会出现两个经常困扰shell程序员的问题: 大于号和小于号必须转义,否则shell会把它们当作重定向符号,把字符串值当作文件名; 大于和小于顺序和 sort 命令所采用的不同。在编写脚本时,第一条可能会导致一个不易察觉的严重问题。下面的例子展示了shell脚本编程初学者时常碰到的问题字符串大小 val1=testing val2='' # if [ -n $val1 ] then echo "The string '$val1'" else echo "The string '$val1'" fi # if [ -z $val2 ] then echo "The string '$val2'" else echo "The string '$val2'" fi # if [ -z $val3 ] then echo "The string '$val3'" else echo "The string '$val3'" fi 这个例子创建了两个字符串变量。 val1 变量包含了一个字符串, val2 变量包含的是一个空字符串。后续的比较如下:if [ -n $val1 ]判断 val1 变量是否长度非0,而它的长度正好非0,所以 then 部分被执行了。if [ -z $var2 ]判断 val2 变量是否长度为0,而它正好长度为0,所以 then 部分被执行了。12if [ -z $val3 ]判断 val3 变量是否长度为0。这个变量并未在shell脚本中定义过,所以它的字符串长度仍然为0,尽管它未被定义过 文件比较 检查目录 jump_directory=/home/arthur # if [ -d $jump_directory ] then echo "The $jump_directory directory exists" cd $jump_directory ls else echo "The $jump_directory directory does not exist" fi -e 比较允许你的脚本代码在使用文件或目录前先检查它们是否存在 location=$HOME file_name="sentinel" # if [ -e $location ] then #Directory does exist echo "OK on the $location directory." echo "Now checking on the file, $file_name." # if [ -e $location/$file_name ] then #File does exist echo "OK on the filename" echo "Updating Current Date..." date >> $location/$file_name # else #File does not exist echo "File does not exist" echo "Nothing to update" fi # else #Directory does not exist echo "The $location directory does not exist." echo "Nothing to update" fi 检查文件-e 比较可用于文件和目录。要确定指定对象为文件,必须用 -f 比较 item_name=$HOME echo echo "The item being checked: $item_name" echo # if [ -e $item_name ] then #Item does exist echo "The item, $item_name, does exist." echo "But is it a file?" echo # if [ -f $item_name ] then #Item is a file echo "Yes, $item_name is a file." # else #Item is not a file echo "No, $item_name is not a file." fi # else #Item does not exist echo "The item, $item_name, does not exist." echo "Nothing to update" fi 检查是否可读 pwfile=/etc/shadow # # first, test if the file exists, and is a file if [ -f $pwfile ] then # now test if you can read it if [ -r $pwfile ] then tail $pwfile else echo "Sorry, I am unable to read the $pwfile file" fi else echo "Sorry, the file $file does not exist" fi 检查空文件 file_name=$HOME/sentinel # if [ -f $file_name ] then if [ -s $file_name ] then echo "The $file_name file exists and has data in it." echo "Will not remove this file." # else echo "The $file_name file exists, but is empty." echo "Deleting empty file..." rm $file_name fi else echo "File, $file_name, does not exist." fi 检查是否可写 item_name=$HOME/nurmemet echo echo "The item being checked: $item_name" echo if [ -w $item_name ]; then echo "yes" else echo "no" fi 检查文件是否可以执行 item_name=test6.sh echo echo "The item being checked: $item_name" echo if [ -x test6.sh ] then echo "yes" else echo "no" fi 检查所属关系 else echo "Sorry, you are not the owner of the /etc/passwd file" fi 检查默认属组关系 if [ -G $HOME/testing ] then echo "You are in the same group as the file" else echo "The file is not owned by your group" fi 检查文件日期 复合条件测试 [ condition1 ] && [ condition2 ] [ condition1 ] || [ condition2 ] if [ -d $HOME ] && [ -w $HOME/testing ] then echo "The file exists and you can write to it" else echo "I cannot write to the file" fi if-then 的高级特性bash shell提供了两项可在 if-then 语句中使用的高级特性: 用于数学表达式的双括号 用于高级字符串处理功能的双方括号后面几节将会详细描述每一种特性双括号命令允许你在比较过程中使用高级数学表达式。 test 命令只能在比较中使用简单的算术操作。双括号命令提供了更多的数学符号,这些符号对于用过其他编程语言的程序员而言并不陌生 val1=10 # if (( $val1 ** 2 > 90 )) then (( val2 = $val1 ** 2 )) echo "The square of $val1 is $val2" fi 使用双方括号双方括号里的 expression 使用了 test 命令中采用的标准字符串比较。但它提供了 test 命令未提供的另一个特性——模式匹配(pattern matching) if [[ $USER == r* ]] then echo "Hello $USER" else echo "Sorry, I do not know you" fi case 命令case 命令会将指定的变量与不同模式进行比较。如果变量和模式是匹配的,那么shell会执行为该模式指定的命令。可以通过竖线操作符在一行中分隔出多个模式模式。星号会捕获所有与已知模式不匹配的值 case $USER in # 用户名如果是rich 或者 barbara rich | barbara) echo "Welcome, $USER" echo "Please enjoy your visit";; # 如果用户名为testing testing) echo "Special testing account";; # 如果用户名为jessica jessica) echo "Do not forget to log off when you're done";; # 如果上面的case都不匹配 *) echo "Sorry, you are not allowed here";; esac
在创建shell脚本文件时,必须在文件的第一行指定要使用的shell。其格式为:#!/bin/bash在通常的shell脚本中,井号( # )用作注释行。shell并不会处理shell脚本中的注释行。然而,shell脚本文件的第一行是个例外, # 后面的惊叹号会告诉shell用哪个shell来运行脚本(是的,你可以使用bash shell,同时还可以使用另一个shell来运行你的脚本)。在指定了shell之后,就可以在文件的每一行中输入命令,然后加一个回车符。之前提到过,注释可用 # 添加。例如: # 同一个行输出内容 加参数-n echo -n "当前时间: " date # 命令替换 !/bin/bash # This script displays the date and who's logged on # 注意下面不是单引号,而是键盘上esc下面那个键,date的输出内容赋值给testing testing=`date` # 也可以这样写 testing=$(date) echo $testing who # 重定向输入和输出 # 当前目录创建文件test6并内容输出到文件中 date > test6 # 输入重定向 # wc 命令可以对对数据中的文本进行计数。默认情况下,它会输出3个值: # 文本的行数 # 文本的词数 # 文本的字节数 wc < test6 # 管道通信 # ps -ef 的输出作为后一个命令grep 的输入 # grep 返回 包含bash字段的一行记录 ps -ef|grep 'bash' 有几种解决方案能够克服bash中数学运算的整数限制。最常见的方案是用内建的bash计算器,叫作 bc 。bc 的基本用法bash计算器实际上是一种编程语言,它允许在命令行中输入浮点表达式,然后解释并计算该表达式,最后返回结果 # bash计算器 # 输入quit退出bash计算器 # 浮点运算是由内建变量 scale 控制的。必须将这个值设置为你希望在计算结果中保留的小数 # 位数,否则无法得到期望的结果 # 除了普通数字,bash计算器还能支持变量 # 变量一旦被定义,你就可以在整个bash计算器会话中使用该变量了。 print 语句允许你打印 # 变量和数字 # 在脚本中使用 bc # 也可以用shell脚本中定义好的变量 # 一旦变量被赋值,那个变量也可以用于其他运算 这个方法适用于较短的运算,但有时你会涉及更多的数字。如果需要进行大量运算,在一个命令行中列出多个表达式就会有点麻烦。有一个方法可以解决这个问题。 bc 命令能识别输入重定向,允许你将一个文件重定向到 bc命令来处理。但这同样会叫人头疼,因为你还得将表达式存放到文件中。最好的办法是使用内联输入重定向,它允许你直接在命令行中重定向数据。在shell脚本中,你可以将输出赋给一个变量 Linux提供了一个专门的变量 $? 来保存上个已执行命令的退出状态码。对于需要进行检查的命令,必须在其运行完毕后立刻查看或使用 $? 变量。它的值会变成由shell所执行的最后一条命令的退出状态码按照惯例,一个成功结束的命令的退出状态码是 0 。如果一个命令结束时有错误,退出状态11.8 退出脚本229码就是一个正数值默认情况下,shell脚本会以脚本中的最后一个命令的退出状态码退出你可以改变这种默认行为,返回自己的退出状态码。 exit 命令允许你在脚本结束时指定一个退出状态码 你要注意这个功能,因为退出状态码最大只能是 255退出状态码被缩减到了0~255的区间。shell通过模运算得到这个结果。一个值的模就是被除后的余数。最终的结果是指定的数值除以256后得到的余数。在这个例子中,指定的值是 300 (返回值),余数是44,因此这个余数就成了最后的状态退出码
vim编辑器在内存缓冲区中处理数据,如在启动vim时未指定文件名,或者这个文件不存在,vim会开辟一段新的缓冲区域来编辑。如果你在命令行下指定了一个已有文件的名字,vim会将文件的整个内容都读到一块缓冲区域来准备编辑 # 当文件不存在时,会新建一个文件并把缓冲区的内容保存到新创建的文件中 vim mytest # 下面会提示New File # vim编辑器有两种模式,插入模式和普通模式 # 普通模式键入i就可以切换到插入模式 # 插入模式下键入esc键可以退回普通模式 # 如果想放弃对对缓冲区所做的更改,不写入到文件 # 在普通模式下键入:q! # 如果对缓冲区没做任何更改并且想退出 # 在普通模式下键入 :q # 如果要对缓冲区所做的更改保存到文件当中 # 在普通模式下键入 :wq # vim查看文件 # 可以用上下键滚动 # 也可以用pgdn 和pgup翻页查看 # 可以用G(大写的G)滚动到缓冲区最后一页(编辑器右下方显示Bot,表示最后一页) # 可以用 gg(小写) 缓冲区第一页(编辑器右下方会提示Top,表示第一页) # 为了快捷操作vim在普通模式下也提供了以下简单命令方便快速操作缓冲区 # 在普通模式下键入 dd删除当前行 # 键入x 删除当前光标所在位置的字符 # 键入dw 删除当前光标所在位置的单词 # 键入 u 撤销前一编辑命令 # 键入 d$ 删除当前光标所在位置至行尾的内容 # vim还有一个模式叫可是模式 # 在普通模式下键入v键入可视模式 # 此时按可以上下键来选中文本 # 选中之后键入y复制文本,此时复制文本的同时vim会退回到普通模式,移动光标到你想粘贴的位置按下p就可粘贴 # vim 会把复制的文本放到另外一个寄存器当中,当你粘贴文本时会从寄存器中读取 # 普通模式下键入/ 光标会移动到消息行 键入要查找的文本按下回车 # 如果未找到 # 此时可以再次按下/ 重新输入 # 可以按下n(next)在多个查找结果中跳转 # 文本替换 # 进入命令模式 # :%s/old/new/g :替换整个文件中的所有 old 。 # %s/old/new/gc :替换整个文件中的所有 old ,但在每次出现时提示。
搜狗输入法官方文档
Spring Cloud Feign 官方文档Github实例
Spring Cloud Task 官方文档 Github实例
Spring Cloud Netflix 官方文档
Spring Cloud and OAuth2 官方文档 Github实例
文件权限 # 添加新用户,默认useradd命令不创建用户home目录 useradd testuser # 为账号添加密码 passwd testuser # 要创建home目录加参数 -m useradd -m testuser # centos 7 默认不加参数 -m 也会创建用户目录 useradd testuser3 -m # 默认用户Home目录在root账号home/目录下分配 # 也可以命令行中指定用户home目录 如 useradd -d useradd test6 -d /usertest6homedir # 如果默认useradd 创建用户目录可以加参数 -M 不创建用户目录 useradd usertest7 -M # 创建用户时创建设置默认密码 useradd usertest8 -p Myhmiiii # userdel 默认不会删除用户目录 userdel testuser3 # 要同时删除用户目录 可以加参数 -r userdel usertest4 -r # 修改用户备注信息 以下修改用户名为usertest8用户的 备注信息 usermod -c '我的备注信息' usertest8 #修改用户登录名 注意用户目录名不变 usermod -l 'newusertest8' usertest8 # ls -l 命令查看 查看目录或这文件的详细属性 ll # 第一个字母 - 表示文件 d表示目录 # l代表链接 # c代表字符型设备 # b代表块儿设备 # n代表网络设备 # 之后三字符的编码,表示文件权限,r 代表可读,w代表可写的,x代表可执行的,若没有某种权限,在该权限位会出现单破折线 # touch 命令用分配给我的用户账户的默认权限创建文件 touch testfile # 修改文件权限,八进制文件权限会自动应用到指定的文件上 chmod 760 tesfile # chown命令可以修改文件的属主 # 可以用用户ID或者登录名来改变文件的新属主如 # chown nurmemet testfile # linux共享文件是通过用户组来实现的 # CentOs查看系统中已安装的软件 yum list installed # 上面的查看方法因为安装的文件软件比较多输出结构会一闪而过,查看不方便 # 可以用下面的命令输出到文件,用less或者more命令查看输出结果更方便 yum list installed > newtestfile # 这是当前目录会生成一个文件newtestfile # 用yum查看某一个已经安装的软件的详细信息 yum list wget.x86_64 # 手动安装rpm包 yum localinstall package_name.rpm # 检查是否有更新 yum list updates # 批量更新所有的 软件 yum update # 更新完之后再次查看 yum list updates # 卸载软件 yum remove package_name # remove 命令只删除软件不会删除其配置文件,要卸载软件并删除其所有文件可以用erase命令 yum erase package_name # 处理损坏的依赖包关系可以用以下命令解决 yum clean all # 然后用update 命令再次更新 yum update # 如果还是不行,可以先查看软件包依赖关系 yum deplist package_name # 如果仍未能解决可以用以下命令 yum update --skip-broken 查看你目前正使用那些仓库获取软件可以用以下命令 yum repolist # 源码安装sysstat,首先下载 wget http://sebastien.godard.pagesperso-orange.fr/sysstat-11.6.0.tar.gz # 解压 tar -xzvf sysstat-11.6.0.tar.gz # 进入解压目录 cd sysstat-11.6.0 # 查看 README.md文件阅读安装说明,按上下键滚动,最后按q键退出 less README.md # 安装开始,首先用 sh configure命令配置 sh configure # 用make命令编译 make # 用 make install 命令安装 make install # mpstat命令查看运行结果 mpstat
Spring 官方文档 注册中心model buildscript { ext { springBootVersion = '1.5.6.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } ext { springCloudVersion = 'Dalston.SR3' } dependencies { compile('org.springframework.cloud:spring-cloud-starter-eureka-server') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } package registerserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; /** * 注册中心 */ @EnableEurekaServer @SpringBootApplication public class RegisterCenterApplication { public static void main(String[] args) { SpringApplication.run(RegisterCenterApplication.class, args); } } application.yml server: port: 8761 eureka: instance: hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 项目目录结构 配置中心model buildscript { ext { springBootVersion = '1.5.6.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } ext { springCloudVersion = 'Dalston.SR3' } dependencies { compile('org.springframework.cloud:spring-cloud-config-server') compile('org.springframework.cloud:spring-cloud-starter-eureka') compile('org.springframework.boot:spring-boot-starter-web') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } package com.cn.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableConfigServer @EnableEurekaClient public class ConfigeServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigeServerApplication.class, args); } } application.yml # 自定义变量 register-center-url: http://localhost:8761/eureka/ # 注册中心地址 eureka.client.serviceUrl.defaultZone: ${register-center-url} # 配置中心存储配置文件的方式 spring.profiles.active: native # 应用名称 spring.application.name: config-server # 端口 server.port: 8888 #本地配置文件存放路径 (${spring.profiles.active} 为native 是才有效) spring.cloud.config.server.native.searchLocations: classpath:/config zuul.ignore-local-service= 项目目录结构 zuul网管 model buildscript { ext { springBootVersion = '1.5.7.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' group = 'com.cn.pppcar' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } ext { springCloudVersion = 'Dalston.SR3' } dependencies { compile('org.springframework.cloud:spring-cloud-starter-zuul') compile('org.springframework.cloud:spring-cloud-starter-eureka') compile('org.springframework.cloud:spring-cloud-starter-config') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } package com.cn.pppcar; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableZuulProxy @EnableEurekaClient public class ZuulGatewayApplication { public static void main(String[] args) { SpringApplication.run(ZuulGatewayApplication.class, args); } @Bean public AccessFilter accessFilter() { return new AccessFilter(); } } package com.cn.pppcar; import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.context.RequestContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletRequest; /** * Created by nurmemet on 9/19/2017. */ public class AccessFilter extends ZuulFilter { private static Logger log = LoggerFactory.getLogger(AccessFilter.class); @Override public String filterType() { return "pre"; } @Override public int filterOrder() { return -10; } @Override public boolean shouldFilter() { return true; } @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); HttpServletRequest request = ctx.getRequest(); log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); return null; } } bootstrap.properties # Flag to say that remote configuration is enabled. Default true; spring.cloud.config.enabled=true spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.service-id=config-server # Name of application used to fetch remote properties. # 远程配置文件名称 如 service0-{profile}.properties # @Value("${spring.application.name:application}") # spring.cloud.config.name=zuul-gateway # The URI of the remote server (default http://localhost:8888). 配置服务器 spring.cloud.config.uri=http://localhost:8888 # 要启用的环境(test,pro,dev 之类的) 配置服务器得有 ${spring.cloud.config.name}-{spring.cloud.config.profile}.properties文件 spring.cloud.config.profile=test #spring.cloud.config.label=config-label-test 在配置中心的配置 zuul: ignoredServices: '*' routes: service0: path: /hello/** stripPrefix: false # serviceId: service0 #也可以用serviceId url: http://localhost:8891/ sensitive-headers: Cookie,Set-Cookie eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ spring: application: name: api-gateway server: port: 8002 项目目录结构 service0 model buildscript { ext { springBootVersion = '1.5.6.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } ext { springCloudVersion = 'Dalston.SR3' } dependencies { compile('org.springframework.cloud:spring-cloud-starter-eureka') compile('org.springframework.cloud:spring-cloud-starter-config') testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } package com.cn.nur; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class Service0Application { public static void main(String[] args) { SpringApplication.run(Service0Application.class, args); } } package com.cn.nur; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by nurmemet on 9/12/2017. */ @RestController @RequestMapping("hello") public class MyController { @Value("${message}") String msg; @RequestMapping("hello") public String hello(){ return "hello "+ msg; } } bootstrap.yml # Flag to say that remote configuration is enabled. Default true; spring.cloud.config.enabled=true spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.service-id=config-server # Name of application used to fetch remote properties. # 远程配置文件名称 如 service0-{profile}.properties # @Value("${spring.application.name:application}") # spring.cloud.config.name=service0 # The URI of the remote server (default http://localhost:8888). 配置服务器 spring.cloud.config.uri=http://localhost:8888 # 要启用的环境(test,pro,dev 之类的) 配置服务器得有 ${spring.cloud.config.name}-{spring.cloud.config.profile}.properties文件 spring.cloud.config.profile=test #spring.cloud.config.label=config-label-test 在配置中心的配置 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ server: port: 8891 spring.application.name: service0 message: nurmemet-test 依次启动 注册中心,配置中心,zuul网管,service0打开浏览器 localhost:8671 所有服务是否注册成功浏览器输入 localhost:8002/hello/hello网管会把这个请求转发到 localhos:8891/hello/hello 所有hello开头的请求都会转发到service0微服务中去
2021年10月
2021年09月