zoukankan      html  css  js  c++  java
  • 代码错误

    管理映射文件错误

    <package name="com/offcn/dao" /> //包名

    <mapper resource="com/offcn/dao/UserDao.xml" /> //映射文件

    导包错误

    @Service
    public class UserServiceImpl implements UserService {
        @Autowired
        UserMapper um;
        @Override
          public User getByUname(String uname) {
    // TODO 自动生成的方法存根
    UserExample ue=new UserExample();
    Criteria cc=ue.createCriteria();
    cc.andUserNameEqualTo(uname);
    List<User> ulist=um.selectByExample(ue);
      if(ulist!=null&&ulist.size()>0) {
        return ulist.get(0);
      }
        return null;
    }}
    --------------------------------------------------------------------------------
    List<User> ulist=um.selectByExample(ue);//如果List类型不是通用的,不能使用参数(user)将他参数化,是导包错误。list导包一般是import java.util.List;

    运行结果错误

    出现http 404错误(所请求的页面不存在或以删除)

    一般是找不到文件

    404解决方法:建立一个新的jsp页面

    出现http 500错误(内部服务错误)一般是代码的错误

    请求的页面、图片再回放的时候找不到

    参数化的取值有问题

    500解决方法:方法类有错误的取值

    编码错误

    <%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>//编码是UTF-8

    访问路径错误

    <bean       class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
    <bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/"></property>
    <property name="suffix" value=".jsp"></property>
    </bean>
    ---------------------------------------------------------------------------------
    <property name="prefix" value="/WEB-INF/"></property>
    访问的路径下的文件

    访问网址错误

    @Controller//标注控制层组件
    @RequestMapping("user")//文件下一级路径
          public class UserController {
          @Autowired//注入相当于映射文件中<bean id="" class=""/>
          UserService us;//全局变量
          @RequestMapping("toIndex")//文件下二级路径
          public String toIndex(Model model) {
        return "main/index";//返回WEB-INF文件下main文件下的index文件
    }}
    -------------------------------------------------------------------------------
    访问网址http://localhost:8080/ssmmusic/user/toIndex

    业务层使用重写接口错误

    @Service//标注业务层组价
    public class UserServiceImpl implements UserService {
    @Autowired//对类成员变量、方法及构造函数进行标注,完成自动装配
    UserMapper um;//全局变量
    @Override//重写接口
    public User getByUname(String uname) {
    UserExample ue=new UserExample();
    Criteria cc=ue.createCriteria();//创建查询条件
    cc.andUserNameEqualTo(uname);//传入查询条件的参数
    List<User> ulist=um.selectByExample(ue);
    if(ulist!=null&&ulist.size()>0) {
    return ulist.get(0);
    }
    return null;
    }}
    -------------------------------------------------------------------------------
    public interface UserService { //UserService接口
    public User getByUname(String uname);
    }
    当接口为空时,必须重写接口

    注解错误

      @Controller//自动注册到Spring容器,不需要在自动扫描
    @RequestMapping("user")
    public class UserController {
        @RequestMapping("toAdminLogin")
        public String toAdminLogin(Model model) {
        return "admin/AdminLogin";
    }
    -------------------------------------------------------------------------------
    @Controller注解相当于<context:component-scan base-package="com.offcn"/>
    //自动扫描com.offcn包下面的类

    数据源调用错误

       <!-- 数据源注入 -->
    <bean id="ds" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    <property name="url" value="jdbc:mysql://localhost:3306/2021aamybatis">         </property>
    <property name="username" value="root"></property>
    <property name="password" value="123456"></property>
    </bean>
    <!-- 实例化JDBC -->
    <bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="ds"></property>
    </bean>
    <!-- 实例化jdbcTempalte -->
    <bean id="accDao" class="com.offcn.dao.AccDaoImpl">
    <property name="jt" ref="jt"></property>
    </bean>
    --------------------------------------------------------------------------------
    ref 函数传入一个值作为参数,一般传入基本数据类型,返回一个基于该值的响应式Ref对象
    实例化jdbcTempalte-->实例化JDBC-->数据源注入

    传参错误(登录页面点击不响应)

    <button type="submit" class="btn btn-primary btn-lg btn-block">LOGIN</button>
    <div class="bottom">
    <span class="helper-text">${message}
    <i class="fa fa-lock"></i>
    <a href="#">忘记密码?</a></span>
    </div>
    -------------------------------------------------------------------------------
    AdminLogin登录界面,${message}进行数据的传参,控制器controller获取message参数

    逆向工程运行错误

         //generator.xml映射文件
        <!-- 指定数据库表 -->
    <table tableName="user"></table>
    <table tableName="music"></table>
    <table tableName="musictype"></table>
          <table tableName="singer"></table>
          <table tableName="message"></table>
          <table tableName="singertype"></table>
          <table tableName="video"></table>
      --------------------------------------------------------
      //GeneratorSqlmap类
      public class GeneratorSqlmap {
            public void generator() throws Exception{
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
    //指向逆向工程
        File configFile = new File
        ("C:\Java培训\ssmmusic\src\com\offcn\utils\generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
    callback, warnings);
        myBatisGenerator.generate(null);
    }
      public static void main(String[] args) throws Exception {
      try {
      GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
      generatorSqlmap.generator();
        } catch (Exception e) {
      e.printStackTrace();
    }
    }}
    --------------------------------------------------------------------------------
    运行GeneratorSqlmap类,生成bean类和dao类

    引用新标签错误

      <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
    ---------------------------------------------
    <c:forEach items="${ulist}" var="u">
        <tr>
          <td>${u.id} </td>
          <td>${u.username}</td>
          <td><fmt:formatDate value="${u.birthday}" pattern="yyyy-MM-dd"/></td>
          <td>
                <c:if test="${u.sex==0}">女</c:if>
                <c:if test="${u.sex==1}">男</c:if>
          </td>
          <td>${u.address}</td>
        </tr>
    </c:forEach>
    --------------------------------------------------------------------------
    视图解析器<%@taglib prefix="" uri=""%>若不定义,新定义的标签系统不识别
    应用前面定义的视图解析器标签完成某种功能

     

  • 相关阅读:
    Android&Java面试题大全—金九银十面试必备
    android招聘啦,美图秀秀欢迎你加入!
    android经典源码,很不错的开源框架
    MongoDB、Hbase、Redis等NoSQL优劣势、应用场景
    体验go语言的风骚式编程
    金九银十中,看看这31道Android面试题
    android高级页面效果集锦
    flask中的request
    flask笔记(三)Flask 添加登陆验证装饰器报错,及解析
    flask笔记(二)
  • 原文地址:https://www.cnblogs.com/Hiramunderneath/p/14934564.html
Copyright © 2011-2022 走看看