最近做了 一个servlet小项目,遇到了很多坑,记录一下
1.设置成员变量,如果是方法的返回值,返回值不能直接点出来
SqlSession sqlSession = MybatisUtil.openSession();
2.封装mybatis的resultMap


或者
<resultMap id="book" type="maosi.domain.Book" >
<id property="id" column="id"/>
<result property="author" column="author"/>
<result property="name" column="name"/>
<result property="price" column="price" />
<result property="sn" column="sn"/>
<result property="dirId" column="dirid"/>
<association property="director"
javaType="maosi.domain.Director"
column="dirid"
select="maosi.mapper.DirectoryMapper.getOne"
>
<id property="id" column="id" />
<result property="name" column="name"/>
<result property="describes" column="describes"/>
</association>
</resultMap>
3.service
servlet的方法中,有doGet,doPost,还有一个Service。Service可以接收get和post。
因为这个方法遇到一个bug,就是我在接收jsp的表单的时候,链接是这样写的:
/director?cmd=insertPage 但是我用doGet就接收不到,cmd参数,会直接转化成表单內的其他数据,而接收不到cmd的参数。 解决办法就是把doGet方法换成service就行了
Comments | NOTHING