大佬教程收集整理的这篇文章主要介绍了代码错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<package name="com/offcn/dao" /> //包名
<mapper resource="com/offcn/dao/UserDao.xml" /> //映射文件
@servicepublic 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("toadR_211_11845@inLogin") public String toadR_211_11845@inLogin(Model model) { return "admin/AdminLogin";}-------------------------------------------------------------------------------@Controller注解相当于<context:component-scan base-package="com.offcn"/>//自动扫描com.offcn包下面的类
<!-- 数据源注入 --><bean id="ds" class="org.apache wangt.cc mons.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 wangt.cc /jsp/jstl/core"%> <%@taglib prefix="fmt" uri="http://java.sun wangt.cc /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=""%>若不定义,新定义的标签系统不识别应用前面定义的视图解析器标签完成某种功能
以上是大佬教程为你收集整理的代码错误全部内容,希望文章能够帮你解决代码错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。