-
配置Java對象屬性與查詢結果集中列名對應關系 1.resultMap標簽 <resultMap type="User" id="UserResult">//type是javabean的完整類名,id要唯一 <id column="id" jdbcType="INTEGER" property="id"/>//id:主鍵,column:數據的字段名,jdbcType:數據字段的類型,property:實體的屬性名 ... </resultMap>查看全部
-
定義SQL語句 1.select標簽 <select id="find" parameterType="long" resultMap="UserResult">//id:定義該標簽的id,以便dao層的調用;parameterType:傳參類型;resultMap:返回的結果集 SELECT * FROM user WHERE id = #{id:INTEGER} </select> 2.delete標簽(同上) 3.update標簽(同上) 4.insert標簽(同上)查看全部
-
SQLSession 的作用和使用方法查看全部
-
常用標簽查看全部
-
一對多關系的配置 //CommandService.java /** * 根據指令查詢消息列表 */ public String queryByCommand(String command){ CommandDao commandDao=new CommandDao(); List<Command> commandList=new ArrayList<Command>(); if(Iconst.HELP_COMMAND.equals(command)){ StringBuffer result=new StringBuffer(); commandList=commandDao.queryCommandList(null, null); for (int i = 0; i < commandList.size(); i++) { if(1!=0){ result.append("<br/>"); } result.append("回復["+ commandList.get(i).getName() + "]可以查看"+commandList.get(i).getDescription()); } return result.toString(); } commandList=commandDao.queryCommandList(command, null); if(commandList.size()>0){ /** * 隨機獲取一條內容 */ List<CommandContent> contentList=commandList.get(0).getContentList(); int i=new Random().nextInt(contentList.size()); return contentList.get(i).getContent(); } return Iconst.NO_MATCHING_CONTENT; }查看全部
-
一對多關系的配置 //主表:Command.xml <resultMap type="com.imooc.bean.Command" id="CommandResult"> <id column="C_ID" jdbcType="INTEGER" property="id"/>//兩個表中都有ID屬性時,別名來代替 <result column="NAME" jdbcType="VARCHAR" property="name"/> <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/> <collection property="contentList" resultMap="CommandContent.CommandContentResult"></collection>//在xml的配置文件中配置對應關系 </resultMap> <select id="queryCommandList" parameterType="com.imooc.bean.Command" resultMap="CommandResult"> select a.ID C_ID,a.NAME,a.DESCRIPTION,b.ID,b.CONTENT,b.COMMAND_ID from COMMAND a left join COMMAND_CONTENT b on a.ID=b.COMMAND_ID <where> <if test="name != null and !"".equals(name.trim())"> and a.NAME=#{name}</if> <if test="description != null and !"".equals(description.trim())"> and a.DESCRIPTION like '%' #{description} '%'</if> </where> </select>查看全部
-
一對多關系的配置 一個指令對應多條不同回復內容 一對多的關系,一般拆分成兩張表,以減少了冗余數據 ①表指令表:主鍵、name、description ②表指令表對應的內容:主鍵、內容、指令表的主鍵(command_id) 這樣,一個指定就可以在②表找到所對應的多條內容 兩種結構: ——————————①一條指令回復一組內容 ——————————②一條指令回復一組中的一個內容,在java代碼中隨機回復一條即可 dao層內容: ——————————————————————列表查詢 ——————————————————————頁面初始化 ——————————————————————微信對話查看全部
-
Mybatis中的OGML表達式 1查看全部
-
Mybatis中的OGML表達式 1 1、Map可以直接用key.屬性名取值 2、foreach標簽不屬于OGML查看全部
-
c:forEach varStatus屬性的相關用法 current當前這次迭代的(集合中的)項 index當前這次迭代從 0 開始的迭代索引 count當前這次迭代從 1 開始的迭代計數 first用來表明當前這輪迭代是否為第一次迭代的標志 last用來表明當前這輪迭代是否為最后一次迭代的標志 begin屬性值 end屬性值 step屬性值查看全部
-
第四章練習代碼:http://pan.baidu.com/s/1kUIRClp查看全部
-
修改文件名和變量名 選擇 -> 右擊 -> Refacter -> Rename //可以將包含此文件名的所有文件都做出修改;快捷鍵:Alt+Shift+R /** * 根據指令查詢消息列表 */ public String queryMessageByCommand(String command){ MessageDao messageDao=new MessageDao(); List<Message> messageList=new ArrayList<Message>(); if(Iconst.HELP_COMMAND.equals(command)){ StringBuffer result=new StringBuffer(); messageList=messageDao.queryMessageList(null, null); for (int i = 0; i < messageList.size(); i++) { if(1!=0){ result.append("<br/>"); } result.append("回復["+ messageList.get(i).getCommand() + "]可以查看"+messageList.get(i).getDescription()); } return result.toString(); } messageList=messageDao.queryMessageList(command, null); if(messageList.size()>0){ return messageList.get(0).getContent(); } return Iconst.NO_MATCHING_CONTENT; }查看全部
-
Eclipse中直接使用jstl標簽,會報錯, 而在 Myeclipse中新建web工程,新建jsp頁面可以直接使用jstl標簽,因為在新建工程時Myeclipse自動導入了使用jstl所需的jar包。 在Eclipse中使用jstl,需要: 1、導入jstl.jar、standard.jar 2個jar包; 2、在WEB-INF下拷入c.tld文件; 3、web.xml加上如下配置 <jsp-config> <taglib> <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> </jsp-config> 經過這幾步就可以正常使用jstl標簽了查看全部
-
標簽總結查看全部
-
Mybatis之SqlSession查看全部
舉報
0/150
提交
取消