portal web service

Service.java 2.4KB

    package com.ekexiu.portal.found; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; import java.util.Map; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.web.annotation.Path; import org.jfw.apt.web.annotation.operate.Get; import org.jfw.apt.web.annotation.param.JdbcConn; import org.jfw.util.jdbc.JdbcUtil; import org.jfw.util.jdbc.PreparedStatementConfig; @Path("/found") public class Service { /** * 查询新发现(含提问) * @param con * @param time 下拉加载上一次返回的最后一条数据的tm,首次不传 * @param id 下拉加载上一次返回的最后一条数据的id,首次不传 * @param rows 下拉加载返回的数据条数,默认20 * @param ex 排除的文章ID * @return [{ctype:"1:专家文章,2:企业文章 3, 提问" * id:"文章id 或 提问ID ", * uid:"专家ID 或 企业id 或 提问人ID ", * tm:"文章发布时间 或 提问时间, * num:0 ,//提问回答数 * img:"图片", * col:0,//文章栏目 * }....] * @throws SQLException */ @Get @Path("/index") public List<Map<String,Object>> query(@JdbcConn Connection con,@DefaultValue("\"9\"") final String time,@DefaultValue("\"0\"") final String id,@DefaultValue("20") final int rows,final String ex)throws SQLException{ return JdbcUtil.queryMaps(con, "SELECT * FROM ( "+ "SELECT ID id,'3' ctype,uid uid,title title, last_reply_time tm,reply_count num,img img,null col FROM question where state='1' UNION ALL "+ "SELECT ARTICLE_ID id, '1' ctype,professor_id uid,article_title title,publish_time tm, 0 num,article_img img,col_num col FROM article WHERE status = '1' AND article_type = '1' AND article_id <>? UNION ALL "+ "SELECT ARTICLE_ID id, '2' ctype,org_id uid,article_title title,publish_time tm,0 num,article_img img,col_num col FROM article WHERE status = '1' AND article_type = '2' AND article_id <>? ) T "+ "WHERE T.tm<? OR (T.tm = ? AND T.id > ?) ORDER BY tm DESC LIMIT ?", new PreparedStatementConfig() { @Override public void config(PreparedStatement ps) throws SQLException { ps.setString(1,ex); ps.setString(2, ex); ps.setString(3, time); ps.setString(4, time); ps.setString(5, id); ps.setInt(6,rows); } }); } }