SpringMVC入门教程(一)有哪些关键点?

更新于
2026-10-12 08:41:20
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计372个文字,预计阅读时间需要2分钟。

SpringMVC入门教程(一)有哪些关键点?

根据您的要求,以下是简化后的内容:

根据逆向工程生成po类以及mapper文件,由于这里进行登录验证,故在UserMapper.java中添加如下代码:package com.ys.mapper;import com.ys.po.User;import java.util.List;import org.apache.ibatis.annotations.*;

请注意,这里已经去掉了不必要的标点符号,并且确保了字数不超过100个字。

根据逆向工程生成 po 类以及 mapper 文件,由于我们这里是进行登录验证,所以在 UserMapper.java 中添加如下代码:

package com.ys.mapper; import com.ys.po.User; import java.util.List; import org.apache.ibatis.annotations.Param; public interface UserMapper { //通过用户名和密码查询User User selectUserByUsernameAndPassword(User user); } UserMapper.xml

dao 层整合完毕之后,我们进行一个测试,要养成每做完一个小模块必须测试的习惯。步步为营,如果整个项目配置完了然后在进行测试,那么有问题进行排除会变得很困难。

package com.ys.test; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.ys.mapper.UserMapper; import com.ys.po.User; public class DaoTest { ApplicationContext context = null; @Before public void init(){ context = new ClassPathXmlApplicationContext("classpath:spring/application-dao.xml"); } @Test public void testSelectByPrimaryKey(){ UserMapper userMapper = (UserMapper) context.getBean("userMapper"); User user = userMapper.selectByPrimaryKey(1); System.out.println(user.getPassword()); } }

SpringMVC入门教程(一)有哪些关键点?

本文共计372个文字,预计阅读时间需要2分钟。

SpringMVC入门教程(一)有哪些关键点?

根据您的要求,以下是简化后的内容:

根据逆向工程生成po类以及mapper文件,由于这里进行登录验证,故在UserMapper.java中添加如下代码:package com.ys.mapper;import com.ys.po.User;import java.util.List;import org.apache.ibatis.annotations.*;

请注意,这里已经去掉了不必要的标点符号,并且确保了字数不超过100个字。

根据逆向工程生成 po 类以及 mapper 文件,由于我们这里是进行登录验证,所以在 UserMapper.java 中添加如下代码:

package com.ys.mapper; import com.ys.po.User; import java.util.List; import org.apache.ibatis.annotations.Param; public interface UserMapper { //通过用户名和密码查询User User selectUserByUsernameAndPassword(User user); } UserMapper.xml

dao 层整合完毕之后,我们进行一个测试,要养成每做完一个小模块必须测试的习惯。步步为营,如果整个项目配置完了然后在进行测试,那么有问题进行排除会变得很困难。

package com.ys.test; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.ys.mapper.UserMapper; import com.ys.po.User; public class DaoTest { ApplicationContext context = null; @Before public void init(){ context = new ClassPathXmlApplicationContext("classpath:spring/application-dao.xml"); } @Test public void testSelectByPrimaryKey(){ UserMapper userMapper = (UserMapper) context.getBean("userMapper"); User user = userMapper.selectByPrimaryKey(1); System.out.println(user.getPassword()); } }

SpringMVC入门教程(一)有哪些关键点?