慕后端0125607
1.通过<form action="<%=request.getContextPath()%>/List.action" id="mainForm" method="post">到ListServlet 2.ListServlet接受页面的值并传给ListService中的queryMessageList(command, description)方法中的参数 3.ListService调用messageDao的queryMessageList(command, description)并返回 4.MessageDao中通过DBAccess的getSqlSession()方法获得sqlSession 5.通过sqlSession执行SQL语句
weixin_慕神2406380
aql是StringBuilder类型的,append是StringBuilder的方法,向后拼接字符串。“?”是占位符,在解析sql时会按顺序替换成传入的参数
区分大小写
兄弟,问下,,用mybatis返回jsp页面的代码,写在哪个位置,,视频里面看不到
qq_光辉岁月_9
在配置数据库连接时必须制定数据库的编码,不然遇到中文查询根本无法查询到结果,如:
<property name="url" value="jdbc:mysql://127.0.0.1:3306/micro_message?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"/>
未卜先知
#{index.id}
qq_与赠_03193390
相当于在select标签里面引用ID为MessageResut的ResultMap标签
【<ResultMap></ResultMap>】就是被引用的那个标签
chaucy
req.getParameter("")接收的是页面上传来的值,并不是数据库里的值。你在页面上输入要查询的值,用req.getParameter("")接收后存在String里,然后转成int型再用mybatis映射查就可以了,只要保证映射值和数据库里的一样就OK
慕仙4974986
改成这样 and symptom_name like concat('%' ,#{symptomName}, '%')
qq_拽鱼爷_04353847
是不是没加端口的原因。localhost:8080
qq_幸福愛努力_0
如果你的其他文件或者配置都没有问题,那么可能的原因就是出现乱码了。
MyBatis两个xml文件,一个是连接数据库的,一个是进行数据库语言操作的。
我之所以没有显示内容,是因为连接数据库的xml部分出现乱码,(整个程序运行正常,进行条件查找,没报错,但就是不现实内容,找了半天最后想到了乱码问题)
解决办法
在连接数据库的xml里改(我的和视频一样是Configuration.xml)
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/micro_message?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</dataSource>
就在“url”地址上增加 (?characterEncoding=UTF-8"/>)问题解决。
qq_琉璃时间_0
慕粉4196669
报错发出来看一下哈
qq_i_18
'%' _#{description}_ '%',这一段里面的_换成空格
qq_柒分醉_03927370
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2009-2012 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--
<settings>
<setting name="useGeneratedKeys" value="false"/>
<setting name="useColumnLabel" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
</typeAliases>
-->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/micro_message"/>
<property name="username" value="root"/>
<property name="password" value="123"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/imooc/config/sqlxml/Message.xml"/>
</mappers>
</configuration>
线粒体123
当点击submit时,会根据表单的action去查找web.xml里配置的servlet,当匹配到对应的servlet时,就会调用servlet的生命周期方法进行处理了,如果有不懂底层的可以随时@我
慕粉2344018232
java.net.MalformedURLException
URL协议、格式或者路径错误, 好好检查下你程序中的代码,看看有没url写错的情况
慕勒4506555
看下Message类中的成员变量的首字母是否跟你的xml中的一致,如command的首字母是小写。
勤勉4193292
代码补全啊,equal函数后面需要一个参数的,就是如果字符串为空返回true,反之为false
qq_幸福客_0
去掉字符串"command"的前后空格
墨脱4032523
是不是数据库JDBC连接那 得添加utf8?
未卜先知
加了?useUnicode=true&characterEncoding=UTF-8还是不行啊
阳光下最猥琐的猩
或者页面不存在,你可以调试下,看看跳到后台没有
慕粉1474367326
吗的,放松了下,重新排查了一遍。是MessageDao.java中以前
public static void main(String[] args) {
MessageDao messageDao = new MessageDao();
messageDao.queryMessageList("", "");
}这个测试用的main函数没注释,调用导致的问题。
showife
咦。。那设断点调试下吧,跟踪下数据是哪儿出问题了。
阿冰yyds
你这个只是把字段换成大写?我昨天忘记说我用的是oracle数据库, 正确的写法是<if test="description !=null and !"".equals(description.trim())">and description like '%' ||#{description} ||'%'</if>
oneamongthosestars
这个应该是jdbc的事。
红袖侍读
谢谢你哈
qq_他说她是他的她_03199161
java家洼
安装的时候有一个选项是选择编码集的
bluedj
问题解决了,和jdbc时候一样,需要设置字符集。。。一个坑栽了两次,醉了。。。