| | |
| | | -- insert into model (name, json) values ('Test', '{"color": "#ffffff", "yaw": 0}'); |
| | | |
| | | select * from model; |
| | | select * from model where upper(name) like '%' order by id limit 10 offset 0; |
| | | -------------------------------------------------------------------------------- |
| | | |
| | |
| | | public class OpController : ApiController |
| | | { |
| | | [HttpGet] |
| | | public List<Model> SelectByPage(string name, int pageSize = 10, int pageIndex = 1) |
| | | { |
| | | try |
| | | { |
| | | return ModelDAL.SelectByPage(string.IsNullOrWhiteSpace(name) ? "" : name.ToString(), pageSize, pageIndex); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.StackTrace); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | [HttpGet] |
| | | public Model SelectById(long id) |
| | | { |
| | | try |
| | |
| | | } |
| | | |
| | | [HttpPost] |
| | | public int insert([FromBody] Model model) |
| | | public int Insert([FromBody] Model model) |
| | | { |
| | | try |
| | | { |
| | | if (null == model) return 0; |
| | | |
| | | return ModelDAL.insert(model); |
| | | return ModelDAL.Insert(model); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | return list.ToArray(); |
| | | } |
| | | |
| | | public static List<Model> SelectByPage(string name, int pageSize = 10, int pageIndex = 1) |
| | | { |
| | | string sql = string.Format("select * from model where upper(name) like @name order by id limit {0} offset {1}", pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | SQLiteParameter param = new SQLiteParameter("@name"); |
| | | param.Value = "%" + name.ToUpper() + "%"; |
| | | |
| | | DataTable dt = SQLiteHelper.GetDataTable(sql, param); |
| | | if (null == dt || dt.Rows.Count == 0) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | List<Model> list = ModelHandler.FillModel<Model>(dt); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public static Model SelectById(long id) |
| | | { |
| | | string sql = "select * from model where id = @id"; |
| | |
| | | return SQLiteHelper.ExecuteNonQuery(sql); |
| | | } |
| | | |
| | | public static int insert(Model model) |
| | | public static int Insert(Model model) |
| | | { |
| | | string sql = "insert into model (name, json) values (@name, @json)"; |
| | | SQLiteParameter[] sqlParams = GetParams<Model>(sql, model); |
| | |
| | | <!DOCTYPE html> |
| | | <html xmlns="http://www.w3.org/1999/xhtml"> |
| | | <head> |
| | | <title>江苏交控智慧高速项目</title> |
| | | <meta http-equiv="Expires" content="0" /> |
| | | <meta http-equiv="Cache" content="no-cache" /> |
| | | <meta http-equiv="Pragma" content="no-cache" /> |
| | | <meta http-equiv="Cache-control" content="no-cache" /> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| | | <title></title> |
| | | <script src="Scripts/jquery-1.7.1.min.js"></script> |
| | | <script> |
| | | $(function () { |
| | | // |
| | | }); |
| | | |
| | | function Insert() { |
| | | var data = getModel(); |
| | | |
| | | ajax("Op/Insert", "POST", data, null, null, function (rs) { |
| | | console.log(rs); |
| | | alert(rs); |
| | | }); |
| | | } |
| | | |
| | | function UpdateById() { |
| | | var data = getModel(); |
| | | |
| | | ajax("Op/UpdateById", "POST", data, null, null, function (rs) { |
| | | console.log(rs); |
| | | alert(rs); |
| | | }); |
| | | } |
| | | |
| | | function getModel() { |
| | | var model = { |
| | | id: $("#id").val(), |
| | | name: $("#name").val(), |
| | | json: $("#json").val() |
| | | }; |
| | | |
| | | return JSON.stringify(model); |
| | | } |
| | | |
| | | function ajax(url, type, data, dataType, contentType, fn) { |
| | | $.ajax({ |
| | | url: url, |
| | | type: type, |
| | | data: data, |
| | | dataType: dataType || "json", // html、json、jsonp、script、text |
| | | contentType: contentType || "application/json", // "application/x-www-form-urlencoded" |
| | | success: function (data) { |
| | | fn(data); |
| | | }, |
| | | error: function (e) { |
| | | console.error(e); |
| | | } |
| | | }); |
| | | } |
| | | </script> |
| | | </head> |
| | | <body> |
| | | <a href="http://localhost/JiangSu/Values/Get">GetValues</a> <br /> |
| | | |
| | | <a href="http://localhost/JiangSu/Op/SelectByPage?pageSize=10&pageIndex=1&name=">SelectByPage?pageSize=10&pageIndex=1&name=</a> <br /> |
| | | |
| | | <a href="http://localhost/JiangSu/Op/SelectById?id=1">SelectById?id=1</a> <br /> |
| | | |
| | | <a href="http://localhost/JiangSu/Op/DeleteByIds?ids=2,3">DeleteByIds?ids=2,3</a> <br /> |
| | | |
| | | <form> |
| | | <input id="id" name="id" value="3" /> <br /> |
| | | <input id="name" name="name" value="A" /> <br /> |
| | | <input id="json" name="json" value="{}" /> <br /> |
| | | |
| | | <input type="button" value="Insert" onclick="Insert();" /> |
| | | <input type="button" value="UpdateById" onclick="UpdateById();" /><br /> |
| | | </form> |
| | | </body> |
| | | </html> |