背景

最近要求项目组成员开发一个通用的分页组件,要求是这个组件简单易用,通用性,兼容现有框架MVVM模式,可是最后给我提交的成果勉强能够用,却欠少灵活性和框架兼容性。

设计的基本思想

传入数据源,总页数,当前页码,每页记录数,达到分页显示数据的功能。

优化

我把原本不支持MVVM的源码改善了一下,可能还可以再优化得好些,支持MVVM模式,较果如下图:

添加一解决方案:TLAgent.Pager

  • 设计DataPager类,继承UserControl, INotifyPropertyChanged ,参考如下代码:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.ComponentModel;
  8.  
  9. namespace TLAgent.Pager {
  10. /// <summary>
  11. /// DataPager.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class DataPager : UserControl, INotifyPropertyChanged {
  14. public DataPager() {
  15. InitializeComponent();
  16. }
  17.  
  18. #region 依赖属性和事件
  19. public int PageSize {
  20. get { return (int)GetValue(PageSizeProperty); }
  21. set { SetValue(PageSizeProperty, value); }
  22. }
  23.  
  24. // Using a DependencyProperty as the backing store for PageSize. This enables animation, styling, binding, etc...
  25. public static readonly DependencyProperty PageSizeProperty =
  26. DependencyProperty.Register("PageSize", typeof(int), typeof(DataPager), new UIPropertyMetadata(10));
  27.  
  28. public int Total {
  29. get { return (int)GetValue(TotalProperty); }
  30. set { SetValue(TotalProperty, value); }
  31. }
  32.  
  33. // Using a DependencyProperty as the backing store for Total. This enables animation, styling, binding, etc...
  34. public static readonly DependencyProperty TotalProperty =
  35. DependencyProperty.Register("Total", typeof(int), typeof(DataPager), new UIPropertyMetadata(0));
  36.  
  37. public int PageIndex {
  38. get { return (int)GetValue(PageIndexProperty); }
  39. set { SetValue(PageIndexProperty, value); }
  40. }
  41.  
  42. // Using a DependencyProperty as the backing store for PageIndex. This enables animation, styling, binding, etc...
  43. public static readonly DependencyProperty PageIndexProperty =
  44. DependencyProperty.Register("PageIndex", typeof(int), typeof(DataPager), new UIPropertyMetadata(1));
  45.  
  46. public string PageSizeList {
  47. get { return (string)GetValue(PageSizeListProperty); }
  48. set { SetValue(PageSizeListProperty, value); }
  49. }
  50.  
  51. // Using a DependencyProperty as the backing store for PageSizeList. This enables animation, styling, binding, etc...
  52. public static readonly DependencyProperty PageSizeListProperty =
  53. DependencyProperty.Register("PageSizeList", typeof(string), typeof(DataPager), new UIPropertyMetadata("5,10,20", (s, e) => {
  54. DataPager dp = s as DataPager;
  55. if (dp.PageSizeItems == null) dp.PageSizeItems = new List<int>();
  56. else dp.PageSizeItems.Clear();
  57. dp.RaisePropertyChanged("PageSizeItems");
  58. }));
  59.  
  60. public IEnumerable<object> ItemsSource {
  61. get { return (IEnumerable<object>)GetValue(ItemsSourceProperty); }
  62. set { SetValue(ItemsSourceProperty, value); }
  63. }
  64.  
  65. /// <summary>
  66. /// ItemsSource数据源
  67. /// </summary>
  68. public static DependencyProperty ItemsSourceProperty =
  69. DependencyProperty.Register("ItemsSource", typeof(IEnumerable<object>), typeof(DataPager), new UIPropertyMetadata(null));
  70.  
  71. public static readonly RoutedEvent PageChangedEvent = EventManager.RegisterRoutedEvent("PageChanged", RoutingStrategy.Bubble, typeof(PageChangedEventHandler), typeof(DataPager));
  72. /// <summary>
  73. /// 分页更改事件
  74. /// </summary>
  75. public event PageChangedEventHandler PageChanged {
  76. add {
  77. AddHandler(PageChangedEvent, value);
  78. }
  79. remove {
  80. RemoveHandler(PageChangedEvent, value);
  81. }
  82. }
  83. #endregion
  84. public ICommand PageChangedCommand { get; set; }
  85.  
  86. #region 通知属性
  87. private List<int> _pageSizeItems;
  88. /// <summary>
  89. /// 显示每页记录数集合
  90. /// </summary>
  91. public List<int> PageSizeItems {
  92. get {
  93. if (_pageSizeItems == null) {
  94. _pageSizeItems = new List<int>();
  95. }
  96. if (PageSizeList != null) {
  97. List<string> strs = PageSizeList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  98. _pageSizeItems.Clear();
  99. strs.ForEach(c => {
  100. _pageSizeItems.Add(Convert.ToInt32(c));
  101. });
  102. }
  103. return _pageSizeItems;
  104. }
  105. set {
  106. if (_pageSizeItems != value) {
  107. _pageSizeItems = value;
  108. RaisePropertyChanged("PageSizeItems");
  109. }
  110. }
  111. }
  112.  
  113. private int _pageCount;
  114. /// <summary>
  115. /// 总页数
  116. /// </summary>
  117. public int PageCount {
  118. get { return _pageCount; }
  119. set {
  120. if (_pageCount != value) {
  121. _pageCount = value;
  122. RaisePropertyChanged("PageCount");
  123. }
  124. }
  125. }
  126.  
  127. private int _start;
  128. /// <summary>
  129. /// 开始记录数
  130. /// </summary>
  131. public int Start {
  132. get { return _start; }
  133. set {
  134. if (_start != value) {
  135. _start = value;
  136. RaisePropertyChanged("Start");
  137. }
  138. }
  139. }
  140.  
  141. private int _end;
  142. /// <summary>
  143. /// 结束记录数
  144. /// </summary>
  145. public int End {
  146. get { return _end; }
  147. set {
  148. if (_end != value) {
  149. _end = value;
  150. RaisePropertyChanged("End");
  151. }
  152. }
  153. }
  154.  
  155. public event PropertyChangedEventHandler PropertyChanged;
  156. public void RaisePropertyChanged(string propertyName) {
  157. if (PropertyChanged != null) {
  158. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  159. }
  160. }
  161. #endregion
  162.  
  163. #region 字段、属性、委托
  164. public delegate void PageChangedEventHandler(object sender, PageChangedEventArgs args);
  165. private PageChangedEventArgs pageChangedEventArgs;
  166. #endregion
  167.  
  168. #region 引发分页更改事件
  169. /// <summary>
  170. /// 引发分页更改事件
  171. /// </summary>
  172. private void RaisePageChanged() {
  173. if (pageChangedEventArgs == null) {
  174. pageChangedEventArgs = new PageChangedEventArgs(PageChangedEvent, PageSize, PageIndex);
  175. } else {
  176. pageChangedEventArgs.PageSize = this.PageSize;
  177. pageChangedEventArgs.PageIndex = this.PageIndex;
  178. }
  179. RaiseEvent(pageChangedEventArgs);
  180. //calc start、end
  181. if (ItemsSource != null) {
  182. int curCount = ItemsSource.Count();
  183. Start = (PageIndex - 1) * PageSize + 1;
  184. End = Start + curCount - 1;
  185.  
  186. if (Total % PageSize != 0) {
  187. PageCount = Total / PageSize + 1;
  188. } else {
  189. PageCount = Total / PageSize;
  190. }
  191. } else {
  192. Start = End = PageCount = Total = 0;
  193. }
  194.  
  195. //调整图片的显示
  196. btnFirst.IsEnabled = btnPrev.IsEnabled = (PageIndex != 1);
  197. btnNext.IsEnabled = btnLast.IsEnabled = (PageIndex != PageCount);
  198. }
  199. #endregion
  200.  
  201. #region 分页操作事件
  202. void DataPager_Loaded(object sender, RoutedEventArgs e) {
  203. RaisePageChanged();
  204. }
  205.  
  206. private void cbpPageSize_SelectionChanged(object sender, SelectionChangedEventArgs e) {
  207. if (this.IsLoaded) {
  208. PageSize = (int)cboPageSize.SelectedItem;
  209. RaisePageChanged();
  210. }
  211. }
  212.  
  213. private void btnFirst_Click(object sender, RoutedEventArgs e) {
  214. PageIndex = 1;
  215. RaisePageChanged();
  216. }
  217.  
  218. private void btnPrev_Click(object sender, RoutedEventArgs e) {
  219. if (PageIndex > 1) {
  220. --PageIndex;
  221. }
  222. RaisePageChanged();
  223. }
  224.  
  225. private void btnNext_Click(object sender, RoutedEventArgs e) {
  226. if (Total % PageSize != 0) {
  227. PageCount = Total / PageSize + 1;
  228. } else {
  229. PageCount = Total / PageSize;
  230. }
  231.  
  232. if (PageIndex < PageCount) {
  233. ++PageIndex;
  234. }
  235. RaisePageChanged();
  236. }
  237.  
  238. private void btnLast_Click(object sender, RoutedEventArgs e) {
  239. if (Total % PageSize != 0) {
  240. PageCount = Total / PageSize + 1;
  241. } else {
  242. PageCount = Total / PageSize;
  243. }
  244. PageIndex = PageCount;
  245. RaisePageChanged();
  246. }
  247. private void btnRefresh_Click(object sender, RoutedEventArgs e) {
  248. RaisePageChanged();
  249. }
  250.  
  251. private void tbPageIndex_PreviewKeyDown(object sender, KeyEventArgs e) {
  252. if (e.Key == Key.Enter) {
  253. tbPageIndex_LostFocus(sender, null);
  254. }
  255. }
  256.  
  257. private void tbPageIndex_LostFocus(object sender, RoutedEventArgs e) {
  258. int pIndex = 0;
  259. try {
  260. pIndex = Convert.ToInt32(tbPageIndex.Text);
  261. } catch { pIndex = 1; }
  262.  
  263. if (pIndex < 1) PageIndex = 1;
  264. else if (pIndex > PageCount) PageIndex = PageCount;
  265. else PageIndex = pIndex;
  266.  
  267. RaisePageChanged();
  268. }
  269. #endregion
  270.  
  271. }
  272.  
  273. /// <summary>
  274. /// 分页更改参数
  275. /// </summary>
  276. public class PageChangedEventArgs : RoutedEventArgs {
  277. public int PageSize { get; set; }
  278. public int PageIndex { get; set; }
  279.  
  280. public PageChangedEventArgs(RoutedEvent routeEvent, int pageSize, int pageIndex)
  281. : base(routeEvent) {
  282. this.PageSize = pageSize;
  283. this.PageIndex = pageIndex;
  284. }
  285. }
  286. }

  • 添加一支持泛型类,可以传入任何类型对象
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace TLAgent.Pager
  8. {
  9. public class DataResult<T> : INotifyPropertyChanged
  10. {
  11.  
  12. public int _total;
  13. public int Total
  14. {
  15. get
  16. {
  17. return _total;
  18. }
  19. set
  20. {
  21. if (_total != value)
  22. {
  23. _total = value;
  24. RaisePropertyChanged("Total");
  25. }
  26. }
  27. }
  28.  
  29. private List<T> _dataSource;
  30. public List<T> DataSource
  31. {
  32. get
  33. {
  34. return _dataSource;
  35. }
  36. set
  37. {
  38. if (_dataSource != value)
  39. {
  40. _dataSource = value;
  41. RaisePropertyChanged("DataSource");
  42. }
  43. }
  44. }
  45.  
  46. public DataResult()
  47. {
  48. DataSource = new List<T>();
  49. }
  50.  
  51. public void RaisePropertyChanged(string propertyName)
  52. {
  53. if (PropertyChanged != null)
  54. {
  55. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  56. }
  57. }
  58.  
  59. public event PropertyChangedEventHandler PropertyChanged;
  60. }
  61. }

测试

添加一个测试项目:TLAgent.Pager.Test

  • 自定义一个命令InteractiveCommand,支持传入参数,代码参考:
  1. // -----------------------------------------------------------------------
  2. // <copyright file="InteractiveCommand.cs" company="M&M">
  3. // TODO: Update copyright text.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6.  
  7. namespace TLAgent.Pager.Test
  8. {
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Windows;
  14. using System.Windows.Input;
  15. using System.Windows.Interactivity;
  16. using System.Reflection;
  17.  
  18. /// <summary>
  19. /// TODO: Update summary.
  20. /// </summary>
  21. public class InteractiveCommand : TriggerAction<DependencyObject>
  22. {
  23. protected override void Invoke(object parameter)
  24. {
  25. if (base.AssociatedObject != null)
  26. {
  27. ICommand command = this.ResolveCommand();
  28. object[] tempObj = { parameter, CommandParameter };
  29. if ((command != null) && command.CanExecute(tempObj))
  30. {
  31. command.Execute(tempObj);
  32. }
  33. }
  34. }
  35.  
  36. public object CommandParameter
  37. {
  38. get { return GetValue(CommandParameterProperty); }
  39. set { SetValue(CommandParameterProperty, value); }
  40. }
  41.  
  42. public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register
  43. ("CommandParameter", typeof(object), typeof(InteractiveCommand), new PropertyMetadata(null, OnCommandParameterChanged));
  44.  
  45. private static void OnCommandParameterChanged
  46. (DependencyObject sender, DependencyPropertyChangedEventArgs e)
  47. {
  48. InteractiveCommand ic = sender as InteractiveCommand;
  49. if (ic != null)
  50. {
  51. ic.SynchronizeElementState();
  52. }
  53. }
  54.  
  55. private void SynchronizeElementState()
  56. {
  57. ICommand command = Command;
  58. if (command != null)
  59. {
  60. FrameworkElement associatedObject = AssociatedObject as FrameworkElement;
  61. if (associatedObject != null)
  62. {
  63. associatedObject.IsEnabled = command.CanExecute(CommandParameter);
  64. }
  65. }
  66. }
  67.  
  68. private ICommand ResolveCommand()
  69. {
  70. ICommand command = null;
  71. if (this.Command != null)
  72. {
  73. return this.Command;
  74. }
  75. if (base.AssociatedObject != null)
  76. {
  77. foreach (PropertyInfo info in base.AssociatedObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
  78. {
  79. if (typeof(ICommand).IsAssignableFrom(info.PropertyType) && string.Equals(info.Name, this.CommandName, StringComparison.Ordinal))
  80. {
  81. command = (ICommand)info.GetValue(base.AssociatedObject, null);
  82. }
  83. }
  84. }
  85. return command;
  86. }
  87.  
  88. private string commandName;
  89. public string CommandName
  90. {
  91. get
  92. {
  93. base.ReadPreamble();
  94. return this.commandName;
  95. }
  96. set
  97. {
  98. if (this.CommandName != value)
  99. {
  100. base.WritePreamble();
  101. this.commandName = value;
  102. base.WritePostscript();
  103. }
  104. }
  105. }
  106.  
  107. #region Command
  108. public ICommand Command
  109. {
  110. get { return (ICommand)GetValue(CommandProperty); }
  111. set { SetValue(CommandProperty, value); }
  112. }
  113. public static readonly DependencyProperty CommandProperty =
  114. DependencyProperty.Register("Command", typeof(ICommand), typeof(InteractiveCommand), new UIPropertyMetadata(null));
  115. #endregion
  116.  
  117. }
  118. }

在MainWindow.xaml中,添一DataGrid和一个DataPager,参考如下代码:

  1. <Window x:Class="TLAgent.Pager.Test.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:lib="clr-namespace:TLAgent.Pager;assembly=TLAgent.Pager"
  5. xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
  6. xmlns:cmd="clr-namespace:TLAgent.Pager.Test"
  7. xmlns:viewModels="clr-namespace:TLAgent.Pager.Test.ViewModels"
  8. Name="self"
  9. Title="MainWindow" Height="350" Width="525">
  10. <Window.DataContext>
  11. <viewModels:MainWindowViewModel/>
  12. </Window.DataContext>
  13.  
  14. <Grid>
  15. <Grid.RowDefinitions>
  16. <RowDefinition Height="*" />
  17. <RowDefinition Height="Auto" />
  18. </Grid.RowDefinitions>
  19. <DataGrid ItemsSource="{Binding Path=ItemsSource,ElementName=dataPager}">
  20. <!--<DataGrid.Columns>
  21. <DataGridTextColumn Header="Name" Binding="{Binding Name}" />
  22. <DataGridTextColumn Header="Age" Binding="{Binding Age}" />
  23. <DataGridTextColumn Header="Gender" Binding="{Binding Gender}" />
  24. </DataGrid.Columns>-->
  25. </DataGrid>
  26. <lib:DataPager Grid.Row="1" Name="dataPager" PageSizeList="10,20,30,50"
  27. ItemsSource="{Binding Result.DataSource,Mode=TwoWay}"
  28. Total="{Binding Result.Total,Mode=TwoWay}"
  29. >
  30. <i:Interaction.Triggers>
  31. <i:EventTrigger EventName="PageChanged">
  32. <cmd:InteractiveCommand Command="{Binding PageChangedCommand}" CommandName="PageChangedCommand"/>
  33. </i:EventTrigger>
  34. </i:Interaction.Triggers>
  35.  
  36. </lib:DataPager>
  37. </Grid>
  38. </Window>

添加一个ViewModel:MainWindowViewModel,继承NotificationObject:

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Windows.Input;
  4. using Microsoft.Practices.Prism.Commands;
  5. using Microsoft.Practices.Prism.ViewModel;
  6.  
  7. namespace TLAgent.Pager.Test.ViewModels
  8. {
  9. public class MainWindowViewModel : NotificationObject
  10. {
  11.  
  12. private DelegateCommand<object[]> _commandWithEventArgs;
  13. public List<Student> _dataSource;//声明数据
  14.  
  15. public MainWindowViewModel()
  16. {
  17. Result = new DataResult<Student>();//此处Student可以传入任何数据类型
  18. _dataSource = Controller.GetData();//获取得数据
  19. Result.DataSource = _dataSource;//给数据源赋值
  20. Query(10, 1);
  21. }
  22.  
  23. private DataResult<Student> _result;
  24. public DataResult<Student> Result//公开给View作数据源绑定
  25. {
  26. get { return _result; }
  27.  
  28. set
  29. {
  30. _result = value;
  31. RaisePropertyChanged("Result");
  32. }
  33. }
  34.  
  35. public void Query(int size, int pageIndex)
  36. {
  37. Result.Total = _dataSource.Count;//给页总数赋值
  38. Result.DataSource = _dataSource.Skip((pageIndex - 1) * size).Take(size).ToList();//改变数据源赋值
  39. }
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. public ICommand PageChangedCommand
  44. {
  45. get { return _commandWithEventArgs ?? (_commandWithEventArgs = new DelegateCommand<object[]>(ShowData)); }
  46. }
  47.  
  48. private void ShowData(object[] objParam)
  49. {
  50. PageChangedEventArgs args = (PageChangedEventArgs)objParam[0];//View把PageChangedEventArgs事件传过来,此事件带来页码和页序号
  51. Query(args.PageSize, args.PageIndex);
  52. }
  53. }
  54. }

添加一个Controller类,从此类中获取测试数据来源:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace TLAgent.Pager.Test
  7. {
  8. public class Controller
  9. {
  10.  
  11. public static List<Student> GetData()
  12. {
  13. List<Student> Students;
  14. Students = new List<Student>();
  15.  
  16. Random random = new Random();
  17. int count = random.Next(20, 200);
  18. for (int i = 1; i <= count; i++)
  19. {
  20. Student stu = new Student
  21. {
  22. Name = "Name" + i,
  23. Age = random.Next(20, 50),
  24. Gender = (i % 3 != 0),
  25. Desc = "Desc " + i,
  26. };
  27. Students.Add(stu);
  28. }
  29. return Students;
  30. }
  31. }
  32. }

添加一个Student类,只是作为测试用,项目中可以按实际需要,DataResult<T>是支持多种类型的数据。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Practices.Prism.ViewModel;
  6.  
  7. namespace TLAgent.Pager.Test {
  8. public class Student : NotificationObject
  9. {
  10. public string Name { get; set; }
  11. public int Age { get; set; }
  12. public bool Gender { get; set; }
  13. public string Desc { get; set; }
  14. }
  15. }

       到此一个分页控件设计就完成了,在此做一些总结。

      源码

基于WPF系统框架设计(10)-分页控件设计的更多相关文章

  1. 基于WPF系统框架设计(5)-Ribbon整合Avalondock 2.0实现多文档界面设计(二)

    AvalonDock 是一个.NET库,用于在停靠模式布局(docking)中排列一系列WPF/WinForm控件.最新发布的版本原生支持MVVM框架.Aero Snap特效并具有更好的性能. Ava ...

  2. 基于avalon+jquery做的bootstrap分页控件

    刚开始学习avalon,项目需要就尝试写了个分页控件Pager.js:基于BootStrap样式这个大家都很熟悉 在这里推荐下国产前端神器avalon:确实好用,帮我解决了很多前端问题. 不多说了,代 ...

  3. WPF自定义控件与样式(10)-进度控件ProcessBar自定义样

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Pro ...

  4. 基于WPF系统框架设计(4)-Ribbon整合Avalondock 2.0实现多文档界面设计(一)

    前些时间研究了WPF的一些框架,感觉基于Prism框架的MVVM模式对系统的UI与逻辑分离很好,所以就按照之前Winform的框架设计,用WPF做了一套,感觉比Winform要强很多. MVVM模式和 ...

  5. 基于WPF系统框架设计(6)-整合MVVM框架(Prism)

    应用场景 我们基础的框架已经搭建起来了,现在整合MVVM框架Prism,在ViewModel做一些逻辑处理,真正把界面设计分离出来. 这样方便我们系统开发分工合作,同时提高系统可维护性和灵活性. 具体 ...

  6. 基于WPF系统框架设计(8)-PasswordBox传值到ViewMode

    应用场景 我要做一个系统登录功能,需要传用户名和密码到ViewModel中,可是PasswordBox传值到ViewModel中好像跟TextBox等控件不一样.这里需要用到附加属性. 附加属性:一个 ...

  7. 基于WPF系统框架设计(7)-TextBox/PasswordBox在ViewModel中支持回车命令

    应用场景 我现在做一个系统登录功能,要求在PasswordBox上输完密码后回车,能够响应Enter事件,并执行ViewModel中对应的方法.如果登录成功则隐藏当前窗口显示主窗体,登录失败则焦点返回 ...

  8. 基于WPF系统框架设计(3)-Fluent Ribbon界面布局

    一个系统框架除了功能菜单导航,有系统内容显示区域,系统状态栏. Silver: Blue: Black: 系统界面设计,就不进行技术细节介绍了,主题以框架设计为主,Xaml源码参考: <Flue ...

  9. 基于WPF系统框架设计(9)-多值绑定之IMultiValueConverter

    应用场景 我想把View层的一个布局控件和功能按钮传到ViewModel层,达到动态变更布局,同时灵活获取功能按钮的属性,让View和ViewModel完全分离,而不受View层影响. 最后我想到使用 ...

随机推荐

  1. mysql 分组查询前n条数据

    今天去面试,碰到一道面试题: 有一个学生成绩表,表中有 表id.学生名.学科.分数.学生id .查询每科学习最好的两名学生的信息: 建表sql: CREATE TABLE `stuscore` ( ` ...

  2. vim的常用操作

      vim的几种编辑模式 正常模式:可以使用快捷键命令,或按:输入命令行. 插入模式:可以输入文本,在正常模式下,按i.a.o等都可以进入插入模式. 可视模式:正常模式下按v可以进入可视模式, 在可视 ...

  3. IOS开发---菜鸟学习之路--(三)-数据解析

    第三篇 上一篇我们讲了如何通过NSURL类来获取数据, 这一章我们来讲下对于获取过来的数据如何解析. 好了直接进入正文吧. 正文: 上一篇讲了 我们获取过来的数据格式是JSON格式的 大家可以搜下对应 ...

  4. IOS开发学习笔记023-UIToolBar的使用

    这里使用代码实现 大概过程: 1.创建工具条 2.创建插入条 3.添加头像.标签.删除按钮 4.点击头像获取标签信息 做一个简单的联系人列表,可以添加删除联系人,现在还没有添加头像和文字,接下来慢慢添 ...

  5. RESTful-rest_framework视图层-第三篇

    图书管理系统: 实现图书接口的增.删.改.查 方式一:普通的方式 views配置: #Book的增.删.改.查接口 class BookSerializer(serializers.ModelSeri ...

  6. [问题解决]docker启动不了

    问题描述:昨天下午整合了同事的代码,发现docker启动好后,docker ps查看不到,docker ps -a发现docker容器没有启动. 尝试多次启动发现都是启动不了. 经过搜索发现 http ...

  7. 设计模式(一)单例模式:2-懒汉模式(Lazy)

    思想: 相比于饿汉模式,懒汉模式实际中的应用更多,因为在系统中,“被用到时再初始化”是更佳的解决方案. 设计思想与饿汉模式类似,同样是持有一个自身的引用,只是将 new 的动作延迟到 getinsta ...

  8. NOIP试题解析

    NOIP试题解析           by QTY_YTQ noip2010关押罪犯(并查集) 题意是有n个罪犯关在两个监狱中,其中有m对罪犯有仇恨关系,如果有仇恨的罪犯关在一起会产生一定影响力的事件 ...

  9. gcc编译生成静态及动态链接库步骤

    gcc编译生成静态及动态链接库步骤 这两天在看<Linux C程序设计大全>,吴岳编著,清华大学出版社.这本书是在一个培训机构看到的,在网上查了下该书的相关信息.从目录而言,该书涵盖了Li ...

  10. input[type="radio"]自定义样式

    input为radio时,虽然会有默认选中的样式,但是并不符合大多数项目的需求,我们的目标是可以随心所欲自定义它的样式.怎么做呢?其实很简单,只要抓住3点.分别是1.label 2.隐藏自带样式 3. ...