<select id=”selectorder” parametertype=”int” resultetype=”me.gacl.domain.order”> select order_id id, order_no orderno ,order_price price form orders where order_id=#{id}; </select>
<select id="getOrder" parameterType="int" resultMap="orderresultmap"> select * from orders where order_id=#{id} </select> <resultMap type=”me.gacl.domain.order” id=”orderresultmap”> <!–用id属性来映射主键字段–> <id property=”id” column=”order_id”> <!–用result属性来映射非主键字段,property为实体类属性名,column为数据表中的属性–> <result property = “orderno” column =”order_no”/> <result property=”price” column=”order_price” /> </reslutMap>
<insert id="insertname”> list<string> names = new arraylist(); names.add(“fred’); names .add(“barney”) ; names .add( betty') ; names.add(“wilma') ; 注意这里 executortype.batch sqlsession sqlsession = sqlsessionfactory.opensession( executortype.batch) ; try{ namemapper mapper = sqlsession.getmapper (namemapper . class ); for(string name : names ) { mapper .insertname(name ); } sqlsession .commit() } catch(Exception e){ e.printStackTrace();sglsession .rollback() ; throw e; } finally { sqlsession .close(); }
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test? characterEncoding=UTF-8", "root", "123456");