java - how to write select tag form mybatis select -
if have class
public class product { private int id; private string name; private double price; private string type; }
a dao interface
public interface { public product selectone(int id); }
a table in database
t_product ( id tinyint, name varchar(50), price long, type varchar(30) );
i want know how write sqlmapper in mybatis selectone method!
this option annotation:
public interface productmapper{ @select( "select id, name, price, tag product id = #{id}" ) public product selectone( @param("id") int id); }
this way of writing in 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="your_interface_name_with_package_name"> <select id="selectone" resulttype="product"> select id, name, price, tag product id = #{id} </select> </mapper>
no result map required because columns can map directly object property.
Comments
Post a Comment