前提是:我在DOS命令下等正常连接mysql,那就排除mysql服务是否启动相关的问题;我是新手,常常犯的错误就是单词拼写错误,那接下来我就比对两个有做mysql配置相关的文件做了检查,一个是application.properties,另一个是 mybatis-generator.xml ,在对比的过程中我就发现这两个文件的mysql密码是对不上的,瞬间six屎啦!
<select id="DAO接口方法名称" parameterType="参数类型" resultType="返回结果类型">select * from 表 where 。。。
</select>
resultType 可以是任意Object对象,如果多条数据,这这个方法返回的是List<Object?>,
如果确认是单条数据,可以直接 Object? ***(**)。
没有封装成对象时,默认返回的是List<Map<字段名称String,列值Object>>这样的数据。
Dao接口:
List<Map<String,Object>>list(Integer id)
SQL:
<select id="list" parameterType="Integer" resultType="Map">
select * from aaa
<where>
<if test="null!=id">
id >#{id}
</if>
</where>
</select>
以上示例中表示查询id>某个数值的所有结果,返回类型为MAP
执行脚本后没有返回结果的吧,看ScriptRunner源码,没有提供任何返回结果的。
private void executeStatement(String command) throws SQLException, UnsupportedEncodingException {
boolean hasResults = false
Statement statement = connection.createStatement()
statement.setEscapeProcessing(escapeProcessing)
String sql = command
if (removeCRs)
sql = sql.replaceAll("\r\n", "\n")
if (stopOnError) {
hasResults = statement.execute(sql)
} else {
try {
hasResults = statement.execute(sql)
} catch (SQLException e) {
String message = "Error executing: " + command + ". Cause: " + e
printlnError(message)
}
}
printResults(statement, hasResults)
try {
statement.close()
} catch (Exception e) {
// Ignore to workaround a bug in some connection pools
}
}
...
有结果时,最后调用了这个方法打印出来而已。
private void print(Object o) {
if (logWriter != null) {
logWriter.print(o)
logWriter.flush()
}
}
你可以调用
public void setLogWriter(PrintWriter logWriter) {
this.logWriter = logWriter
}
传入你自己的Writer。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)