今天在做一个官网的后端接口,需要返回前端新闻列表,做个简单分页
表结构
create table xp_home_news(
news_id int primary key identity(1,1),
news_image nvarchar(200),
[type] int default(1),
title nvarchar(200),
subtitle nvarchar(300),
news_date nvarchar(200),
content text,
title_eng nvarchar(200),
subtitle_eng nvarchar(300),
content_eng text,
is_show int default(1),
srot int
)
go
通过sql分页查询,传入当前页(1)和每页个数(10)
select * from
(select top 1000 news_id,news_image,title_eng,subtitle_eng,news_date,ROW_NUMBER() OVER(Order by news_id ) AS RowId
from xp_home_news
where [type]=1 and is_show=1
order by srot) a
where RowId between 1+(1-1*10) and 1*10
查询成功
一点题外话,这几天心情都不咋好,挺低落的,与人相处好难啊,
好难受啊>_<