本来mybatis的generator想要自动生成增删改的,但是到后来语句就两个select,原因是数据中没有给字段加primary,就不会有删改增。
以及Controller的Junit测试
先导入包
//用来说明此测试类的运行者,这里用了 SpringJUnit4ClassRunner @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration //指定 Spring 配置信息的来源,支持指定 XML 文件位置或者 Spring 配置类名 @ContextConfiguration(locations = {"classpath:spring-mvc.xml","classpath:spring-mybatis.xml"}) //@Transactional //这里的事务关联到配置文件中的事务控制器(transactionManager = "transactionManager"),同时//指定自动回滚(defaultRollback = true)。这样做操作的数据才不会污染数据库! @Transactional public class BaseWebJunitTest { }
在进行Junit的测试的时候,需要继承这个基础类。
public class UserTest extends BaseWebJunitTest { @Autowired private Shiro_UserMapper shiroMapper; @Test public void testPermission() { List<String> user = shiroMapper.selectRoles("user1"); System.out.println(user); System.out.println(shiroMapper.selectRoles("user1")); // } } }
在配置Junit的时候突然会报错 Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
这是我在使用maven的时候不小心的错误
可能解决方案如下
解决方案:
打开工程属性对话框,到Deployment Assembly页面,点击Add–>Java Build Path Entries–>Next–>Maven Dependencies–>Finish–>Apply–>OK