标签:异常 while esc volatile str ssi ted main方法 自动
if (this.treeView1.SelectedNode.Level>0) { //判断TreeView选中节点是否为空 }
private void Form1_Load(object sender, EventArgs e) { //判断xml文件的属性值之经典代码 Streats str = new Streats(); TreeNode tn=null; XmlDocument doc = new XmlDocument(); doc.Load("Address.xml"); XmlNode root = doc.DocumentElement; string name = ""; foreach (XmlNode item in root.ChildNodes) { if (root.Attributes["name"].Value != name) { tn = new TreeNode(root.Attributes["name"].Value); str.StreesName = root.Attributes["name"].Value; list.Add(str); treeView1.Nodes.Add(tn); } TreeNode tree = new TreeNode(item.Attributes["name"].Value); str.JuweiHui = item.Attributes["name"].Value; foreach (XmlNode it in item.ChildNodes) { TreeNode xx = new TreeNode(it.Attributes["name"].Value); str.Smid = it.Attributes["name"].Value; tree.Nodes.Add(xx); foreach (XmlNode vv in it.ChildNodes) { TreeNode pp = new TreeNode(vv.InnerText); str.Fijname = vv.InnerText; pp.Tag = list; xx.Nodes.Add(pp); } } tree.Tag = item; tn.Nodes.Add(tree); name = root.Attributes["name"].Value; } }
什么是程序集
1.是一个或多个托管模块,以及一些资源文件的逻辑组合
2.是组件的复用,以及实施安全策略的版本的最小单位
3.包含一个或者多个类型自定义文件盒资源文件的集合
//01.查询所有年级信息 public List<Grade> getAllGrades() { string sql = "select * from grade"; DataTable dt = SQLHelper.ExecuteDataTable(sql); MyTool tool=new MyTool(); List<Grade> list = tool.DataTableToList<Grade>(dt); return list; }
你给我一个sql我还你个table
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Student.Model; using System.Data; namespace Student.DAL { public class StudentDAL { public bool AddStudent(Students stu) { bool falg = false; string sql = @"Insert into Student(Student,LoginPwd,StudentName,Gender,GradeId,Phone,Address,Birthday,Email) values ("+stu.StudentNo+",‘"+stu.LoginPwd+"‘,‘"+stu.StudentName+"‘,‘"+stu.Gender+"‘,"+stu.GradeId+",‘"+stu.Phone+"‘,‘"+stu.Address+"‘,‘"+stu.Birthday+"‘,‘"+stu.Email+"‘,)"; int a= SQLHelper.ExecuteNonQuery(sql); if (a>1) { falg = true; } return falg; } public List<Grade> StudentList() {
//弱类型的DataTable转换成钱类型List<>泛型集合 string sql = "select *from Grade"; DataTable dt = SQLHelper.ExecuteDataTable(sql); MyTool tool = new MyTool(); return tool.DataTableToList<Grade>(dt); } } }
create procedure Usp_S2227GetInitial @gender char(1), @sum int Output --输出参数 as select *from Student where Gender=@gender select @sum=COUNT(1) from Student where Gender=@gender return 100 declare @num int set @num=0 declare @myReturn int set @myReturn=0 exec @myReturn=Usp_S2227GetInitial ‘1‘,@num Output print @myReturn
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <connectionStrings> <add name="contr" connectionString="Data Source=.; Initial CataLog=MySchool;Uid=Sa;"/> </connectionStrings> </configuration> <!-- App.config配置文件-->
//Sql注入恒等式 ‘ or 1=1 --
drop Student where studentid>4
public static string Constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; public static int id;
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace D_018 { public class MyTool { public void GetStudentInsterEx(Student stu) { string str = "Data Source=.; Initial CataLog=MySchool; Uis=Sa;"; string sql = "select *from Student where Student=@Student and StudentPwd=@StudentPwd"; string sql1 = "usp_GetS2227"; //自动释放连接对象 using (SqlConnection con = new SqlConnection(str)) { SqlCommand cmd = new SqlCommand(sql, con); //简易版防注入添加 cmd.Parameters.Add(new SqlParameter("@StudentName", stu.StudentName)); con.Open(); //创建事务 SqlTransaction tx = new SqlTransaction(); //绑定的到执行操作 cmd.Transaction = tx; //指定事务类型 cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] p = { //@...要与数据库里面的事务字段一一对应 //要求 //1.带输入参数的储存过程 性别 char(1) //2.带输出参数的储存过程 统计女生的总人数 @sum //3.带返回值的储存过程 输出储存过程的返回值 new SqlParameter("@gender","1"), new SqlParameter("@num",SqlDbType.Int), new SqlParameter("myRetuen",SqlDbType.Int) }; //把值绑定到TextBox中 //表示为输出参数 p[1].Direction = ParameterDirection.InputOutput;
//设置参数为返回值类型
p[2].Direction = ParameterDirection.ReturnValue;
//加入到cmd对象中
cmd.Parameters.AddRange(p); int count = Convert.ToInt32(p[1].Value); int ret = Convert.ToInt32(p[2].Value); //开启事务 tx = con.BeginTransaction(); //提交事务 tx.Commit(); } } } }
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace D_018 { public class MyTool { public void GetStudentInsterEx(Student stu) { string str = "Data Source=.; Initial CataLog=MySchool; Uis=Sa;"; string sql = "select *from Student where Student=@Student and StudentPwd=@StudentPwd"; string sql1 = "usp_GetS2227"; //自动释放连接对象 using (SqlConnection con = new SqlConnection(str)) { SqlCommand cmd = new SqlCommand(sql, con); //简易版防注入添加 cmd.Parameters.Add(new SqlParameter("@StudentName", stu.StudentName)); con.Open(); //创建事务 //开启事务 SqlTransaction tx = con.BeginTransaction(); //绑定的到执行操作 cmd.Transaction = tx; //指定储存过程类型 cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] p = { //@...要与数据库里面的事务字段一一对应 //要求 //1.带输入参数的储存过程 性别 char(1) //2.带输出参数的储存过程 统计女生的总人数 @sum //3.带返回值的储存过程 输出储存过程的返回值 new SqlParameter("@gender","1"), new SqlParameter("@num",SqlDbType.Int), new SqlParameter("myRetuen",SqlDbType.Int) }; //把值绑定到TextBox中 //表示为输出参数 p[1].Direction = ParameterDirection.InputOutput; //设置参数为返回值类型 p[2].Direction = ParameterDirection.ReturnValue; //加入到cmd对象中 cmd.Parameters.AddRange(p); int count = Convert.ToInt32(p[1].Value); int ret = Convert.ToInt32(p[2].Value); //提交事务 tx.Commit(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace MySchool.BLL { //(util)通用工具类 public class MySchoolBLL { //MD5加密 public string MD5GetEx(string name) { MD5CryptoServiceProvider m = new MD5CryptoServiceProvider(); byte[] b1 = Encoding.Default.GetBytes(name); byte[] b2 = m.ComputeHash(b1); string na = string.Empty; foreach (byte item in b2) { na += item.ToString("x2"); } return na; } //加密不可逆 //可以对字符串/文件加密 } }
MD5 m = new MD5CryptoServiceProvider(); byte[] a = Encoding.Default.GetBytes("1"); byte[] b=m.ComputeHash(a); StringBuilder sb = new StringBuilder(); foreach (byte item in b) { sb.Append(item.ToString("X2")); } Console.WriteLine(sb.ToString()); Console.ReadKey();
//删除光标消失 int xx = dataGridView1.CurrentRow.Index; dataGridView1.Rows[xx].Selected = true; dataGridView1.Rows[0].Selected = false;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="file/jQuery1.11.1.js" type="text/javascript"></script> </head> <script> $(document).ready(function(){ var str="www.bdqn"; str.title="北大青鸟"; alert(str.substring (4)); }); </script> <body> </body> </html>
select *from Room select *from RoomType select *from RoomState select RoomID,BedNUm,RoomStateName,TypeName,Description ,GuestNum,TypeID from RoomType,Room,RoomState where Room.RoomStateID=RoomState.RoomStateID and RoomTypeID=RoomType.TypeID insert into Room(BedNum,RoomStateID,RoomTypeID,Description,GuestNum) values(10,2,13,‘ing送的‘,0) update Room set BedNum=20,RoomTypeID=19,Description=‘ing房子‘ where RoomID=26 select RoomID, Convert(varchar(2),RoomID)+ ‘号房(床位:‘ +Convert(varchar(2),(BedNum-GuestNum)) + cast(‘)‘ as varchar(20)) as description from Room where BedNUm>GuestNum delete Room where RoomID=26 select *from ResideState select *from GuestRecord delete GuestRecord where GuestID=8 insert into GuestRecord(IdentityID,GuestName,RoomID,ResideID,ResideDate,Deposit) values (112313123,‘灰太狼‘,6,1,‘2012-2-3‘,2000) update Room set GuestNum+=1 where RoomID=6 select GuestName,Identityid,ResideDate,Deposit,ResideName,LeaveDate,TotalMoney,Room.RoomID,TypeName,RoomStateName,GuestId from RoomType,Room,GuestRecord,RoomState,ResideState where RoomType.TypeID=Room.RoomTypeID and RoomState.RoomStateID=Room.RoomStateID and Room.RoomID=GuestRecord.RoomID and ResideState.ResideId=GuestRecord.ResideID and ResideDate between Convert(datetime,‘2011-02-12 16:50:00.000‘) and Convert(datetime,‘2013-09-01 10:47:00.000‘) and GuestRecord.ResideID=1 select RoomId from Room where RoomTypeID=13 SELECT a.RoomID, a.BedNum, a.RoomStateID, a.Description, a.GuestNum, a.RoomTypeID, b.TypeName, b.TypePrice, c.RoomStateName FROM [Room] a INNER JOIN [RoomType] b ON a.RoomTypeID = b.TypeID INNER JOIN [RoomState] c ON a.RoomStateID = c.RoomStateID WHERE 1=1
表示层exe 业务逻辑层dll 数据访问层dll
E:\apache-tomcat-7.0.77\work\Catalina\localhost\AA\org\apache\jsp
/* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat/7.0.77 * Generated at: 2017-07-20 02:28:50 UTC * Note: The last modified time of this file was set to * the last modified time of the source file after * generation to assist with modification tracking. */ package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import java.util.*; public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { private static final javax.servlet.jsp.JspFactory _jspxFactory = javax.servlet.jsp.JspFactory.getDefaultFactory(); private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants; private volatile javax.el.ExpressionFactory _el_expressionfactory; private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager; public java.util.Map<java.lang.String,java.lang.Long> getDependants() { return _jspx_dependants; } public javax.el.ExpressionFactory _jsp_getExpressionFactory() { if (_el_expressionfactory == null) { synchronized (this) { if (_el_expressionfactory == null) { _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); } } } return _el_expressionfactory; } public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() { if (_jsp_instancemanager == null) { synchronized (this) { if (_jsp_instancemanager == null) { _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig()); } } } return _jsp_instancemanager; } public void _jspInit() { } public void _jspDestroy() { } public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException { final javax.servlet.jsp.PageContext pageContext; javax.servlet.http.HttpSession session = null; final javax.servlet.ServletContext application; final javax.servlet.ServletConfig config; javax.servlet.jsp.JspWriter out = null; final java.lang.Object page = this; javax.servlet.jsp.JspWriter _jspx_out = null; javax.servlet.jsp.PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=utf-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write(‘\r‘); out.write(‘\n‘); String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" <base href=\""); out.print(basePath); out.write("\">\r\n"); out.write(" \r\n"); out.write(" <title>My JSP ‘index.jsp‘ starting page</title>\r\n"); out.write("\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n"); out.write("\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n"); out.write("\t<!--\r\n"); out.write("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">\r\n"); out.write("\t-->\r\n"); out.write(" </head>\r\n"); out.write(" \r\n"); out.write(" <body>\r\n"); out.write(" 今天天气不错\r\n"); out.write(" "); String info= request.getRemoteAddr()+ "\t"+request.getRemoteUser(); System.out.println(info); out.write("\r\n"); out.write(" </body>\r\n"); out.write("</html>\r\n"); } catch (java.lang.Throwable t) { if (!(t instanceof javax.servlet.jsp.SkipPageException)){ out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { if (response.isCommitted()) { out.flush(); } else { out.clearBuffer(); } } catch (java.io.IOException e) {} if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } }
<% String info= request.getRemoteAddr()+ "\t"+request.getRemoteUser(); System.out.println(info); %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
1.什么内置对象 不用new 直接用 2.request.setResuqestDisponse().forname()转向 request.getParamper();获取属性 resquest.setAttbrite()设置属性 resquest.getParamperValues(); 3.response.sendRedrist();重定向 4 转发 重定向 请求次数 1 2 url地址 不变 变 站内站外 站内 站外 资源共享 共享 不共享 5.保存在服务器端的一次请求N次相应的过程 6.session.setAttbrite("name",name); 7.<%@ page import="java.util.*" lanauge="html/text" pageEncoding="utf-8" %> 8小脚本 注释 表达式
在我们在myeclips里使用junit测试工具时有时会遇到错误,这是什么原因呢? 导致问题的原因通常有下面几个: (1)没有导入jar包 (2)导入jar包版本太低 (3)注意@Test要写在方法上面
即使报错 但是 Test单词只要变成灰色就能用因为你还没有写测试方法
jsp 页面 500报错 该 大写的 UTF-8 localhost
<!--声明出去的是全局变量 --> <%! int a=1; %> <%=a++ %>
<!-- 它是jsp指令,也是一种特殊的标签! --> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <% //获取项目名 String path = request.getContextPath(); //http://localhost:8080/项目名/ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html "> <html> <head> <!-- 向页面输出basePath,但只能在查看源文件里面显示值 --> <base href="<%=basePath %>"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Jsp基本内容</title> </head> <body> <% //java代码片段(常用),用于定义0~N条Java语句!方法内能写什么,它就可以放什么! int a = 10;//是局部变量 %> <% out.print(a++);//永远输出10,因为没有this那a就是局部变量 %> <%=a %><!-- 作用和out.print(a)一样 ,因为上面输出a后a加了1所以永远输出11,无论刷新多少次--> <!-- 下面这个a是全局变量 --> <%! int a=100; public void fun1(){ System.out.println(a); } %> <% out.print(this.a++);//调用的是声明的那个变量a,页面输出值,因为 这个a是全局变量,所以刷新页面原来的值还在 fun1();//控制台输出 %> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%-- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> --%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <%-- <base href="<%=basePath%>"> --%> <title>登陆</title> </head> <body> <!-- 报错的原因把上面的注释掉 --> <%@ include file="index.jsp" %> <% int i=7; int j=10; %> </body> </html>
前缀运算符的运算规则是先运算后引用,所以,此题输出结果为Count:2
在JSP中的注释一共分为两种注释: 显式注释:在HTML中存在注释“<!--注释内容 -->” 隐式注释:可以使用java中的“//”、“/*….*/”,以及JSP中自己的注释:“<%-- 注释内容 --%>”
//分页查询 public List<News> findAll(int pageIndex,int pageSize) throws Exception{ String sql="select top "+pageSize+" * from news where nid not in(select top "+(pageIndex-1)*pageSize+" nid from news )"; //top后面不能跟变量 //String sql="select top ? * from news where nid not in(select top ? nid from news )"; //Object[] p={pageSize,(pageIndex-1)*pageSize}; ResultSet rs=executeQuery(sql); List<News> list=new ArrayList<News>(); while(rs.next()){ News news=new News(); news.setNititle(rs.getString("nititle")); news.setNcreatedate(rs.getString("string")); list.add(news); } return list; }
SELECT * FROM news WHERE ntid=15 OR ntid=16 AND nid >=(1-1)*3 LIMIT 0,3 mysql 多条件分页查询 下标,总数据数
//静态方法不可以直接访问实例成员 //实例方法可以直接访问静态成员
// 1. 默认三条数据 int pageSize = 3; page.setPageSize(3); // 2. 总页数 int mytotalpages = 0; try { mytotalpages = service.getAllCount() % pageSize == 0 ? service .getAllCount() / pageSize : service.getAllCount() / pageSize + 1; } catch (Exception e2) { } page.setTotalPages(mytotalpages); // 3. 默认当前页 int myindex = 1; String pageIndex = request.getParameter("pageIndex"); // 解决页初加载时为null的问题 if (pageIndex != null && (!pageIndex.equals(""))) { myindex = Integer.parseInt(pageIndex); } if(myindex>mytotalpages){ myindex=1; } if(myindex<1){ myindex=1; } System.out.println("当前页"+myindex+"\n"+"总页数"+mytotalpages); // 当前页赋值 page.setPageIndex(myindex); // 4 泛型集合 try { //获取当前的新闻编号 String ntid=request.getParameter("ntid"); request.setAttribute("topicid", ntid); System.out.println("储存当前新闻编号"+(String)request.getAttribute("topicid")); List<News> xx = service.getOneNewsData(page.getPageIndex(),pageSize,ntid); page.setList(xx); } catch (Exception e1) { e1.printStackTrace(); } // 5. 放到作用域中 request.setAttribute("list", page); // 6.加载新闻主题 ITopicService topic=new TopicServiceImpl(); try { List<Topic> topicList=topic.findAll(); request.setAttribute("topicList",topicList); } catch (Exception e) { } // 7. 转发到index.jsp request.getRequestDispatcher("/index.jsp").forward(request, response);
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>欢迎</title> <script type="text/javascript"> var request=new XMLHttpRequest(); request.open("GET", getphp, true); request.send();//放了一些数据 request.onreadystatechange=function(){//对过程进行了间监听 if(request.readyState==4&&request.status===200) request.responseText } </script> </head> <body> </body> </html>
获取相同属性名的表单 if 判断 只要有一个符合条件就不在往下进行
<jsp:include page="包含的页面" />为动态包含,即所包含的页面是独立包含,主与子页面互不影响
<%@ include file="包含的页面" %> 为静态包含,即所包含的页面是父页面的子,做为父页面的一部分来调用,会共享父页面的变量
java快捷键
syst+Alt+/=打印方法名
下面举个生活中的实例来说明:
请求重定向:就好比我们找一个A广告公司给设计名片,A明确告诉我们他们不会设计,就让我们找B公司,结果B公司给我设计好了,所以我们会对外宣称是B公司给我们设计的名片,(所以我们就相当于发送了两次次请求,URL地址栏里就从A变成了B公司)
请求转发:同样去找A公司给设计名片,A公司虽然不能设计但是他们接下了我们的活,把这项任务外包(转发)给B公司,最终我们会把钱给A公司,也就会对外宣称是A公司给我们设计的名片这就是请求重定向(所以我们就相当于只对A发送了一次请求,URL地址栏里依然是A公司)。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
用El表达式截取字符串
<%=item.getContent().substring(0, 3) %>...
先给大家介绍下MyBatis中#{}和${}的区别,具体介绍如下:
1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。如:order by #user_id#,如果传入的值是111,那么解析成sql时的值为order by "111", 如果传入的值是id,则解析成的sql为order by "id".
2. $将传入的数据直接显示生成在sql中。如:order by $user_id$,如果传入的值是111,那么解析成sql时的值为order by user_id, 如果传入的值是id,则解析成的sql为order by id.
3. #方式能够很大程度防止sql注入。
4.$方式无法防止Sql注入。
5.$方式一般用于传入数据库对象,例如传入表名.
6.一般能用#的就别用$.
MyBatis排序时使用order by 动态参数时需要注意,用$而不是#
字符串替换
默认情况下,使用#{}格式的语法会导致MyBatis创建预处理语句属性并以它为背景设置安全的值(比如?)。这样做很安全,很迅速也是首选做法,有时你只是想直接在SQL语句中插入一个不改变的字符串。比如,像ORDER BY,你可以这样来使用:
ORDER BY ${columnName}
这里MyBatis不会修改或转义字符串。
重要:接受从用户输出的内容并提供给语句中不变的字符串,这样做是不安全的。这会导致潜在的SQL注入攻击,因此你不应该允许用户输入这些字段,或者通常自行转义并检查。
<!--内存级别的分页--> <select id="RowBound" parameterType="map" resultType="dept"> select * from dept </select>
//内存级别的分页 public List<Dept> RowBound(int num1 ,int num2 ); @Test//内存级别的分页(逻辑分页) public void RowsRound() throws Exception { List<Dept> list = MyBatisUtil.getSqlSession().selectList("RowBound", new RowBounds(1, 3)); for (Dept item : list) { System.out.println(item.getDeptName()); } }
物理分页:
package com.cy.service; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.cy.mapper.StudentMapper; import com.cy.model.Student; import com.cy.util.SqlSessionFactoryUtil; public class StudentTest2 { private static Logger logger = Logger.getLogger(StudentTest2.class); private SqlSession sqlSession=null; private StudentMapper studentMapper=null; @Before public void setUp() throws Exception { sqlSession=SqlSessionFactoryUtil.openSession(); studentMapper=sqlSession.getMapper(StudentMapper.class); } @After public void tearDown() throws Exception { sqlSession.close(); } /** * 逻辑分页,实现过程:先把所有数据都查出来,再从内存中从0开始,取3条数据; */ @Test public void findStudent() { logger.info("查询学生逻辑分页"); int offset = 0; //start;开始 int limit = 3; //limit: 每页大小; RowBounds rowBound = new RowBounds(offset, limit); //RowBounds里面有分页信息 List<Student> studentList=studentMapper.findStudent(rowBound); for(Student student:studentList){ System.out.println(student); } } @Test public void findStudent2() { logger.info("查询学生物理分页"); Map<String, Object> map = new HashMap<String, Object>(); map.put("start", 0); map.put("size", 3); List<Student> studentList=studentMapper.findStudent2(map); for(Student student:studentList){ System.out.println(student); } } }
2)StudentMapper.java接口:
1 //逻辑分页 RowBounds里面有分页信息 2 public List<Student> findStudent(RowBounds rowBound); 3 4 //物理分页 5 public List<Student> findStudent2(Map<String, Object> map);
3)StudentMapper.xml映射文件:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.cy.mapper.StudentMapper"> <resultMap type="com.cy.model.Student" id="StudentResult"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="age" column="age"/> <result property="remark" column="remark"/> </resultMap> <!-- 逻辑分页 --> <select id="findStudent" resultMap="StudentResult"> select * from t_student </select> <!-- 物理分页 --> <select id="findStudent2" parameterType="Map" resultMap="StudentResult"> select * from t_student <if test="start!=null and size!=null"> limit #{start}, #{size} </if> </select> </mapper>
console:
配置二级缓存:
1)StudentMapper.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.cy.mapper.StudentMapper"> <!-- 1,size:表示缓存cache中能容纳的最大元素数。默认是1024; 2,flushInterval:定义缓存刷新周期,以毫秒计; 3,eviction:定义缓存的移除机制;默认是LRU(least recently userd,最近最少使用),还有FIFO(first in first out,先进先出) 4,readOnly:默认值是false,假如是true的话,缓存只能读。 --> <cache size="1024" flushInterval="60000" eviction="LRU" readOnly="false"/> <resultMap type="com.cy.model.Student" id="StudentResult"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="age" column="age"/> <result property="remark" column="remark"/> </resultMap> <select id="findStudents" resultMap="StudentResult" flushCache="false" useCache="true"> select * from t_student </select> <insert id="insertStudent" parameterType="Student" flushCache="true"> insert into t_student values(null,#{name},#{age},#{pic},#{remark}); </insert> </mapper>
在html中form表单的submit具有最高权限只要你敢写submit不管你是Ajax还是别的
我都发送的是同步的请求
关于异常补充
1.
system。exit(int stat)强制退出异常
2.
异常链
列子
A异常调用B异常B异常调用C异常
main方法调用A异常这是异常链
3.
关于如何查看main方法调用A异常包含的所有异常
throw new (Exception ex)
每一个异常块中都加入这句代码
4.自定义异常
一个普通的类必须间接的继承Throw Abel的子类或顶级父类
5.return关键字
如果一个try中出现了return关键字
001.return之前假如有breao zore0除数不能为0的异常
解析:因为执行到return之前就出现了异常所以return不回走程序正常执行
002.return之前没有代码错误
解析:不会走return会先走finaly块然后走return跳出程序
接口能继承接口
标签:异常 while esc volatile str ssi ted main方法 自动
原文地址:http://www.cnblogs.com/lcycn/p/7118042.html