* MySandBox [#ff6dc498] ** myhtmlcode0 [#l4f9935b] #myhtmlcode(){{ <Context docBase="MyService" <Resource name="jdbc/datasource" attr1="xxx" attr2="xxx" /> </Context> }} #myhtmlcode(){{ <Context docBase="MyService" <Resource name="jdbc/datasource" attr1="xxx" attr2="xxx" /> <tag1>xxxxxx</tag1> <tag2> <tag3>xxxxx</tag3> </tag2> <tag4> xxxxxx </ta4> </Context> }} ** myhtmlcode1 [#m5e6212d] #myhtmlcode(){{ <Context docBase="MyService" <Resource name="jdbc/datasource" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/example_db" username="example_user" password="example_pass" /> </Context> }} ** myhtmlcode2 [#t0308e29] #myhtmlcode(){{ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- アンダースコアとキャメルケースの変換をするかどうか --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> <environments default="development"> <environment id="development"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/example_db?useUnicode=true&characterEncoding=UTF-8" /> <property name="username" value="user" /> <property name="password" value="pass" /> </dataSource> </environment> </environments> <mappers> <mapper resource="example/mapper/BookMapper.xml" /> </mappers> </configuration> }} ** mycode [#qaf49fb1] #mycode(){{ package example.mapper; import java.util.List; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.SelectKey; import org.apache.ibatis.annotations.Update; import example.entity.Book; public interface BookMapper { /* コメント1*/ private String test = ""; /* * 複数行コメント */ private String test = ""; // コメント2 private String test = ""; /** JAVADOCコメント */ private String test = ""; /** * 引数のidを条件にして1件取得. * @param id * @return Bookオブジェクト */ @Select("select * from books where id = #{id}") Book selectById(int id); /** * 全件取得. * @return Bookオブジェクトのリスト */ @Select("select * from books order by id") List selectAll(); /** * 登録. * @param book Bookオブジェクト */ @Insert("insert into books (isbn,title,price,created_at,updated_at) values (#{isbn},#{title},#{price},now(),now())") @SelectKey(statement="select LAST_INSERT_ID()", keyProperty="id", before=false, resultType=int.class) void insert(Book book); /** * 更新. * @param book Bookオブジェクト */ @Update("update books set title = #{title}, price = #{price}, updated_at = now() where id = #{id}") void update(Book book); /** * 引数のidを条件にして削除. * @param id */ @Delete("delete from books where id = #{id}") void deleteById(int id); /** * 引数のBookオブジェクトに設定されたidを条件にして削除. * @param id */ @Delete("delete from books where id = #{id}") @Path("{id}") @Produces(MediaType.APPLICATION_JSON) void delete(Book book); void test(String args) { System.out.println(MediaType.APPLICATION_JSON); /* test "test" test test "test" */ System.out.println("test1!"); // 行の途中からコメント "test" System.out.println("test2!"); /* 行の途中からコメント */ System.out.println("test3!"); /* 行の途中からコメント */ System.out.println("test3-2!"); System.out.println("test4!"); /* 行の途中からコメント */ System.out.println("test4-2!"); /* 行の途中からコメント */ System.out.println("test5!"); /* 行の途中からコメント */ System.out.println("test4-3!"); // 行の途中からコメント "test" } } }} #mycode(){{ package example.service; import java.util.List; import org.apache.ibatis.session.SqlSession; import example.entity.Book; import example.mapper.BookMapper; /** * アノテーションを使用したSQLマッピングによる検索(複数件).<br /> */ public class SampleSelect02 extends SampleBase { public static void main(String[] args) throws Exception { SampleSelect02 obj = new SampleSelect02(); SqlSession session = obj.openSqlSession(); try { // 複数件取得 List<Book> list = session.getMapper(BookMapper.class).selectAll(); for (Book book : list) { System.out.println("id : " + book.getId()); System.out.println("isbn : " + book.getIsbn()); System.out.println("title : " + book.getTitle()); System.out.println("price : " + book.getPrice()); System.out.println("created : " + book.getCreatedAt()); System.out.println("updated : " + book.getUpdatedAt()); System.out.println("------------------------------"); } } finally { session.close(); } } } }}