惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks

博客园 - FredGrit

WPF customize via three combied custom controls WPF DataGrid DataGridTemplateColumn DataTemplate ContentPresenter ContentTemplate WPF Customcontrol NumUpDownScroller WPF CustomControl override Template in Generic.xaml and invoke different style WPF HierarchicalDataTemplate customize via ToggleButton WPF DataGrid DataGridTemplateColumn DataTemplate call predefined DataTemplate via ContentPresenter and ContentTemplate WPF ListBox load data via contentcontrol an ItemTemplate WPF DataGrid load data from Asp.Net Core WebAPI WPF TreeView HierarchicalDataTemplate with grouped Data WPF display grouped data with GroupBox and ItemsControl WPF two listbox scroll syncchronously via behavior WPF invoke data from WebAPI,DataGridTemplate call pre defined DataTemplate via ContentPresenter WPF ListBox load data from WCF WPF datagrid load data from WCF via json, export selected items to json file WPF ItemsControl load data from WCF,DataTemplate, ContentControl WPF customize rotated wheel relentlessly via custom control WPF embed DataTemplate in HierchicalDataTemplate of TreeView WPF ContentControl, ItemsControl, ItemsPanelTemplate,VirtualizingStackPanel,convert xml string to List<T> WPF parse web.config recursively, TreeView and HierarchicalDataTemplate WPF Custom control in cs and Generic.xaml WPF ContextMenu independent visual tree resolved via Freezable implemented class WPF custom control GetTemplateChild vs FindName,NameScope separation between Logical Tree and Visual Tree, WPF ListBox ListView Datatemplate, parse xml to List via XmlSerializer and StringReader WPF TreeView HierarchicalDataTemplate, parse xml via traverse in XmlElement WPF parse xml via [XmRoot] and [XmlElement] attributes together, contentcontrol's template is ControlTemplate from Resources WPF ContentControl invoke Template from resource, reuse datatemplate WPF deserialize xml string as List via [XmlRoot] and [XmlElement] attribute WPF ContentControl Template WPF DatagridTemplate Binding DataTemplate WPF TreeView explicitly given key name to HierarchicalDataTemplate
C# WebAPI
FredGrit · 2026-03-15 · via 博客园 - FredGrit
Install-Package Swashbuckle.AspNetCore
namespace WebApplication1.Models
{
    public class Book
    {
        public int Id { get; set; }
        public string Name { get; set;  }
        public string ISBN { get; set;  }
        public string Author { get; set;  }
        public string Abstract {  get; set; }
        public string Comment { get; set;  }
        public string Content { get; set; }
        public string Summary { get; set;  }
        public string Title { get; set;  }
        public string Topic { get; set;  }
    }
}


using WebApplication1.Models;

namespace WebApplication1.Services
{
    public class BookService
    {
        static int Idx = 0;
        private int GetIdx()
        {
            return Interlocked.Increment(ref Idx);
        }

        public List<Book> GetBooksList()
        {
            List<Book> booksList=new List<Book>();
            for(int i=0;i<1000;i++)
            {
                var idx=GetIdx();
                var bk = new Book()
                {
                    Id=idx,
                    Name=$"Name_{idx}",
                    ISBN=$"ISBN_{idx}_{Guid.NewGuid():N}",
                    Author=$"Author_{idx}",
                    Abstract=$"Abstract_{idx}",
                    Comment=$"Comment_{idx}",
                    Content=$"Content_{idx}",
                    Summary=$"Summary_{idx}",
                    Title=$"Title_{idx}",
                    Topic=$"Topic_{idx}"
                };
                booksList.Add(bk);
            }
            return booksList;
        }
    }
}



using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;
using WebApplication1.Services;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class BookController : Controller
    {
        private readonly BookService bkService;

        public BookController(BookService bkServiceValue)
        {
            bkService = bkServiceValue;
        }

        [HttpGet]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public ActionResult<List<Book>> GetBooks()
        {
            var books = bkService.GetBooksList();
            return Ok(books);
        }

        [HttpGet("{id}")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult<Book> GetBookById(int id)
        {
            var books = bkService.GetBooksList();
            var bk=books.FirstOrDefault(x => x.Id == id);

            if(bk==null)
            {
                return NotFound($"Can't find book whose ID is {id}");
            }
            return Ok(bk);
        }
    }
}



using WebApplication1.Services;

namespace WebApplication1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
            builder.Services.AddOpenApi();
            builder.Services.AddSingleton<BookService>();
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();

            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.MapOpenApi();
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseHttpsRedirection();

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}

image

https://localhost:7205/api/book/9250

{
  "id": 9250,
  "name": "Name_9250",
  "isbn": "ISBN_9250_3d940005204f46abb2bd3ced7e17b4a8",
  "author": "Author_9250",
  "abstract": "Abstract_9250",
  "comment": "Comment_9250",
  "content": "Content_9250",
  "summary": "Summary_9250",
  "title": "Title_9250",
  "topic": "Topic_9250"
}
https://localhost:7205/api/book

image

image

posted @ 2026-03-15 00:01  FredGrit  阅读(7)  评论()    收藏  举报